comparison test/test_multipart.py @ 3915:6b3919328381

support for receiving OpenPGP MIME messages (signed or encrypted) This introduces some new config options that still need to be documented. This required a small fix for roundup's handling of MIME boundaries. The multipart tests were changed to have boundaries that match this new handling.
author Justus Pendleton <jpend@users.sourceforge.net>
date Sat, 22 Sep 2007 07:25:35 +0000
parents 30a444b7b212
children 0bb3054274b8
comparison
equal deleted inserted replaced
3914:a1b3692f5b1e 3915:6b3919328381
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 # 17 #
18 # $Id: test_multipart.py,v 1.7 2004-01-17 13:49:06 jlgijsbers Exp $ 18 # $Id: test_multipart.py,v 1.8 2007-09-22 07:25:35 jpend Exp $
19 19
20 import unittest 20 import unittest
21 from cStringIO import StringIO 21 from cStringIO import StringIO
22 22
23 from roundup.mailgw import Message 23 from roundup.mailgw import Message
28 'multipart/alternative': ' boundary="boundary-%(indent)s";\n', 28 'multipart/alternative': ' boundary="boundary-%(indent)s";\n',
29 'text/plain': ' name="foo.txt"\nfoo\n', 29 'text/plain': ' name="foo.txt"\nfoo\n',
30 'application/pgp-signature': ' name="foo.gpg"\nfoo\n', 30 'application/pgp-signature': ' name="foo.gpg"\nfoo\n',
31 'application/pdf': ' name="foo.pdf"\nfoo\n', 31 'application/pdf': ' name="foo.pdf"\nfoo\n',
32 'message/rfc822': 'Subject: foo\n\nfoo\n'} 32 'message/rfc822': 'Subject: foo\n\nfoo\n'}
33 33
34 def __init__(self, spec): 34 def __init__(self, spec):
35 """Create a basic MIME message according to 'spec'. 35 """Create a basic MIME message according to 'spec'.
36 36
37 Each line of a spec has one content-type, which is optionally indented. 37 Each line of a spec has one content-type, which is optionally indented.
38 The indentation signifies how deep in the MIME hierarchy the 38 The indentation signifies how deep in the MIME hierarchy the
42 parts = [] 42 parts = []
43 for line in spec.splitlines(): 43 for line in spec.splitlines():
44 content_type = line.strip() 44 content_type = line.strip()
45 if not content_type: 45 if not content_type:
46 continue 46 continue
47 47
48 indent = self.getIndent(line) 48 indent = self.getIndent(line)
49 if indent: 49 if indent:
50 parts.append('--boundary-%s\n' % indent) 50 parts.append('\n--boundary-%s\n' % indent)
51 parts.append('Content-type: %s;\n' % content_type) 51 parts.append('Content-type: %s;\n' % content_type)
52 parts.append(self.table[content_type] % {'indent': indent + 1}) 52 parts.append(self.table[content_type] % {'indent': indent + 1})
53 53
54 Message.__init__(self, StringIO(''.join(parts))) 54 Message.__init__(self, StringIO(''.join(parts)))
55 55
66 def setUp(self): 66 def setUp(self):
67 self.fp = StringIO() 67 self.fp = StringIO()
68 w = self.fp.write 68 w = self.fp.write
69 w('Content-Type: multipart/mixed; boundary="foo"\r\n\r\n') 69 w('Content-Type: multipart/mixed; boundary="foo"\r\n\r\n')
70 w('This is a multipart message. Ignore this bit.\r\n') 70 w('This is a multipart message. Ignore this bit.\r\n')
71 w('--foo\r\n') 71 w('\r\n--foo\r\n')
72 72
73 w('Content-Type: text/plain\r\n\r\n') 73 w('Content-Type: text/plain\r\n\r\n')
74 w('Hello, world!\r\n') 74 w('Hello, world!\r\n')
75 w('\r\n') 75 w('\r\n')
76 w('Blah blah\r\n') 76 w('Blah blah\r\n')
77 w('foo\r\n') 77 w('foo\r\n')
78 w('-foo\r\n') 78 w('-foo\r\n')
79 w('--foo\r\n') 79 w('\r\n--foo\r\n')
80 80
81 w('Content-Type: multipart/alternative; boundary="bar"\r\n\r\n') 81 w('Content-Type: multipart/alternative; boundary="bar"\r\n\r\n')
82 w('This is a multipart message. Ignore this bit.\r\n') 82 w('This is a multipart message. Ignore this bit.\r\n')
83 w('--bar\r\n') 83 w('\r\n--bar\r\n')
84 84
85 w('Content-Type: text/plain\r\n\r\n') 85 w('Content-Type: text/plain\r\n\r\n')
86 w('Hello, world!\r\n') 86 w('Hello, world!\r\n')
87 w('\r\n') 87 w('\r\n')
88 w('Blah blah\r\n') 88 w('Blah blah\r\n')
89 w('--bar\r\n') 89 w('\r\n--bar\r\n')
90 90
91 w('Content-Type: text/html\r\n\r\n') 91 w('Content-Type: text/html\r\n\r\n')
92 w('<b>Hello, world!</b>\r\n') 92 w('<b>Hello, world!</b>\r\n')
93 w('--bar--\r\n') 93 w('\r\n--bar--\r\n')
94 w('--foo\r\n') 94 w('\r\n--foo\r\n')
95 95
96 w('Content-Type: text/plain\r\n\r\n') 96 w('Content-Type: text/plain\r\n\r\n')
97 w('Last bit\n') 97 w('Last bit\n')
98 w('--foo--\r\n') 98 w('\r\n--foo--\r\n')
99 self.fp.seek(0) 99 self.fp.seek(0)
100 100
101 def testMultipart(self): 101 def testMultipart(self):
102 m = Message(self.fp) 102 m = Message(self.fp)
103 self.assert_(m is not None) 103 self.assert_(m is not None)
183 multipart/mixed 183 multipart/mixed
184 multipart/alternative 184 multipart/alternative
185 text/plain 185 text/plain
186 application/pdf 186 application/pdf
187 """, ('foo\n', [('foo.pdf', 'application/pdf', 'foo\n')])) 187 """, ('foo\n', [('foo.pdf', 'application/pdf', 'foo\n')]))
188 188
189 def testSignedText(self): 189 def testSignedText(self):
190 self.TestExtraction(""" 190 self.TestExtraction("""
191 multipart/signed 191 multipart/signed
192 text/plain 192 text/plain
193 application/pgp-signature""", ('foo\n', [])) 193 application/pgp-signature""", ('foo\n', []))

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