Getting multipart email notifications working again
Christian Ebert
blacktrash at gmx.net
Thu Jul 30 01:50:20 CDT 2009
* Christian Ebert on Thursday, July 30, 2009 at 06:18:34 +0200
> Could you try if the patch below works for you?
This one might be simpler/better; if you can try it first.
Thanks.
c
# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1248936412 -7200
# Node ID 5c6f6f3fe2deb38430c24cc9aa226e7119cd2d91
# Parent 25255ce87bcfb753df078b2f8cabc6bcb5cb96ce
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.
diff --git a/hgext/notify.py b/hgext/notify.py
--- a/hgext/notify.py
+++ b/hgext/notify.py
@@ -70,7 +70,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 = '''
@@ -180,20 +180,26 @@
'''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 payload
+ # (multipart templates must take care of this themselves)
+
+ # store remaining headers
+ 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")
More information about the Mercurial
mailing list