From: richard Date: Fri, 27 Dec 2002 23:54:05 +0000 (+0000) Subject: - applied patches for handling Outlook quirks (thanks Andrey Lebedev) X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2c2b802ac5dacb7371e4046c11ee77a7ec7c7650;p=roundup.git - applied patches for handling Outlook quirks (thanks Andrey Lebedev) (multipart/alternative, "fw" and content-type "name") git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1419 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/CHANGES.txt b/CHANGES.txt index 2055529..77c11c2 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -8,6 +8,8 @@ are given with the most recent entry first. - fixed time default in date.py - fixed error in cgi/templates.py (sf bug 652089) - fixed handling of missing password (sf bug 655632) +- applied patches for handling Outlook quirks (thanks Andrey Lebedev) + (multipart/alternative, "fw" and content-type "name") 2002-12-11 0.5.3 diff --git a/roundup/mailgw.py b/roundup/mailgw.py index 9de891b..9d1fc8e 100644 --- a/roundup/mailgw.py +++ b/roundup/mailgw.py @@ -73,7 +73,7 @@ are calling the create() method to create a new node). If an auditor raises an exception, the original message is bounced back to the sender with the explanatory message given in the exception. -$Id: mailgw.py,v 1.102 2002-12-11 01:52:20 richard Exp $ +$Id: mailgw.py,v 1.103 2002-12-27 23:54:05 richard Exp $ ''' import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri @@ -134,7 +134,7 @@ class Message(mimetools.Message): s.seek(0) return Message(s) -subject_re = re.compile(r'(?P\s*\W?\s*(fwd|re|aw)\W\s*)*' +subject_re = re.compile(r'(?P\s*\W?\s*(fw|fwd|re|aw)\W\s*)*' r'\s*(?P")?(\[(?P[^\d\s]+)(?P\d+)?\])?' r'\s*(?P[^[]+)?"?(\[(?P<args>.+?)\])?', re.I) @@ -737,13 +737,29 @@ Subject was: "%s" name = mailmess.getheader('subject') part.fp.seek(i) attachments.append((name, 'message/rfc822', part.fp.read())) + elif subtype == 'multipart/alternative': + # Search for text/plain in message with attachment and + # alternative text representation + part.getPart() + while 1: + # get the next part + subpart = part.getPart() + if subpart is None: + break + # parse it + if subpart.gettype() == 'text/plain' and not content: + content = self.get_part_data_decoded(subpart) else: # try name on Content-Type - name = part.getparam('name').strip() + name = part.getparam('name') + if name: + name = name.strip() if not name: disp = part.getheader('content-disposition', None) if disp: - name = disp.getparam('filename').strip() + name = disp.getparam('filename') + if name: + name = name.strip() # this is just an attachment data = self.get_part_data_decoded(part) attachments.append((name, part.gettype(), data)) @@ -892,7 +908,7 @@ def parseContent(content, keep_citations, keep_body, blank_line=re.compile(r'[\r\n]+\s*[\r\n]+'), eol=re.compile(r'[\r\n]+'), signature=re.compile(r'^[>|\s]*[-_]+\s*$'), - original_message=re.compile(r'^[>|\s]*-----Original Message-----$')): + original_msg=re.compile(r'^[>|\s]*-----\s?Original Message\s?-----$')): ''' The message body is divided into sections by blank lines. Sections where the second and all subsequent lines begin with a ">" or "|" character are considered "quoting sections". The first line of @@ -946,7 +962,7 @@ def parseContent(content, keep_citations, keep_body, elif signature.match(lines[0]) and 2 <= len(lines) <= 10: # lose any signature break - elif original_message.match(lines[0]): + elif original_msg.match(lines[0]): # ditch the stupid Outlook quoting of the entire original message break