X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/58c61f10b2af8dd6f94ebe81e9d9e38cea319f49..79df2f0df89f382b63e4122aa15099a257a06463:/stgit/commands/mail.py diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py index 31cc48a..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 @@ -55,7 +58,7 @@ SMTP authentication is also possible with '--smtp-user' and The patch e-mail template accepts the following variables: %(patch)s - patch name - %(maintainer)s - 'authname ' as read from the config file + %(sender)s - 'sender' or 'authname ' as per the config file %(shortdescr)s - the first line of the patch description %(longdescr)s - the rest of the patch description, after the first line %(diff)s - unified diff of the patch @@ -65,15 +68,15 @@ The patch e-mail template accepts the following variables: %(patchnr)s - patch number %(totalnr)s - total number of patches to be sent %(number)s - empty if only one patch is sent or ' patchnr/totalnr' + %(fromauth)s - 'From: author\\n\\n' if different from sender %(authname)s - author's name %(authemail)s - author's email %(authdate)s - patch creation date %(commname)s - committer's name %(commemail)s - committer's e-mail -For the preamble e-mail template, only the %(maintainer)s, -%(version)s, %(patchnr)s, %(totalnr)s and %(number)s variables are -supported.""" +For the preamble e-mail template, only the %(sender)s, %(version)s, +%(patchnr)s, %(totalnr)s and %(number)s variables are supported.""" options = [make_option('-a', '--all', help = 'e-mail all the applied patches', @@ -122,16 +125,22 @@ options = [make_option('-a', '--all', action = 'store_true')] -def __get_maintainer(): +def __get_sender(): """Return the 'authname ' string as read from the configuration file """ - if config.has_option('stgit', 'authname') \ - and config.has_option('stgit', 'authemail'): - return '%s <%s>' % (config.get('stgit', 'authname'), - config.get('stgit', 'authemail')) + if config.has_option('stgit', 'sender'): + sender = config.get('stgit', 'sender') else: - return None + 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]) @@ -190,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 = '' @@ -296,9 +305,7 @@ def __edit_message(msg): def __build_cover(tmpl, total_nr, msg_id, options): """Build the cover message (series description) to be sent via SMTP """ - maintainer = __get_maintainer() - if not maintainer: - maintainer = '' + sender = __get_sender() if options.version: version_str = ' %s' % options.version @@ -317,7 +324,9 @@ def __build_cover(tmpl, total_nr, msg_id, options): else: number_str = '' - tmpl_dict = {'maintainer': maintainer, + tmpl_dict = {'sender': sender, + # for backward template compatibility + 'maintainer': sender, # for backward template compatibility 'endofheaders': '', # for backward template compatibility @@ -365,9 +374,18 @@ def __build_message(tmpl, patch, patch_nr, total_nr, msg_id, ref_id, options): short_descr = descr_lines[0].rstrip() long_descr = '\n'.join(descr_lines[1:]).lstrip() - maintainer = __get_maintainer() - if not maintainer: - maintainer = '%s <%s>' % (p.get_commname(), p.get_commemail()) + authname = p.get_authname(); + authemail = p.get_authemail(); + commname = p.get_commname(); + commemail = p.get_commemail(); + + sender = __get_sender() + + fromauth = '%s <%s>' % (authname, authemail) + if fromauth != sender: + fromauth = 'From: %s\n\n' % fromauth + else: + fromauth = '' if options.version: version_str = ' %s' % options.version @@ -387,7 +405,9 @@ def __build_message(tmpl, patch, patch_nr, total_nr, msg_id, ref_id, options): number_str = '' tmpl_dict = {'patch': patch, - 'maintainer': maintainer, + 'sender': sender, + # for backward template compatibility + 'maintainer': sender, 'shortdescr': short_descr, 'longdescr': long_descr, # for backward template compatibility @@ -403,11 +423,12 @@ def __build_message(tmpl, patch, patch_nr, total_nr, msg_id, ref_id, options): 'patchnr': patch_nr_str, 'totalnr': total_nr_str, 'number': number_str, - 'authname': p.get_authname(), - 'authemail': p.get_authemail(), + 'fromauth': fromauth, + 'authname': authname, + 'authemail': authemail, 'authdate': p.get_authdate(), - 'commname': p.get_commname(), - 'commemail': p.get_commemail()} + 'commname': commname, + 'commemail': commemail} # change None to '' for key in tmpl_dict: if not tmpl_dict[key]: @@ -462,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'