diff roundup/mailgw.py @ 594:82555a1429d0

mailgw checks encoding on first part too.
author Engelbert Gruber <grubert@users.sourceforge.net>
date Fri, 01 Feb 2002 07:43:12 +0000
parents b43f031f3946
children 4c3dcda799f7
line wrap: on
line diff
--- a/roundup/mailgw.py	Tue Jan 29 20:07:15 2002 +0000
+++ b/roundup/mailgw.py	Fri Feb 01 07:43:12 2002 +0000
@@ -73,7 +73,7 @@
 an exception, the original message is bounced back to the sender with the
 explanatory message given in the exception. 
 
-$Id: mailgw.py,v 1.59 2002-01-23 21:43:23 richard Exp $
+$Id: mailgw.py,v 1.60 2002-02-01 07:43:12 grubert Exp $
 '''
 
 
@@ -487,8 +487,27 @@
                 subtype = part.gettype()
                 if subtype == 'text/plain' and not content:
                     # add all text/plain parts to the message content
+                    # BUG (in code or comment) only add the first one. 
                     if content is None:
-                        content = part.fp.read()
+                        # try name on Content-Type
+                        # maybe add name to non text content ?
+                        name = part.getparam('name')
+                        # assume first part is the mail
+                        encoding = part.getencoding()
+                        if encoding == 'base64':
+                            data = binascii.a2b_base64(part.fp.read())
+                        elif encoding == 'quoted-printable':
+                            # the quopri module wants to work with files
+                            decoded = cStringIO.StringIO()
+                            quopri.decode(part.fp, decoded)
+                            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()
+                        content = data
                     else:
                         content = content + part.fp.read()
 
@@ -516,7 +535,6 @@
                     elif encoding == 'uuencoded':
                         data = binascii.a2b_uu(part.fp.read())
                     attachments.append((name, part.gettype(), data))
-
             if content is None:
                 raise MailUsageError, '''
 Roundup requires the submission to be plain text. The message parser could
@@ -757,6 +775,9 @@
 
 #
 # $Log: not supported by cvs2svn $
+# Revision 1.59  2002/01/23 21:43:23  richard
+# tabnuke
+#
 # Revision 1.58  2002/01/23 21:41:56  richard
 #  . mailgw failures (unexpected ones) are forwarded to the roundup admin
 #

Roundup Issue Tracker: http://roundup-tracker.org/