+usage = """%prog [options] [<patch1>] [<patch2>] [<patch3>..<patch4>]
+
+Send a patch or a range of patches by e-mail using the SMTP server
+specified by the 'stgit.smtpserver' configuration option, or the
+'--smtp-server' command line 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
+'/usr/share/stgit/templates/patchmail.tmpl'). A patch can be sent as
+attachment using the --attach option in which case the 'mailattch.tmpl'
+template will be used instead of '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
+be used as a template. The latter option will invoke the editor on the
+specified file (defaulting to '.git/covermail.tmpl' or
+'~/.stgit/templates/covermail.tmpl' or
+'/usr/share/stgit/templates/covermail.tmpl').
+
+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'. TLS encryption can be enabled by
+'--smtp-tls' option and 'smtptls' setting.
+
+The following variables are accepted by both the preamble and the
+patch e-mail templates:
+
+ %(diffstat)s - diff statistics
+ %(number)s - empty if only one patch is sent or ' patchnr/totalnr'
+ %(patchnr)s - patch number
+ %(sender)s - 'sender' or 'authname <authemail>' as per the config file
+ %(totalnr)s - total number of patches to be sent
+ %(version)s - ' version' string passed on the command line (or empty)
+
+In addition to the common variables, the preamble e-mail template
+accepts the following:
+
+ %(shortlog)s - first line of each patch description, listed by author
+
+In addition to the common variables, the patch e-mail template accepts
+the following:
+
+ %(authdate)s - patch creation date
+ %(authemail)s - author's email
+ %(authname)s - author's name
+ %(commemail)s - committer's e-mail
+ %(commname)s - committer's name
+ %(diff)s - unified diff of the patch
+ %(fromauth)s - 'From: author\\n\\n' if different from sender
+ %(longdescr)s - the rest of the patch description, after the first line
+ %(patch)s - patch name
+ %(prefix)s - 'prefix ' string passed on the command line
+ %(shortdescr)s - the first line of the patch description"""
+
+directory = DirectoryHasRepository()
+options = [make_option('-a', '--all',
+ help = 'e-mail all the applied patches',
+ action = 'store_true'),
+ make_option('--to',
+ help = 'add TO to the To: list',
+ action = 'append'),
+ make_option('--cc',
+ help = 'add CC to the Cc: list',
+ action = 'append'),
+ make_option('--bcc',
+ help = 'add BCC to the Bcc: list',
+ action = 'append'),
+ make_option('--auto',
+ help = 'automatically cc the patch signers',
+ action = 'store_true'),
+ make_option('--noreply',
+ help = 'do not send subsequent messages as replies',
+ action = 'store_true'),
+ make_option('--unrelated',
+ help = 'send patches without sequence numbering',
+ action = 'store_true'),
+ make_option('--attach',
+ help = 'send a patch as attachment',
+ action = 'store_true'),
+ make_option('-v', '--version', metavar = 'VERSION',
+ help = 'add VERSION to the [PATCH ...] prefix'),
+ make_option('--prefix', metavar = 'PREFIX',
+ help = 'add PREFIX to the [... PATCH ...] prefix'),
+ make_option('-t', '--template', metavar = 'FILE',