From 1cbbb3c14250a5802ae6422a27da2e158618a411 Mon Sep 17 00:00:00 2001 From: grubert Date: Tue, 5 Feb 2002 14:15:29 +0000 Subject: [PATCH] . respect encodings in non multipart messages. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@612 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 1 + roundup/mailgw.py | 25 +++++++++++++++++++---- test/test_mailgw.py | 50 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 71 insertions(+), 5 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 8307c0f..84f02a5 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -10,6 +10,7 @@ Feature: . you can now use the roundup-admin tool pack the database Fixed: + . respect encodings in non multipart messages. . makeHtmlBase: re.sub under python 2.2 did not replace '.', string.replace does it. . preamble in tepmlateBuilder mentioned htmldata . mailgw checks encoding on first part too. diff --git a/roundup/mailgw.py b/roundup/mailgw.py index bf02c3b..b624b1b 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.61 2002-02-04 09:40:21 grubert Exp $ +$Id: mailgw.py,v 1.62 2002-02-05 14:15:29 grubert Exp $ ''' @@ -505,7 +505,6 @@ Unknown address: %s data = decoded.getvalue() elif encoding == 'uuencoded': data = binascii.a2b_uu(part.fp.read()) - attachments.append((name, part.gettype(), data)) else: # take it as text data = part.fp.read() @@ -569,8 +568,23 @@ not find a text/plain part to use. ''' else: - content = message.fp.read() - + encoding = message.getencoding() + if encoding == 'base64': + # BUG: is base64 really used for text encoding or + # are we inserting zip files here. + data = binascii.a2b_base64(message.fp.read()) + elif encoding == 'quoted-printable': + # the quopri module wants to work with files + decoded = cStringIO.StringIO() + quopri.decode(message.fp, decoded) + data = decoded.getvalue() + elif encoding == 'uuencoded': + data = binascii.a2b_uu(message.fp.read()) + else: + # take it as text + data = message.fp.read() + content = data + summary, content = parseContent(content) # @@ -777,6 +791,9 @@ def parseContent(content, blank_line=re.compile(r'[\r\n]+\s*[\r\n]+'), # # $Log: not supported by cvs2svn $ +# Revision 1.61 2002/02/04 09:40:21 grubert +# . add test for multipart messages with first part being encoded. +# # Revision 1.60 2002/02/01 07:43:12 grubert # . mailgw checks encoding on first part too. # diff --git a/test/test_mailgw.py b/test/test_mailgw.py index cb53984..382c8f2 100644 --- a/test/test_mailgw.py +++ b/test/test_mailgw.py @@ -8,7 +8,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: test_mailgw.py,v 1.8 2002-02-04 09:40:21 grubert Exp $ +# $Id: test_mailgw.py,v 1.9 2002-02-05 14:15:29 grubert Exp $ import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys @@ -188,6 +188,51 @@ http://some.useful.url/issue1 ___________________________________________________ ''', 'Generated message not correct') + def testEnc01(self): + self.testNewIssue() + message = cStringIO.StringIO('''Content-Type: text/plain; + charset="iso-8859-1" +From: mary +To: issue_tracker@fill.me.in. +Message-Id: +In-Reply-To: +Subject: [issue1] Testing... +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + +A message with encoding (encoded oe =F6) + +''') + handler = self.instance.MailGW(self.instance, self.db) + handler.main(message) + message_data = open(os.environ['SENDMAILDEBUG']).read() + self.assertEqual(message_data, +'''FROM: roundup-admin@fill.me.in. +TO: chef@bork.bork.bork, richard@test +Content-Type: text/plain +Subject: [issue1] Testing... +To: chef@bork.bork.bork, richard@test +From: mary +Reply-To: Roundup issue tracker +MIME-Version: 1.0 +Message-Id: +In-Reply-To: + + +mary added the comment: + +A message with encoding (encoded oe รถ) + +---------- +status: unread -> chatting +___________________________________________________ +"Roundup issue tracker" +http://some.useful.url/issue1 +___________________________________________________ +''', 'Generated message not correct') + + def testMultipartEnc01(self): self.testNewIssue() message = cStringIO.StringIO('''Content-Type: text/plain; @@ -251,6 +296,9 @@ def suite(): # # $Log: not supported by cvs2svn $ +# Revision 1.8 2002/02/04 09:40:21 grubert +# . add test for multipart messages with first part being encoded. +# # Revision 1.7 2002/01/22 11:54:45 rochecompaan # Fixed status change in mail gateway. # -- 2.30.2