Mercurial > hg
changeset 9313:8736b1c853ff
notify: do not mime encode multipart templates
Mulitpart templates should take care of this themselves.
See http://www.selenic.com/pipermail/mercurial/2009-July/027017.html
Also catch potential parsing errors gracefully.
author | Christian Ebert <blacktrash@gmx.net> |
---|---|
date | Wed, 05 Aug 2009 17:19:08 +0200 |
parents | 73bec717b825 |
children | 3f93f6838639 |
files | hgext/notify.py |
diffstat | 1 files changed, 16 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/notify.py Sun Aug 02 19:21:47 2009 -0700 +++ b/hgext/notify.py Wed Aug 05 17:19:08 2009 +0200 @@ -66,7 +66,7 @@ from mercurial.i18n import _ from mercurial import patch, cmdutil, templater, util, mail -import email.Parser, fnmatch, socket, time +import email.Parser, email.Errors, fnmatch, socket, time # template for single changeset can include email headers. single_template = ''' @@ -176,20 +176,25 @@ '''send message.''' p = email.Parser.Parser() - msg = p.parsestr(data) + try: + msg = p.parsestr(data) + except email.Errors.MessageParseError, inst: + raise util.Abort(inst) # store sender and subject sender, subject = msg['From'], msg['Subject'] del msg['From'], msg['Subject'] - # store remaining headers - headers = msg.items() - # create fresh mime message from msg body - text = msg.get_payload() - # for notification prefer readability over data precision - msg = mail.mimeencode(self.ui, text, self.charsets, self.test) - # reinstate custom headers - for k, v in headers: - msg[k] = v + + if not msg.is_multipart(): + # create fresh mime message from scratch + # (multipart templates must take care of this themselves) + headers = msg.items() + payload = msg.get_payload() + # for notification prefer readability over data precision + msg = mail.mimeencode(self.ui, payload, self.charsets, self.test) + # reinstate custom headers + for k, v in headers: + msg[k] = v msg['Date'] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2")