Allow e-mail aliases for the "mail" command
authorCatalin Marinas <catalin.marinas@gmail.com>
Wed, 10 Jan 2007 19:38:26 +0000 (19:38 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Wed, 10 Jan 2007 19:38:26 +0000 (19:38 +0000)
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 <catalin.marinas@gmail.com>
examples/gitconfig
stgit/commands/common.py
stgit/commands/mail.py

index a2980c9..0c0555a 100644 (file)
@@ -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
index 466f584..2e57824 100644 (file)
@@ -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
index fe44bc9..6f61b83 100644 (file)
@@ -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 = ''