From 79df2f0df89f382b63e4122aa15099a257a06463 Mon Sep 17 00:00:00 2001 From: Catalin Marinas Date: Wed, 10 Jan 2007 19:38:26 +0000 Subject: [PATCH] Allow e-mail aliases for the "mail" command The addresses passed via options or in the template file can also be aliases stored in the [aliases] section of the configuration file. They get expanded automatically when building the patch or cover e-mails. Signed-off-by: Catalin Marinas --- examples/gitconfig | 4 ++++ stgit/commands/common.py | 18 ++++++++++++++++++ stgit/commands/mail.py | 17 ++++++++++------- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/examples/gitconfig b/examples/gitconfig index a2980c9..0c0555a 100644 --- a/examples/gitconfig +++ b/examples/gitconfig @@ -60,3 +60,7 @@ # Extensions for the files involved in a three-way merge (ancestor, # current, patched) #extensions = .ancestor .current .patched + +[mail "alias"] + # E-mail aliases used with the 'mail' command + git = git@vger.kernel.org diff --git a/stgit/commands/common.py b/stgit/commands/common.py index 466f584..2e57824 100644 --- a/stgit/commands/common.py +++ b/stgit/commands/common.py @@ -303,6 +303,24 @@ def name_email_date(address): return str_list[0] +def address_or_alias(addr_str): + """Return the address if it contains an e-mail address or look up + the aliases in the config files. + """ + def __address_or_alias(addr): + if addr.find('@') >= 0: + # it's an e-mail address + return addr + if config.has_option('mail "alias"', addr): + # it's an alias + return config.get('mail "alias"', addr) + + raise CmdException, 'unknown e-mail alias: %s' % addr + + addr_list = [__address_or_alias(addr.strip()) + for addr in addr_str.split(',')] + return ', '.join(addr_list) + def patch_name_from_msg(msg): """Return a string to be used as a patch name. This is generated from the first 30 characters of the top line of the string passed diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py index fe44bc9..6f61b83 100644 --- a/stgit/commands/mail.py +++ b/stgit/commands/mail.py @@ -32,10 +32,13 @@ Send a patch or a range of patches by e-mail using the 'smtpserver' configuration option. The From address and the e-mail format are generated from the template file passed as argument to '--template' (defaulting to '.git/patchmail.tmpl' or -'~/.stgit/templates/patchmail.tmpl' or or -'/usr/share/stgit/templates/patchmail.tmpl'). The To/Cc/Bcc addresses -can either be added to the template file or passed via the -corresponding command line options. +'~/.stgit/templates/patchmail.tmpl' or +'/usr/share/stgit/templates/patchmail.tmpl'). + +The To/Cc/Bcc addresses can either be added to the template file or +passed via the corresponding command line options. They can be e-mail +addresses or aliases which are automatically expanded to the values +stored in the [mail "alias"] section of GIT configuration files. A preamble e-mail can be sent using the '--cover' and/or '--edit-cover' options. The first allows the user to specify a file to @@ -137,7 +140,7 @@ def __get_sender(): if not sender: raise CmdException, 'unknown sender details' - return sender + return address_or_alias(sender) def __parse_addresses(addresses): """Return a two elements tuple: (from, [to]) @@ -196,9 +199,9 @@ def __build_address_headers(msg, options, extra_cc = []): del msg[header] if crt_addr: - msg[header] = ', '.join([crt_addr, addr]) + msg[header] = address_or_alias(', '.join([crt_addr, addr])) else: - msg[header] = addr + msg[header] = address_or_alias(addr) to_addr = '' cc_addr = '' -- 2.11.0