Merge pull request 'Handle missing Content-Type properly' (#125) from 124-missing-ct into main
Reviewed-on: #125
This commit is contained in:
commit
c8f6743768
|
@ -209,7 +209,7 @@ def _rewrap_payload(message: EmailMessage) -> MIMEPart:
|
||||||
wrapper.set_type(message.get_content_type())
|
wrapper.set_type(message.get_content_type())
|
||||||
|
|
||||||
# Copy all Content-Type parameters.
|
# Copy all Content-Type parameters.
|
||||||
for (pname, pvalue) in message.get_params():
|
for (pname, pvalue) in message.get_params(failobj=list()):
|
||||||
# Skip MIME type that's also returned by get_params().
|
# Skip MIME type that's also returned by get_params().
|
||||||
if not '/' in pname:
|
if not '/' in pname:
|
||||||
wrapper.set_param(pname, pvalue)
|
wrapper.set_param(pname, pvalue)
|
||||||
|
|
|
@ -40,3 +40,17 @@ class LacreCoreTest(unittest.TestCase):
|
||||||
'only content and content-type should be copied')
|
'only content and content-type should be copied')
|
||||||
self.assertEqual(rewrapped.get_content_type(), 'text/plain',
|
self.assertEqual(rewrapped.get_content_type(), 'text/plain',
|
||||||
'rewrapped part should have initial message\'s content-type')
|
'rewrapped part should have initial message\'s content-type')
|
||||||
|
|
||||||
|
def test_payload_wrapping_wo_content_type(self):
|
||||||
|
m = EmailMessage()
|
||||||
|
m.set_payload('This is a payload.\r\n'
|
||||||
|
+ '\r\n'
|
||||||
|
+ 'It has two paragraphs.\r\n')
|
||||||
|
m['Subject'] = 'Source message'
|
||||||
|
|
||||||
|
rewrapped = lacre.core._rewrap_payload(m)
|
||||||
|
|
||||||
|
self.assertFalse('Subject' in rewrapped,
|
||||||
|
'only content and content-type should be copied')
|
||||||
|
self.assertEqual(rewrapped.get_content_type(), 'text/plain',
|
||||||
|
'rewrapped part should have initial message\'s content-type')
|
||||||
|
|
Loading…
Reference in New Issue