From e5c32acfbabf6f00c3189402ba4493db7dba60fc Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Thu, 6 Dec 2007 23:28:42 +0000 Subject: [PATCH] Allow multipart templates for patch e-mails (bug #10237) Organization: Straylight/Edgeware From: Catalin Marinas 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 --- stgit/commands/mail.py | 19 ++++++++++++++++--- templates/mailattch.tmpl | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 templates/mailattch.tmpl diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py index 883a4f3..53cd239 100644 --- a/stgit/commands/mail.py +++ b/stgit/commands/mail.py @@ -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 index 0000000..430b341 --- /dev/null +++ b/templates/mailattch.tmpl @@ -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-- -- [mdw]