Allow e-mail aliases for the "mail" command
[stgit] / stgit / commands / mail.py
index 176d7a2..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
@@ -127,14 +130,18 @@ def __get_sender():
     configuration file
     """
     if config.has_option('stgit', 'sender'):
-        return config.get('stgit', 'sender')
-    elif config.has_option('stgit', 'authname') \
-             and config.has_option('stgit', 'authemail'):
-        return '%s <%s>' % (config.get('stgit', 'authname'),
-                            config.get('stgit', 'authemail'))
+        sender = config.get('stgit', 'sender')
     else:
+        try:
+            sender = str(git.user())
+        except git.GitException:
+            sender = str(git.author())
+
+    if not sender:
         raise CmdException, 'unknown sender details'
 
+    return address_or_alias(sender)
+
 def __parse_addresses(addresses):
     """Return a two elements tuple: (from, [to])
     """
@@ -192,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 = ''
@@ -476,7 +483,8 @@ def func(parser, options, args):
     if options.all:
         patches = applied
     elif len(args) >= 1:
-        patches = parse_patches(args, applied)
+        unapplied = crt_series.get_unapplied()
+        patches = parse_patches(args, applied + unapplied, len(applied))
     else:
         raise CmdException, 'Incorrect options. Unknown patches to send'