handle plain base64 as transfer-encoding in incoming mails
This commit is contained in:
parent
65755feb2f
commit
0fa52645c2
2 changed files with 36 additions and 3 deletions
|
@ -128,10 +128,14 @@ def decode_email_segment(segment, charset, transfer_encoding):
|
|||
decode_as = 'cp1251'
|
||||
elif charset == 'iso-8859-1':
|
||||
decode_as = 'latin1'
|
||||
segment = unescape_and_decode_quoted_printable(segment)
|
||||
segment = unescape_and_decode_base64(segment)
|
||||
if transfer_encoding == 'quoted-printable':
|
||||
segment = unescape_simplified_quoted_printable(segment, decode_as)
|
||||
elif transfer_encoding == 'base64':
|
||||
import base64
|
||||
segment = base64.b64decode(segment).decode('utf-8')
|
||||
else:
|
||||
segment = unescape_and_decode_quoted_printable(segment)
|
||||
segment = unescape_and_decode_base64(segment)
|
||||
return segment
|
||||
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ class LMTPHandlerTestCase(TestCase): # TODO replace with less hacky test
|
|||
self.assertEqual('Text mit Quoted-Printable-Kodierung: äöüß', Email.objects.all()[0].body)
|
||||
self.assertTrue(Email.objects.all()[0].raw_file.path)
|
||||
|
||||
def test_handle_base64(self):
|
||||
def test_handle_base64_inline(self):
|
||||
from aiosmtpd.smtp import Envelope
|
||||
from asgiref.sync import async_to_sync
|
||||
import aiosmtplib
|
||||
|
@ -186,6 +186,35 @@ class LMTPHandlerTestCase(TestCase): # TODO replace with less hacky test
|
|||
self.assertEqual('Text mit Base64-Kodierung: äöüß', Email.objects.all()[0].body)
|
||||
self.assertTrue(Email.objects.all()[0].raw_file.path)
|
||||
|
||||
def test_handle_base64_transfer_encoding(self):
|
||||
from aiosmtpd.smtp import Envelope
|
||||
from asgiref.sync import async_to_sync
|
||||
import aiosmtplib
|
||||
aiosmtplib.send = make_mocked_coro()
|
||||
handler = LMTPHandler()
|
||||
server = mock.Mock()
|
||||
session = mock.Mock()
|
||||
envelope = Envelope()
|
||||
envelope.mail_from = 'test1@test'
|
||||
envelope.rcpt_tos = ['test2@test']
|
||||
envelope.content = b'''Subject: test
|
||||
From: test3@test
|
||||
To: test4@test
|
||||
Message-ID: <1@test>
|
||||
Content-Type: text/plain; charset=utf-8
|
||||
Content-Transfer-Encoding: base64
|
||||
|
||||
VGVzdCBtaXQgQmFzZTY0LUtvZGllcnVuZzogw6TDtsO8w58='''
|
||||
|
||||
result = async_to_sync(handler.handle_DATA)(server, session, envelope)
|
||||
self.assertEqual(result, '250 Message accepted for delivery')
|
||||
self.assertEqual(len(Email.objects.all()), 2)
|
||||
self.assertEqual(len(IssueThread.objects.all()), 1)
|
||||
aiosmtplib.send.assert_called_once()
|
||||
self.assertEqual('test', Email.objects.all()[0].subject)
|
||||
self.assertEqual('Test mit Base64-Kodierung: äöüß', Email.objects.all()[0].body)
|
||||
self.assertTrue(Email.objects.all()[0].raw_file.path)
|
||||
|
||||
def test_handle_client_reply(self):
|
||||
issue_thread = IssueThread.objects.create(
|
||||
name="test",
|
||||
|
|
Loading…
Add table
Reference in a new issue