Code

. respect encodings in non multipart messages.
authorgrubert <grubert@57a73879-2fb5-44c3-a270-3262357dd7e2>
Tue, 5 Feb 2002 14:15:29 +0000 (14:15 +0000)
committergrubert <grubert@57a73879-2fb5-44c3-a270-3262357dd7e2>
Tue, 5 Feb 2002 14:15:29 +0000 (14:15 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@612 57a73879-2fb5-44c3-a270-3262357dd7e2

CHANGES.txt
roundup/mailgw.py
test/test_mailgw.py

index 8307c0fefba045b19e8ce07814494fe49ca2b452..84f02a598d75645a6e1ac7009fa73196b7a69b7f 100644 (file)
@@ -10,6 +10,7 @@ Feature:
  . you can now use the roundup-admin tool pack the database
 
 Fixed:
  . 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.
  . 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.
index bf02c3bd1c29fbd6b692b58b7ffd612d41e9f144..b624b1bc6f560e3cc6db156344d38166c9bd7855 100644 (file)
@@ -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. 
 
 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())
                             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()
                         else:
                             # take it as text
                             data = part.fp.read()
@@ -569,8 +568,23 @@ not find a text/plain part to use.
 '''
 
         else:
 '''
 
         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)
 
         # 
         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 $
 
 #
 # $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.
 #
 # Revision 1.60  2002/02/01 07:43:12  grubert
 #  . mailgw checks encoding on first part too.
 #
index cb53984dc4cdd0e275daada0b0972e3edf4640fe..382c8f27805ad2e7161389bb5daf3ac080458998 100644 (file)
@@ -8,7 +8,7 @@
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 #
 # 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
 
 
 import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys
 
@@ -188,6 +188,51 @@ http://some.useful.url/issue1
 ___________________________________________________
 ''', 'Generated message not correct')
 
 ___________________________________________________
 ''', 'Generated message not correct')
 
+    def testEnc01(self):
+        self.testNewIssue()
+        message = cStringIO.StringIO('''Content-Type: text/plain;
+  charset="iso-8859-1"
+From: mary <mary@test>
+To: issue_tracker@fill.me.in.
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+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 <issue_tracker@fill.me.in.>
+Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.>
+MIME-Version: 1.0
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+
+
+mary <mary@test> added the comment:
+
+A message with encoding (encoded oe รถ)
+
+----------
+status: unread -> chatting
+___________________________________________________
+"Roundup issue tracker" <issue_tracker@fill.me.in.>
+http://some.useful.url/issue1
+___________________________________________________
+''', 'Generated message not correct')
+
+
     def testMultipartEnc01(self):
         self.testNewIssue()
         message = cStringIO.StringIO('''Content-Type: text/plain;
     def testMultipartEnc01(self):
         self.testNewIssue()
         message = cStringIO.StringIO('''Content-Type: text/plain;
@@ -251,6 +296,9 @@ def suite():
 
 #
 # $Log: not supported by cvs2svn $
 
 #
 # $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.
 #
 # Revision 1.7  2002/01/22 11:54:45  rochecompaan
 # Fixed status change in mail gateway.
 #