help = 'send a patch or series of patches by e-mail'
-usage = """%prog [options] [<patch>]"""
+usage = """%prog [options] [<patch>]
+
+Send a patch or a range of patches (defaulting to the applied patches)
+by e-mail using the 'smtpserver' configuration option. The From/To/Cc
+addresses and the e-mail format are generated from the template file
+passed as argument to '--template' (defaulting to
+.git/patchmail.tmpl). A preamble e-mail can also be sent using the
+'--first' option (no default template).
+
+All the subsequent e-mails appear as replies to the first e-mail sent
+(either the preamble or the first patch). E-mails can be seen as
+replies to a different e-mail by using the '--refid' option.
+
+SMTP authentication is also possible with '--smtp-user' and
+'--smtp-password' options, also available as configuration settings:
+'smtpuser' and 'smtppassword'.
+
+The template e-mail headers and body must be separated by
+'%(endofheaders)s' variable, which is replaced by StGIT with
+additional headers and a blank line. The patch e-mail template accepts
+the following variables:
+
+ %(patch)s - patch name
+ %(shortdescr)s - the first line of the patch description
+ %(longdescr)s - the rest of the patch description, after the first line
+ %(endofheaders)s - delimiter between e-mail headers and body
+ %(diff)s - unified diff of the patch
+ %(diffstat)s - diff statistics
+ %(date)s - current date/time
+ %(patchnr)s - patch number
+ %(totalnr)s - total number of patches to be sent
+ %(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 %(date)s, %(endofheaders)s
+and %(totalnr)s variables are supported."""
options = [make_option('-a', '--all',
help = 'e-mail all the applied patches',
make_option('-s', '--sleep', type = 'int', metavar = 'SECONDS',
help = 'sleep for SECONDS between e-mails sending'),
make_option('--refid',
- help = 'Use REFID as the reference id')]
+ help = 'Use REFID as the reference id'),
+ make_option('-u', '--smtp-user', metavar = 'USER',
+ help = 'username for SMTP authentication'),
+ make_option('-p', '--smtp-password', metavar = 'PASSWORD',
+ help = 'username for SMTP authentication')]
def __parse_addresses(string):
return (from_addr_list[0], to_addr_list)
-def __send_message(smtpserver, from_addr, to_addr_list, msg, sleep):
+def __send_message(smtpserver, from_addr, to_addr_list, msg, sleep,
+ smtpuser, smtppassword):
"""Send the message using the given SMTP server
"""
try:
s.set_debuglevel(0)
try:
+ if smtpuser and smtppassword:
+ s.ehlo()
+ s.login(smtpuser, smtppassword)
+
s.sendmail(from_addr, to_addr_list, msg)
# give recipients a chance of receiving patches in the correct order
time.sleep(sleep)
raise CmdException, 'smtpserver not defined'
smtpserver = config.get('stgit', 'smtpserver')
+ smtpuser = None
+ smtppassword = None
+ if config.has_option('stgit', 'smtpuser'):
+ smtpuser = config.get('stgit', 'smtpuser')
+ if config.has_option('stgit', 'smtppassword'):
+ smtppassword = config.get('stgit', 'smtppassword')
+
applied = crt_series.get_applied()
if len(args) == 1:
else:
raise CmdException, 'Incorrect options. Unknown patches to send'
+ if options.smtp_password:
+ smtppassword = options.smtp_password
+
+ if options.smtp_user:
+ smtpuser = options.smtp_user
+
+ if (smtppassword and not smtpuser):
+ raise CmdException, 'SMTP password supplied, username needed'
+ if (smtpuser and not smtppassword):
+ raise CmdException, 'SMTP username supplied, password needed'
+
total_nr = len(patches)
if total_nr == 0:
raise CmdException, 'No patches to send'
print 'Sending file "%s"...' % options.first,
sys.stdout.flush()
- __send_message(smtpserver, from_addr, to_addr_list, msg, sleep)
+ __send_message(smtpserver, from_addr, to_addr_list, msg, sleep,
+ smtpuser, smtppassword)
print 'done'
print 'Sending patch "%s"...' % p,
sys.stdout.flush()
- __send_message(smtpserver, from_addr, to_addr_list, msg, sleep)
+ __send_message(smtpserver, from_addr, to_addr_list, msg, sleep,
+ smtpuser, smtppassword)
print 'done'