Mercurial > p > roundup > code
comparison test/test_multipart.py @ 4425:0bb3054274b8
- some formatting
- fix broken regression-test for message/rfc822 in test_multipart -- the
rfc822 message must have its own header -- this is where we have to
look for the subject. This means we have to include a newline before
the Subject in the test-message, otherwise the Subject line is part of
the mime header, not part of the email attachment.
| author | Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net> |
|---|---|
| date | Wed, 06 Oct 2010 14:13:09 +0000 |
| parents | 6b3919328381 |
| children | 6e3e4f24c753 |
comparison
equal
deleted
inserted
replaced
| 4424:f1affb6b7a08 | 4425:0bb3054274b8 |
|---|---|
| 21 from cStringIO import StringIO | 21 from cStringIO import StringIO |
| 22 | 22 |
| 23 from roundup.mailgw import Message | 23 from roundup.mailgw import Message |
| 24 | 24 |
| 25 class TestMessage(Message): | 25 class TestMessage(Message): |
| 26 # A note on message/rfc822: The content of such an attachment is an | |
| 27 # email with at least one header line. RFC2046 tells us: """ A | |
| 28 # media type of "message/rfc822" indicates that the body contains an | |
| 29 # encapsulated message, with the syntax of an RFC 822 message. | |
| 30 # However, unlike top-level RFC 822 messages, the restriction that | |
| 31 # each "message/rfc822" body must include a "From", "Date", and at | |
| 32 # least one destination header is removed and replaced with the | |
| 33 # requirement that at least one of "From", "Subject", or "Date" must | |
| 34 # be present.""" | |
| 35 # This means we have to add a newline after the mime-header before | |
| 36 # the subject, otherwise the subject is part of the mime header not | |
| 37 # part of the email header. | |
| 26 table = {'multipart/signed': ' boundary="boundary-%(indent)s";\n', | 38 table = {'multipart/signed': ' boundary="boundary-%(indent)s";\n', |
| 27 'multipart/mixed': ' boundary="boundary-%(indent)s";\n', | 39 'multipart/mixed': ' boundary="boundary-%(indent)s";\n', |
| 28 'multipart/alternative': ' boundary="boundary-%(indent)s";\n', | 40 'multipart/alternative': ' boundary="boundary-%(indent)s";\n', |
| 29 'text/plain': ' name="foo.txt"\nfoo\n', | 41 'text/plain': ' name="foo.txt"\nfoo\n', |
| 30 'application/pgp-signature': ' name="foo.gpg"\nfoo\n', | 42 'application/pgp-signature': ' name="foo.gpg"\nfoo\n', |
| 31 'application/pdf': ' name="foo.pdf"\nfoo\n', | 43 'application/pdf': ' name="foo.pdf"\nfoo\n', |
| 32 'message/rfc822': 'Subject: foo\n\nfoo\n'} | 44 'message/rfc822': '\nSubject: foo\n\nfoo\n'} |
| 33 | 45 |
| 34 def __init__(self, spec): | 46 def __init__(self, spec): |
| 35 """Create a basic MIME message according to 'spec'. | 47 """Create a basic MIME message according to 'spec'. |
| 36 | 48 |
| 37 Each line of a spec has one content-type, which is optionally indented. | 49 Each line of a spec has one content-type, which is optionally indented. |
| 213 def testMessageRfc822(self): | 225 def testMessageRfc822(self): |
| 214 self.TestExtraction(""" | 226 self.TestExtraction(""" |
| 215 multipart/mixed | 227 multipart/mixed |
| 216 message/rfc822""", | 228 message/rfc822""", |
| 217 (None, | 229 (None, |
| 218 [('foo', 'message/rfc822', 'foo\n')])) | 230 [('foo.eml', 'message/rfc822', 'Subject: foo\n\nfoo\n')])) |
| 219 | 231 |
| 220 def test_suite(): | 232 def test_suite(): |
| 221 suite = unittest.TestSuite() | 233 suite = unittest.TestSuite() |
| 222 suite.addTest(unittest.makeSuite(MultipartTestCase)) | 234 suite.addTest(unittest.makeSuite(MultipartTestCase)) |
| 223 return suite | 235 return suite |
