Getting multipart email notifications working again
Christian Ebert
blacktrash at gmx.net
Wed Jul 29 23:18:34 CDT 2009
* Christopher Nuzum on Wednesday, July 29, 2009 at 12:02:43 -0400
> I used to use the template below with the NotifyExtension, but it
> broke several revisions ago (I think it broke in 1.2) and sine then
> I've been unable to get any variation of multipart notification
> messages working. The error I get is "remote: error: incoming.notify
> hook raised an exception: 'list' object has no attribute 'decode'".
>
> My goal is to treat the diff that's appended as an attachment, showing
> only the overview in the content of the email message, and as I
> mentioned, this used to work beautifully.
Could you try if the patch below works for you?
Thank you.
c
# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1248927198 -7200
# Node ID 0fd020f0f4adbb67dc34105e6a0575abeb8c074c
# Parent 25255ce87bcfb753df078b2f8cabc6bcb5cb96ce
notify: handle multipart templates
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.MIMEMultipart, fnmatch, socket, time
# template for single changeset can include email headers.
single_template = '''
@@ -187,10 +187,16 @@
del msg['From'], msg['Subject']
# store remaining headers
headers = msg.items()
- # create fresh mime message from msg body
- text = msg.get_payload()
+ # create fresh mime message from payload
+ payload = msg.get_payload()
# for notification prefer readability over data precision
- msg = mail.mimeencode(self.ui, text, self.charsets, self.test)
+ if not msg.is_multipart():
+ msg = mail.mimeencode(self.ui, payload, self.charsets, self.test)
+ else:
+ msg = email.MIMEMultipart.MIMEMultipart()
+ for part in payload:
+ part = mail.mimeencode(self.ui, part, self.charsets, self.test)
+ msg.attach(part)
# reinstate custom headers
for k, v in headers:
msg[k] = v
More information about the Mercurial
mailing list