annotate test/test_multipart.py @ 5418:55f09ca366c4

Python 3 preparation: StringIO. This generally arranges for StringIO and cStringIO references to use io.StringIO for Python 3 but io.BytesIO for Python 2, consistent with the string representations generally used in Roundup. A special FasterStringIO in the TAL code, which referenced internals of the old Python 2 StringIO module, is cut down so it doesn't actually do anything beyond the StringIO class it inherits from (it would also be reasonable to remove FasterStringIO completely). One place in roundup_server.py clearly needing binary I/O is made to use io.BytesIO unconditionally.
author Joseph Myers <jsm@polyomino.org.uk>
date Wed, 25 Jul 2018 09:08:29 +0000
parents 2120f77554d5
children 725266c03eab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
213
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
1 #
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
3 # This module is free software, and you may redistribute it and/or modify
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
4 # under the same terms as Python, so long as this copyright message and
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
5 # disclaimer are retained in their original form.
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
6 #
214
18134bffab37 stupid typo
Richard Jones <richard@users.sourceforge.net>
parents: 213
diff changeset
7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
213
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
10 # POSSIBILITY OF SUCH DAMAGE.
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
11 #
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 127
diff changeset
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
17
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
18 import unittest
5418
55f09ca366c4 Python 3 preparation: StringIO.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5400
diff changeset
19 from roundup.anypy.strings import StringIO
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
20
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
21 from roundup.mailgw import Message
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
22
5035
b5bb492e4b3c Rename TestMessage to ExampleMessage
John Kristensen <john@jerrykan.com>
parents: 4570
diff changeset
23 class ExampleMessage(Message):
4425
0bb3054274b8 - some formatting
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3915
diff changeset
24 # A note on message/rfc822: The content of such an attachment is an
0bb3054274b8 - some formatting
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3915
diff changeset
25 # email with at least one header line. RFC2046 tells us: """ A
0bb3054274b8 - some formatting
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3915
diff changeset
26 # media type of "message/rfc822" indicates that the body contains an
0bb3054274b8 - some formatting
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3915
diff changeset
27 # encapsulated message, with the syntax of an RFC 822 message.
0bb3054274b8 - some formatting
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3915
diff changeset
28 # However, unlike top-level RFC 822 messages, the restriction that
0bb3054274b8 - some formatting
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3915
diff changeset
29 # each "message/rfc822" body must include a "From", "Date", and at
0bb3054274b8 - some formatting
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3915
diff changeset
30 # least one destination header is removed and replaced with the
0bb3054274b8 - some formatting
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3915
diff changeset
31 # requirement that at least one of "From", "Subject", or "Date" must
0bb3054274b8 - some formatting
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3915
diff changeset
32 # be present."""
0bb3054274b8 - some formatting
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3915
diff changeset
33 # This means we have to add a newline after the mime-header before
0bb3054274b8 - some formatting
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3915
diff changeset
34 # the subject, otherwise the subject is part of the mime header not
0bb3054274b8 - some formatting
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3915
diff changeset
35 # part of the email header.
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
36 table = {'multipart/signed': ' boundary="boundary-%(indent)s";\n',
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
37 'multipart/mixed': ' boundary="boundary-%(indent)s";\n',
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
38 'multipart/alternative': ' boundary="boundary-%(indent)s";\n',
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
39 'text/plain': ' name="foo.txt"\nfoo\n',
5307
5b4931cfc182 Test entity code path in dehtml.
John Rouillard <rouilj@ieee.org>
parents: 5306
diff changeset
40 'text/html': ' name="bar.html"\n<html><body>bar &gt;</body></html>\n',
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
41 'application/pgp-signature': ' name="foo.gpg"\nfoo\n',
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
42 'application/pdf': ' name="foo.pdf"\nfoo\n',
4425
0bb3054274b8 - some formatting
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3915
diff changeset
43 'message/rfc822': '\nSubject: foo\n\nfoo\n'}
3915
6b3919328381 support for receiving OpenPGP MIME messages (signed or encrypted)
Justus Pendleton <jpend@users.sourceforge.net>
parents: 1975
diff changeset
44
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
45 def __init__(self, spec):
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
46 """Create a basic MIME message according to 'spec'.
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
47
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
48 Each line of a spec has one content-type, which is optionally indented.
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
49 The indentation signifies how deep in the MIME hierarchy the
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
50 content-type is.
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
51
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
52 """
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
53 parts = []
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
54 for line in spec.splitlines():
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
55 content_type = line.strip()
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
56 if not content_type:
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
57 continue
3915
6b3919328381 support for receiving OpenPGP MIME messages (signed or encrypted)
Justus Pendleton <jpend@users.sourceforge.net>
parents: 1975
diff changeset
58
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
59 indent = self.getIndent(line)
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
60 if indent:
3915
6b3919328381 support for receiving OpenPGP MIME messages (signed or encrypted)
Justus Pendleton <jpend@users.sourceforge.net>
parents: 1975
diff changeset
61 parts.append('\n--boundary-%s\n' % indent)
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
62 parts.append('Content-type: %s;\n' % content_type)
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
63 parts.append(self.table[content_type] % {'indent': indent + 1})
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
64
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
65 Message.__init__(self, StringIO(''.join(parts)))
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
66
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
67 def getIndent(self, line):
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
68 """Get the current line's indentation, using four-space indents."""
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
69 count = 0
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
70 for char in line:
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
71 if char != ' ':
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
72 break
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
73 count += 1
5400
2120f77554d5 Python 3 preparation: use // and __truediv__ as needed.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5307
diff changeset
74 return count // 4
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
75
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
76 class MultipartTestCase(unittest.TestCase):
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
77 def setUp(self):
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
78 self.fp = StringIO()
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
79 w = self.fp.write
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
80 w('Content-Type: multipart/mixed; boundary="foo"\r\n\r\n')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
81 w('This is a multipart message. Ignore this bit.\r\n')
3915
6b3919328381 support for receiving OpenPGP MIME messages (signed or encrypted)
Justus Pendleton <jpend@users.sourceforge.net>
parents: 1975
diff changeset
82 w('\r\n--foo\r\n')
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
83
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
84 w('Content-Type: text/plain\r\n\r\n')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
85 w('Hello, world!\r\n')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
86 w('\r\n')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
87 w('Blah blah\r\n')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
88 w('foo\r\n')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
89 w('-foo\r\n')
3915
6b3919328381 support for receiving OpenPGP MIME messages (signed or encrypted)
Justus Pendleton <jpend@users.sourceforge.net>
parents: 1975
diff changeset
90 w('\r\n--foo\r\n')
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
91
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
92 w('Content-Type: multipart/alternative; boundary="bar"\r\n\r\n')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
93 w('This is a multipart message. Ignore this bit.\r\n')
3915
6b3919328381 support for receiving OpenPGP MIME messages (signed or encrypted)
Justus Pendleton <jpend@users.sourceforge.net>
parents: 1975
diff changeset
94 w('\r\n--bar\r\n')
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
95
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
96 w('Content-Type: text/plain\r\n\r\n')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
97 w('Hello, world!\r\n')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
98 w('\r\n')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
99 w('Blah blah\r\n')
3915
6b3919328381 support for receiving OpenPGP MIME messages (signed or encrypted)
Justus Pendleton <jpend@users.sourceforge.net>
parents: 1975
diff changeset
100 w('\r\n--bar\r\n')
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
101
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
102 w('Content-Type: text/html\r\n\r\n')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
103 w('<b>Hello, world!</b>\r\n')
3915
6b3919328381 support for receiving OpenPGP MIME messages (signed or encrypted)
Justus Pendleton <jpend@users.sourceforge.net>
parents: 1975
diff changeset
104 w('\r\n--bar--\r\n')
6b3919328381 support for receiving OpenPGP MIME messages (signed or encrypted)
Justus Pendleton <jpend@users.sourceforge.net>
parents: 1975
diff changeset
105 w('\r\n--foo\r\n')
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
106
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
107 w('Content-Type: text/plain\r\n\r\n')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
108 w('Last bit\n')
3915
6b3919328381 support for receiving OpenPGP MIME messages (signed or encrypted)
Justus Pendleton <jpend@users.sourceforge.net>
parents: 1975
diff changeset
109 w('\r\n--foo--\r\n')
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
110 self.fp.seek(0)
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
111
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
112 def testMultipart(self):
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
113 m = Message(self.fp)
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
114 self.assert_(m is not None)
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
115
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
116 # skip the first bit
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
117 p = m.getpart()
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
118 self.assert_(p is not None)
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
119 self.assertEqual(p.fp.read(),
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
120 'This is a multipart message. Ignore this bit.\r\n')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
121
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
122 # first text/plain
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
123 p = m.getpart()
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
124 self.assert_(p is not None)
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
125 self.assertEqual(p.gettype(), 'text/plain')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
126 self.assertEqual(p.fp.read(),
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
127 'Hello, world!\r\n\r\nBlah blah\r\nfoo\r\n-foo\r\n')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
128
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
129 # sub-multipart
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
130 p = m.getpart()
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
131 self.assert_(p is not None)
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
132 self.assertEqual(p.gettype(), 'multipart/alternative')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
133
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
134 # sub-multipart text/plain
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
135 q = p.getpart()
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
136 self.assert_(q is not None)
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
137 q = p.getpart()
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
138 self.assert_(q is not None)
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
139 self.assertEqual(q.gettype(), 'text/plain')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
140 self.assertEqual(q.fp.read(), 'Hello, world!\r\n\r\nBlah blah\r\n')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
141
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
142 # sub-multipart text/html
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
143 q = p.getpart()
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
144 self.assert_(q is not None)
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
145 self.assertEqual(q.gettype(), 'text/html')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
146 self.assertEqual(q.fp.read(), '<b>Hello, world!</b>\r\n')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
147
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
148 # sub-multipart end
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
149 q = p.getpart()
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
150 self.assert_(q is None)
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
151
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
152 # final text/plain
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
153 p = m.getpart()
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
154 self.assert_(p is not None)
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
155 self.assertEqual(p.gettype(), 'text/plain')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
156 self.assertEqual(p.fp.read(),
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
157 'Last bit\n')
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
158
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
159 # end
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
160 p = m.getpart()
110
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
161 self.assert_(p is None)
19686b60e410 Multipart message class has the getPart method now. Added some tests for it.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
162
5306
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
163 def TestExtraction(self, spec, expected, convert_html_with=False):
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
164 if convert_html_with:
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
165 from roundup.dehtml import dehtml
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
166 html2text=dehtml(convert_html_with).html2text
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
167 else:
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
168 html2text=None
5305
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
169
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
170 self.assertEqual(ExampleMessage(spec).extract_content(
5306
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
171 html2text=html2text), expected)
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
172
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
173 def testTextPlain(self):
5305
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
174 self.TestExtraction('text/plain', ('foo\n', [], False))
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
175
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
176 def testAttachedTextPlain(self):
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
177 self.TestExtraction("""
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
178 multipart/mixed
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
179 text/plain
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
180 text/plain""",
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
181 ('foo\n',
5305
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
182 [('foo.txt', 'text/plain', 'foo\n')], False))
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
183
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
184 def testMultipartMixed(self):
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
185 self.TestExtraction("""
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
186 multipart/mixed
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
187 text/plain
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
188 application/pdf""",
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
189 ('foo\n',
5305
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
190 [('foo.pdf', 'application/pdf', 'foo\n')], False))
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
191
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
192 def testMultipartMixedHtml(self):
5306
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
193 # test with html conversion enabled
5305
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
194 self.TestExtraction("""
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
195 multipart/mixed
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
196 text/html
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
197 application/pdf""",
5307
5b4931cfc182 Test entity code path in dehtml.
John Rouillard <rouilj@ieee.org>
parents: 5306
diff changeset
198 ('bar >\n',
5305
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
199 [('bar.html', 'text/html',
5307
5b4931cfc182 Test entity code path in dehtml.
John Rouillard <rouilj@ieee.org>
parents: 5306
diff changeset
200 '<html><body>bar &gt;</body></html>\n'),
5306
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
201 ('foo.pdf', 'application/pdf', 'foo\n')], False),
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
202 convert_html_with='dehtml')
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
203
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
204 # test with html conversion disabled
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
205 self.TestExtraction("""
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
206 multipart/mixed
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
207 text/html
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
208 application/pdf""",
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
209 (None,
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
210 [('bar.html', 'text/html',
5307
5b4931cfc182 Test entity code path in dehtml.
John Rouillard <rouilj@ieee.org>
parents: 5306
diff changeset
211 '<html><body>bar &gt;</body></html>\n'),
5306
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
212 ('foo.pdf', 'application/pdf', 'foo\n')], False),
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
213 convert_html_with=False)
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
214
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
215 def testMultipartAlternative(self):
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
216 self.TestExtraction("""
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
217 multipart/alternative
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
218 text/plain
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
219 application/pdf
5305
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
220 """, ('foo\n', [('foo.pdf', 'application/pdf', 'foo\n')], False))
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
221
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
222 def testMultipartAlternativeHtml(self):
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
223 self.TestExtraction("""
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
224 multipart/alternative
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
225 text/html
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
226 application/pdf""",
5307
5b4931cfc182 Test entity code path in dehtml.
John Rouillard <rouilj@ieee.org>
parents: 5306
diff changeset
227 ('bar >\n',
5305
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
228 [('bar.html', 'text/html',
5307
5b4931cfc182 Test entity code path in dehtml.
John Rouillard <rouilj@ieee.org>
parents: 5306
diff changeset
229 '<html><body>bar &gt;</body></html>\n'),
5306
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
230 ('foo.pdf', 'application/pdf', 'foo\n')], False),
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
231 convert_html_with='dehtml')
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
232
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
233 self.TestExtraction("""
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
234 multipart/alternative
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
235 text/html
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
236 application/pdf""",
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
237 (None,
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
238 [('bar.html', 'text/html',
5307
5b4931cfc182 Test entity code path in dehtml.
John Rouillard <rouilj@ieee.org>
parents: 5306
diff changeset
239 '<html><body>bar &gt;</body></html>\n'),
5306
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
240 ('foo.pdf', 'application/pdf', 'foo\n')], False),
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
241 convert_html_with=False)
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
242
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
243 def testMultipartAlternativeHtmlText(self):
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
244 # text should take priority over html when html is first
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
245 self.TestExtraction("""
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
246 multipart/alternative
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
247 text/html
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
248 text/plain
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
249 application/pdf""",
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
250 ('foo\n',
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
251 [('bar.html', 'text/html',
5307
5b4931cfc182 Test entity code path in dehtml.
John Rouillard <rouilj@ieee.org>
parents: 5306
diff changeset
252 '<html><body>bar &gt;</body></html>\n'),
5306
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
253 ('foo.pdf', 'application/pdf', 'foo\n')], False),
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
254 convert_html_with='dehtml')
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
255
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
256 # text should take priority over html when text is first
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
257 self.TestExtraction("""
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
258 multipart/alternative
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
259 text/plain
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
260 text/html
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
261 application/pdf""",
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
262 ('foo\n',
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
263 [('bar.html', 'text/html',
5307
5b4931cfc182 Test entity code path in dehtml.
John Rouillard <rouilj@ieee.org>
parents: 5306
diff changeset
264 '<html><body>bar &gt;</body></html>\n'),
5306
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
265 ('foo.pdf', 'application/pdf', 'foo\n')], False),
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
266 convert_html_with='dehtml')
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
267
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
268 # text should take priority over html when text is second and
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
269 # html is disabled
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
270 self.TestExtraction("""
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
271 multipart/alternative
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
272 text/html
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
273 text/plain
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
274 application/pdf""",
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
275 ('foo\n',
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
276 [('bar.html', 'text/html',
5307
5b4931cfc182 Test entity code path in dehtml.
John Rouillard <rouilj@ieee.org>
parents: 5306
diff changeset
277 '<html><body>bar &gt;</body></html>\n'),
5306
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
278 ('foo.pdf', 'application/pdf', 'foo\n')], False),
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
279 convert_html_with=False)
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
280
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
281 # text should take priority over html when text is first and
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
282 # html is disabled
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
283 self.TestExtraction("""
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
284 multipart/alternative
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
285 text/plain
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
286 text/html
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
287 application/pdf""",
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
288 ('foo\n',
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
289 [('bar.html', 'text/html',
5307
5b4931cfc182 Test entity code path in dehtml.
John Rouillard <rouilj@ieee.org>
parents: 5306
diff changeset
290 '<html><body>bar &gt;</body></html>\n'),
5306
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
291 ('foo.pdf', 'application/pdf', 'foo\n')], False),
91354bf0b683 Codecov showed text/html followed by text/plain not tested. Fixed bug
John Rouillard <rouilj@ieee.org>
parents: 5305
diff changeset
292 convert_html_with=False)
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
293
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
294 def testDeepMultipartAlternative(self):
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
295 self.TestExtraction("""
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
296 multipart/mixed
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
297 multipart/alternative
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
298 text/plain
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
299 application/pdf
5305
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
300 """, ('foo\n', [('foo.pdf', 'application/pdf', 'foo\n')], False))
3915
6b3919328381 support for receiving OpenPGP MIME messages (signed or encrypted)
Justus Pendleton <jpend@users.sourceforge.net>
parents: 1975
diff changeset
301
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
302 def testSignedText(self):
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
303 self.TestExtraction("""
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
304 multipart/signed
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
305 text/plain
5305
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
306 application/pgp-signature""", ('foo\n', [], False))
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
307
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
308 def testSignedAttachments(self):
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
309 self.TestExtraction("""
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
310 multipart/signed
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
311 multipart/mixed
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
312 text/plain
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
313 application/pdf
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
314 application/pgp-signature""",
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
315 ('foo\n',
5305
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
316 [('foo.pdf', 'application/pdf', 'foo\n')], False))
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
317
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
318 def testAttachedSignature(self):
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
319 self.TestExtraction("""
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
320 multipart/mixed
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
321 text/plain
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
322 application/pgp-signature""",
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
323 ('foo\n',
5305
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
324 [('foo.gpg', 'application/pgp-signature', 'foo\n')], False))
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
325
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
326 def testMessageRfc822(self):
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
327 self.TestExtraction("""
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
328 multipart/mixed
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
329 message/rfc822""",
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
330 (None,
5305
e20f472fde7d issue2550799: provide basic support for handling html only emails
John Rouillard <rouilj@ieee.org>
parents: 5037
diff changeset
331 [('foo.eml', 'message/rfc822', 'Subject: foo\n\nfoo\n')], False))
1975
30a444b7b212 *** empty log message ***
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents: 1873
diff changeset
332
127
0791d13baea7 Added vim command to all source so that we don't get no steenkin' tabs :)
Richard Jones <richard@users.sourceforge.net>
parents: 110
diff changeset
333 # vim: set filetype=python ts=4 sw=4 et si

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