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.
This commit is contained in:
R. David Murray 2010-01-16 05:15:17 +00:00
parent 57cd8ebc20
commit ed44dfa4c7
4 changed files with 86 additions and 0 deletions

View file

@ -3275,6 +3275,42 @@ Content-Type: application/x-foo;
eq(s, 'My Document For You')
# 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 96843.
class TestSigned(TestEmailBase):
def _msg_and_obj(self, filename):
fp = openfile(findfile(filename))
try:
original = fp.read()
msg = email.message_from_string(original)
finally:
fp.close()
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_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__]