Skip to content

Commit e6ce87e

Browse files
author
Engelbert Gruber
committed
respect encodings in non multipart messages.
1 parent 5c350af commit e6ce87e

File tree

3 files changed

+71
-5
lines changed

3 files changed

+71
-5
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Feature:
1010
. you can now use the roundup-admin tool pack the database
1111

1212
Fixed:
13+
. respect encodings in non multipart messages.
1314
. makeHtmlBase: re.sub under python 2.2 did not replace '.', string.replace does it.
1415
. preamble in tepmlateBuilder mentioned htmldata
1516
. mailgw checks encoding on first part too.

roundup/mailgw.py

Lines changed: 21 additions & 4 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.61 2002-02-04 09:40:21 grubert Exp $
76+
$Id: mailgw.py,v 1.62 2002-02-05 14:15:29 grubert Exp $
7777
'''
7878

7979

@@ -505,7 +505,6 @@ def handle_message(self, message):
505505
data = decoded.getvalue()
506506
elif encoding == 'uuencoded':
507507
data = binascii.a2b_uu(part.fp.read())
508-
attachments.append((name, part.gettype(), data))
509508
else:
510509
# take it as text
511510
data = part.fp.read()
@@ -569,8 +568,23 @@ def handle_message(self, message):
569568
'''
570569

571570
else:
572-
content = message.fp.read()
573-
571+
encoding = message.getencoding()
572+
if encoding == 'base64':
573+
# BUG: is base64 really used for text encoding or
574+
# are we inserting zip files here.
575+
data = binascii.a2b_base64(message.fp.read())
576+
elif encoding == 'quoted-printable':
577+
# the quopri module wants to work with files
578+
decoded = cStringIO.StringIO()
579+
quopri.decode(message.fp, decoded)
580+
data = decoded.getvalue()
581+
elif encoding == 'uuencoded':
582+
data = binascii.a2b_uu(message.fp.read())
583+
else:
584+
# take it as text
585+
data = message.fp.read()
586+
content = data
587+
574588
summary, content = parseContent(content)
575589

576590
#
@@ -777,6 +791,9 @@ def parseContent(content, blank_line=re.compile(r'[\r\n]+\s*[\r\n]+'),
777791

778792
#
779793
# $Log: not supported by cvs2svn $
794+
# Revision 1.61 2002/02/04 09:40:21 grubert
795+
# . add test for multipart messages with first part being encoded.
796+
#
780797
# Revision 1.60 2002/02/01 07:43:12 grubert
781798
# . mailgw checks encoding on first part too.
782799
#

test/test_mailgw.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# but WITHOUT ANY WARRANTY; without even the implied warranty of
99
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1010
#
11-
# $Id: test_mailgw.py,v 1.8 2002-02-04 09:40:21 grubert Exp $
11+
# $Id: test_mailgw.py,v 1.9 2002-02-05 14:15:29 grubert Exp $
1212

1313
import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys
1414

@@ -188,6 +188,51 @@ def testFollowup2(self):
188188
___________________________________________________
189189
''', 'Generated message not correct')
190190

191+
def testEnc01(self):
192+
self.testNewIssue()
193+
message = cStringIO.StringIO('''Content-Type: text/plain;
194+
charset="iso-8859-1"
195+
From: mary <mary@test>
196+
197+
Message-Id: <followup_dummy_id>
198+
In-Reply-To: <dummy_test_message_id>
199+
Subject: [issue1] Testing...
200+
Content-Type: text/plain;
201+
charset="iso-8859-1"
202+
Content-Transfer-Encoding: quoted-printable
203+
204+
A message with encoding (encoded oe =F6)
205+
206+
''')
207+
handler = self.instance.MailGW(self.instance, self.db)
208+
handler.main(message)
209+
message_data = open(os.environ['SENDMAILDEBUG']).read()
210+
self.assertEqual(message_data,
211+
212+
TO: [email protected], richard@test
213+
Content-Type: text/plain
214+
Subject: [issue1] Testing...
215+
To: [email protected], richard@test
216+
From: mary <[email protected].>
217+
Reply-To: Roundup issue tracker <[email protected].>
218+
MIME-Version: 1.0
219+
Message-Id: <followup_dummy_id>
220+
In-Reply-To: <dummy_test_message_id>
221+
222+
223+
mary <mary@test> added the comment:
224+
225+
A message with encoding (encoded oe ö)
226+
227+
----------
228+
status: unread -> chatting
229+
___________________________________________________
230+
"Roundup issue tracker" <[email protected].>
231+
http://some.useful.url/issue1
232+
___________________________________________________
233+
''', 'Generated message not correct')
234+
235+
191236
def testMultipartEnc01(self):
192237
self.testNewIssue()
193238
message = cStringIO.StringIO('''Content-Type: text/plain;
@@ -251,6 +296,9 @@ def suite():
251296

252297
#
253298
# $Log: not supported by cvs2svn $
299+
# Revision 1.8 2002/02/04 09:40:21 grubert
300+
# . add test for multipart messages with first part being encoded.
301+
#
254302
# Revision 1.7 2002/01/22 11:54:45 rochecompaan
255303
# Fixed status change in mail gateway.
256304
#

0 commit comments

Comments
 (0)