Mercurial > p > roundup > code
diff roundup/mailgw.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 | 9655a1b65974 |
| children | 0bb3054274b8 |
line wrap: on
line diff
--- a/roundup/mailgw.py Mon Oct 04 12:56:37 2010 +0000 +++ b/roundup/mailgw.py Tue Oct 05 14:24:25 2010 +0000 @@ -27,6 +27,9 @@ and given "file" class nodes that are linked to the "msg" node. . In a multipart/alternative message or part, we look for a text/plain subpart and ignore the other parts. + . A message/rfc822 is treated similar tomultipart/mixed (except for + special handling of the first text part) if unpack_rfc822 is set in + the mailgw config section. Summary ------- @@ -277,12 +280,17 @@ def getname(self): """Find an appropriate name for this message.""" + name = None if self.gettype() == 'message/rfc822': # handle message/rfc822 specially - the name should be # the subject of the actual e-mail embedded here + # we add a '.eml' extension like other email software does it self.fp.seek(0) - name = Message(self.fp).getheader('subject') - else: + s = cStringIO.StringIO(self.getbody()) + name = Message(s).getheader('subject') + if name: + name = name + '.eml' + if not name: # try name on Content-Type name = self.getparam('name') if not name: @@ -355,8 +363,11 @@ # flagging. # multipart/form-data: # For web forms only. + # message/rfc822: + # Only if configured in [mailgw] unpack_rfc822 - def extract_content(self, parent_type=None, ignore_alternatives = False): + def extract_content(self, parent_type=None, ignore_alternatives=False, + unpack_rfc822=False): """Extract the body and the attachments recursively. If the content is hidden inside a multipart/alternative part, @@ -374,7 +385,7 @@ ig = ignore_alternatives and not content_found for part in self.getparts(): new_content, new_attach = part.extract_content(content_type, - not content and ig) + not content and ig, unpack_rfc822) # If we haven't found a text/plain part yet, take this one, # otherwise make it an attachment. @@ -399,6 +410,13 @@ attachments.extend(new_attach) if ig and content_type == 'multipart/alternative' and content: attachments = [] + elif unpack_rfc822 and content_type == 'message/rfc822': + s = cStringIO.StringIO(self.getbody()) + m = Message(s) + ig = ignore_alternatives and not content + new_content, attachments = m.extract_content(m.gettype(), ig, + unpack_rfc822) + attachments.insert(0, m.text_as_attachment()) elif (parent_type == 'multipart/signed' and content_type == 'application/pgp-signature'): # ignore it so it won't be saved as an attachment @@ -1276,7 +1294,8 @@ encrypted.""") # now handle the body - find the message ig = self.instance.config.MAILGW_IGNORE_ALTERNATIVES - content, attachments = message.extract_content(ignore_alternatives = ig) + content, attachments = message.extract_content(ignore_alternatives=ig, + unpack_rfc822 = self.instance.config.MAILGW_UNPACK_RFC822) if content is None: raise MailUsageError, _(""" Roundup requires the submission to be plain text. The message parser could
