chiark / gitweb /
Allow multipart templates for patch e-mails (bug #10237)
authorCatalin Marinas <catalin.marinas@gmail.com>
Thu, 6 Dec 2007 23:28:42 +0000 (23:28 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Thu, 6 Dec 2007 23:28:42 +0000 (23:28 +0000)
If the template is a multipart MIME message, it sets the charset only to
the payloads. The patch also adds the '--attach' option to 'mail' which uses
the templates/mailattch.tmpl template file.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
stgit/commands/mail.py
templates/mailattch.tmpl [new file with mode: 0644]

index 883a4f3fd5aa897f69be48879e78cfd6bb2ae3bd..53cd239cb583505901ec476a23fa15d13ac0803c 100644 (file)
@@ -35,7 +35,9 @@ specified by the 'stgit.smtpserver' configuration option, or the
 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').
+'/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
@@ -110,6 +112,9 @@ options = [make_option('-a', '--all',
            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',
@@ -234,6 +239,7 @@ def __build_address_headers(msg, options, extra_cc = []):
         to_addr = ', '.join(options.to)
     if options.cc:
         cc_addr = ', '.join(options.cc + extra_cc)
+        cc_addr = ', '.join(options.cc + extra_cc)
     elif extra_cc:
         cc_addr = ', '.join(extra_cc)
     if options.bcc:
@@ -290,7 +296,11 @@ def __encode_message(msg):
         msg.replace_header(header, new_val)
 
     # encode the body and set the MIME and encoding headers
-    msg.set_charset(charset)
+    if msg.is_multipart():
+        for p in msg.get_payload():
+            p.set_charset(charset)
+    else:
+        msg.set_charset(charset)
 
 def __edit_message(msg):
     fname = '.stgitmail.txt'
@@ -565,7 +575,10 @@ def func(parser, options, args):
     if options.template:
         tmpl = file(options.template).read()
     else:
-        tmpl = templates.get_template('patchmail.tmpl')
+        if options.attach:
+            tmpl = templates.get_template('mailattch.tmpl')
+        else:
+            tmpl = templates.get_template('patchmail.tmpl')
         if not tmpl:
             raise CmdException, 'No e-mail template file found'
 
diff --git a/templates/mailattch.tmpl b/templates/mailattch.tmpl
new file mode 100644 (file)
index 0000000..430b341
--- /dev/null
@@ -0,0 +1,21 @@
+From: %(sender)s
+Subject: [%(prefix)sPATCH%(version)s%(number)s] %(shortdescr)s
+Mime-Version: 1.0
+Content-Type: multipart/mixed; boundary=MIMEBOUNDARY
+
+This is a MIME message.
+
+--MIMEBOUNDARY
+Content-Type: text/plain
+Content-Disposition: inline
+
+%(fromauth)s%(longdescr)s
+---
+
+%(diffstat)s
+--MIMEBOUNDARY
+Content-Type: text/plain; name=%(patch)s.patch
+Content-Disposition: attachment; filename=%(patch)s.patch
+
+%(diff)s
+--MIMEBOUNDARY--