From 6d0614d1b0d227b867b47ad133f7c8d2943d52f1 Mon Sep 17 00:00:00 2001 From: Mark Sapiro Date: Fri, 23 Jan 2015 17:35:45 -0800 Subject: Implemented dmarc_wrapped_message_text to optionally add an explanitory text/plain part to a message wrapped via dmarc_moderation_action. --- Mailman/Handlers/WrapMessage.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'Mailman/Handlers/WrapMessage.py') diff --git a/Mailman/Handlers/WrapMessage.py b/Mailman/Handlers/WrapMessage.py index 0e47e1e4..83f521fb 100644 --- a/Mailman/Handlers/WrapMessage.py +++ b/Mailman/Handlers/WrapMessage.py @@ -24,6 +24,9 @@ original message. import copy +from email.MIMEMessage import MIMEMessage +from email.MIMEText import MIMEText + from Mailman import Utils # Headers from the original that we want to keep in the wrapper. @@ -63,12 +66,23 @@ def process(mlist, msg, msgdata): if key.lower() not in KEEPERS: del msg[key] msg['MIME-Version'] = '1.0' - msg['Content-Type'] = 'message/rfc822' - msg['Content-Disposition'] = 'inline' msg['Message-ID'] = Utils.unique_message_id(mlist) # Add the headers from CookHeaders. for k, v in msgdata['add_header'].items(): msg[k] = v - # And set the payload the way email parses it. - msg.set_payload([omsg]) + # Are we including dmarc_wrapped_message_text? I.e., do we have text and + # are we wrapping because of dmarc_moderation_action? + if mlist.dmarc_wrapped_message_text and msgdata.get('from_is_list') == 2: + part1 = MIMEText(Utils.wrap(mlist.dmarc_wrapped_message_text), + 'plain', + Utils.GetCharSet(mlist.preferred_language)) + part1['Content-Disposition'] = 'inline' + part2 = MIMEMessage(omsg) + part2['Content-Disposition'] = 'inline' + msg['Content-Type'] = 'multipart/mixed' + msg.set_payload([part1, part2]) + else: + msg['Content-Type'] = 'message/rfc822' + msg['Content-Disposition'] = 'inline' + msg.set_payload([omsg]) -- cgit v1.2.3