diff options
| author | R. David Murray <rdmurray@bitdance.com> | 2010-01-16 18:30:03 +0000 |
|---|---|---|
| committer | R. David Murray <rdmurray@bitdance.com> | 2010-01-16 18:30:03 +0000 |
| commit | a8f480f54597cf20e460b12e17bb0416a8008868 (patch) | |
| tree | 3ce1c3a6e2bdc298c8fcb530eeb4d14525b9495e /Lib/email/test/test_email.py | |
| parent | 9f96ffc8b9e647d0a192b20013d4b8fcff32f586 (diff) | |
| download | cpython-git-a8f480f54597cf20e460b12e17bb0416a8008868.tar.gz | |
Merged revisions 77517,77525 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
Merge adds an additional test for as_string with a maxheaderlen specified.
........
r77517 | r.david.murray | 2010-01-16 00:15:17 -0500 (Sat, 16 Jan 2010) | 6 lines
Issue #1670765: Prevent email.generator.Generator from re-wrapping
headers in multipart/signed MIME parts, which fixes one of the sources of
invalid modifications to such parts by Generator. Patch and tests by
Martin von Gagern.
........
r77525 | r.david.murray | 2010-01-16 11:08:32 -0500 (Sat, 16 Jan 2010) | 2 lines
Fix issue number in comment.
........
Diffstat (limited to 'Lib/email/test/test_email.py')
| -rw-r--r-- | Lib/email/test/test_email.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py index 4ffc8f9b2c..77364122a4 100644 --- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -3387,6 +3387,44 @@ Content-Type: application/x-foo; +# Tests to ensure that signed parts of an email are completely preserved, as +# required by RFC1847 section 2.1. Note that these are incomplete, because the +# email package does not currently always preserve the body. See issue 1670765. +class TestSigned(TestEmailBase): + + def _msg_and_obj(self, filename): + with openfile(findfile(filename)) as fp: + original = fp.read() + msg = email.message_from_string(original) + return original, msg + + def _signed_parts_eq(self, original, result): + # Extract the first mime part of each message + import re + repart = re.compile(r'^--([^\n]+)\n(.*?)\n--\1$', re.S | re.M) + inpart = repart.search(original).group(2) + outpart = repart.search(result).group(2) + self.assertEqual(outpart, inpart) + + def test_long_headers_as_string(self): + original, msg = self._msg_and_obj('msg_45.txt') + result = msg.as_string() + self._signed_parts_eq(original, result) + + def test_long_headers_as_string_maxheaderlen(self): + original, msg = self._msg_and_obj('msg_45.txt') + result = msg.as_string(maxheaderlen=60) + self._signed_parts_eq(original, result) + + def test_long_headers_flatten(self): + original, msg = self._msg_and_obj('msg_45.txt') + fp = StringIO() + Generator(fp).flatten(msg) + result = fp.getvalue() + self._signed_parts_eq(original, result) + + + def _testclasses(): mod = sys.modules[__name__] return [getattr(mod, name) for name in dir(mod) if name.startswith('Test')] |
