Skip to content

Commit 3704ad5

Browse files
author
Richard Jones
committed
applied patches for handling Outlook quirks...
multipart/alternative, "fw" and content-type "name". (thanks Andrey Lebedev)
1 parent 6e837b2 commit 3704ad5

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ are given with the most recent entry first.
88
- fixed time default in date.py
99
- fixed error in cgi/templates.py (sf bug 652089)
1010
- fixed handling of missing password (sf bug 655632)
11+
- applied patches for handling Outlook quirks (thanks Andrey Lebedev)
12+
(multipart/alternative, "fw" and content-type "name")
1113

1214

1315
2002-12-11 0.5.3

roundup/mailgw.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class node. Any parts of other types are each stored in separate files
7373
an exception, the original message is bounced back to the sender with the
7474
explanatory message given in the exception.
7575
76-
$Id: mailgw.py,v 1.102 2002-12-11 01:52:20 richard Exp $
76+
$Id: mailgw.py,v 1.103 2002-12-27 23:54:05 richard Exp $
7777
'''
7878

7979
import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri
@@ -134,7 +134,7 @@ def getPart(self):
134134
s.seek(0)
135135
return Message(s)
136136

137-
subject_re = re.compile(r'(?P<refwd>\s*\W?\s*(fwd|re|aw)\W\s*)*'
137+
subject_re = re.compile(r'(?P<refwd>\s*\W?\s*(fw|fwd|re|aw)\W\s*)*'
138138
r'\s*(?P<quote>")?(\[(?P<classname>[^\d\s]+)(?P<nodeid>\d+)?\])?'
139139
r'\s*(?P<title>[^[]+)?"?(\[(?P<args>.+?)\])?', re.I)
140140

@@ -737,13 +737,29 @@ def handle_message(self, message):
737737
name = mailmess.getheader('subject')
738738
part.fp.seek(i)
739739
attachments.append((name, 'message/rfc822', part.fp.read()))
740+
elif subtype == 'multipart/alternative':
741+
# Search for text/plain in message with attachment and
742+
# alternative text representation
743+
part.getPart()
744+
while 1:
745+
# get the next part
746+
subpart = part.getPart()
747+
if subpart is None:
748+
break
749+
# parse it
750+
if subpart.gettype() == 'text/plain' and not content:
751+
content = self.get_part_data_decoded(subpart)
740752
else:
741753
# try name on Content-Type
742-
name = part.getparam('name').strip()
754+
name = part.getparam('name')
755+
if name:
756+
name = name.strip()
743757
if not name:
744758
disp = part.getheader('content-disposition', None)
745759
if disp:
746-
name = disp.getparam('filename').strip()
760+
name = disp.getparam('filename')
761+
if name:
762+
name = name.strip()
747763
# this is just an attachment
748764
data = self.get_part_data_decoded(part)
749765
attachments.append((name, part.gettype(), data))
@@ -892,7 +908,7 @@ def parseContent(content, keep_citations, keep_body,
892908
blank_line=re.compile(r'[\r\n]+\s*[\r\n]+'),
893909
eol=re.compile(r'[\r\n]+'),
894910
signature=re.compile(r'^[>|\s]*[-_]+\s*$'),
895-
original_message=re.compile(r'^[>|\s]*-----Original Message-----$')):
911+
original_msg=re.compile(r'^[>|\s]*-----\s?Original Message\s?-----$')):
896912
''' The message body is divided into sections by blank lines.
897913
Sections where the second and all subsequent lines begin with a ">"
898914
or "|" character are considered "quoting sections". The first line of
@@ -946,7 +962,7 @@ def parseContent(content, keep_citations, keep_body,
946962
elif signature.match(lines[0]) and 2 <= len(lines) <= 10:
947963
# lose any signature
948964
break
949-
elif original_message.match(lines[0]):
965+
elif original_msg.match(lines[0]):
950966
# ditch the stupid Outlook quoting of the entire original message
951967
break
952968

0 commit comments

Comments
 (0)