Code

When debugging mail (debug = <filename> setting in [mail] section of
[roundup.git] / test / test_multipart.py
index 99e0bf40427c5eea920b0dc8c08f9ba951c862fe..0cbc384c668a7cf5b9e4bc65f505dd56066a1fd4 100644 (file)
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: test_multipart.py,v 1.7 2004-01-17 13:49:06 jlgijsbers Exp $ 
+# $Id: test_multipart.py,v 1.8 2007-09-22 07:25:35 jpend Exp $ 
 
 import unittest
 from cStringIO import StringIO
@@ -23,14 +23,26 @@ from cStringIO import StringIO
 from roundup.mailgw import Message
 
 class TestMessage(Message):
+    # A note on message/rfc822: The content of such an attachment is an
+    # email with at least one header line. RFC2046 tells us: """   A
+    # media type of "message/rfc822" indicates that the body contains an
+    # encapsulated message, with the syntax of an RFC 822 message.
+    # However, unlike top-level RFC 822 messages, the restriction that
+    # each "message/rfc822" body must include a "From", "Date", and at
+    # least one destination header is removed and replaced with the
+    # requirement that at least one of "From", "Subject", or "Date" must
+    # be present."""
+    # This means we have to add a newline after the mime-header before
+    # the subject, otherwise the subject is part of the mime header not
+    # part of the email header.
     table = {'multipart/signed': '    boundary="boundary-%(indent)s";\n',
              'multipart/mixed': '    boundary="boundary-%(indent)s";\n',
              'multipart/alternative': '    boundary="boundary-%(indent)s";\n',
              'text/plain': '    name="foo.txt"\nfoo\n',
              'application/pgp-signature': '    name="foo.gpg"\nfoo\n',
              'application/pdf': '    name="foo.pdf"\nfoo\n',
-             'message/rfc822': 'Subject: foo\n\nfoo\n'}
-    
+             'message/rfc822': '\nSubject: foo\n\nfoo\n'}
+
     def __init__(self, spec):
         """Create a basic MIME message according to 'spec'.
 
@@ -44,10 +56,10 @@ class TestMessage(Message):
             content_type = line.strip()
             if not content_type:
                 continue
-            
+
             indent = self.getIndent(line)
             if indent:
-                parts.append('--boundary-%s\n' % indent)
+                parts.append('\n--boundary-%s\n' % indent)
             parts.append('Content-type: %s;\n' % content_type)
             parts.append(self.table[content_type] % {'indent': indent + 1})
 
@@ -68,7 +80,7 @@ class MultipartTestCase(unittest.TestCase):
         w = self.fp.write
         w('Content-Type: multipart/mixed; boundary="foo"\r\n\r\n')
         w('This is a multipart message. Ignore this bit.\r\n')
-        w('--foo\r\n')
+        w('\r\n--foo\r\n')
 
         w('Content-Type: text/plain\r\n\r\n')
         w('Hello, world!\r\n')
@@ -76,26 +88,26 @@ class MultipartTestCase(unittest.TestCase):
         w('Blah blah\r\n')
         w('foo\r\n')
         w('-foo\r\n')
-        w('--foo\r\n')
+        w('\r\n--foo\r\n')
 
         w('Content-Type: multipart/alternative; boundary="bar"\r\n\r\n')
         w('This is a multipart message. Ignore this bit.\r\n')
-        w('--bar\r\n')
+        w('\r\n--bar\r\n')
 
         w('Content-Type: text/plain\r\n\r\n')
         w('Hello, world!\r\n')
         w('\r\n')
         w('Blah blah\r\n')
-        w('--bar\r\n')
+        w('\r\n--bar\r\n')
 
         w('Content-Type: text/html\r\n\r\n')
         w('<b>Hello, world!</b>\r\n')
-        w('--bar--\r\n')
-        w('--foo\r\n')
+        w('\r\n--bar--\r\n')
+        w('\r\n--foo\r\n')
 
         w('Content-Type: text/plain\r\n\r\n')
         w('Last bit\n')
-        w('--foo--\r\n')
+        w('\r\n--foo--\r\n')
         self.fp.seek(0)
 
     def testMultipart(self):
@@ -185,7 +197,7 @@ multipart/mixed
         text/plain
         application/pdf
 """, ('foo\n', [('foo.pdf', 'application/pdf', 'foo\n')]))
-    
+
     def testSignedText(self):
         self.TestExtraction("""
 multipart/signed
@@ -215,7 +227,7 @@ multipart/mixed
 multipart/mixed
     message/rfc822""",
                   (None,
-                   [('foo', 'message/rfc822', 'foo\n')]))
+                   [('foo.eml', 'message/rfc822', 'Subject: foo\n\nfoo\n')]))
 
 def test_suite():
     suite = unittest.TestSuite()