diff roundup/roundupdb.py @ 4424:f1affb6b7a08

Mail gateway fixes and improvements. - new mailgw config item unpack_rfc822 that unpacks message attachments of type message/rfc822 and attaches the individual parts instead of attaching the whole message/rfc822 attachment to the roundup issue. - Fix handling of incoming message/rfc822 attachments. These resulted in a weird mail usage error because the email module threw a TypeError which roundup interprets as a Reject exception. Fixes issue2550667. Added regression tests for message/rfc822 attachments with and without configured unpacking (mailgw unpack_rfc822, see Features above) Thanks to Benni Bärmann for reporting.
author Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
date Tue, 05 Oct 2010 14:24:25 +0000
parents 579802067547
children 25085aec7d5a
line wrap: on
line diff
--- a/roundup/roundupdb.py	Mon Oct 04 12:56:37 2010 +0000
+++ b/roundup/roundupdb.py	Tue Oct 05 14:24:25 2010 +0000
@@ -30,6 +30,7 @@
 from email.Header import Header
 from email.MIMEText import MIMEText
 from email.MIMEBase import MIMEBase
+from email.parser   import FeedParser
 
 from roundup import password, date, hyperdb
 from roundup.i18n import _
@@ -492,6 +493,12 @@
                         else:
                             part = MIMEText(content)
                             part['Content-Transfer-Encoding'] = '7bit'
+                    elif mime_type == 'message/rfc822':
+                        main, sub = mime_type.split('/')
+                        p = FeedParser()
+                        p.feed(content)
+                        part = MIMEBase(main, sub)
+                        part.set_payload([p.close()])
                     else:
                         # some other type, so encode it
                         if not mime_type:
@@ -503,7 +510,8 @@
                         part = MIMEBase(main, sub)
                         part.set_payload(content)
                         Encoders.encode_base64(part)
-                    part['Content-Disposition'] = 'attachment;\n filename="%s"'%name
+                    cd = 'Content-Disposition'
+                    part[cd] = 'attachment;\n filename="%s"'%name
                     message.attach(part)
 
             else:

Roundup Issue Tracker: http://roundup-tracker.org/