-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For attachment only email with base64 encoded filename
- Loading branch information
Anton Engelhardt
committed
Jun 25, 2022
1 parent
e3dfa93
commit ff9a340
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -366,6 +366,39 @@ | |
------=_NextPart_000_0038_01D3F85C.02934C4A-- | ||
""" | ||
|
||
raw_email_attachment_only = """Delivered-To: [email protected] | ||
X-Originating-Email: [[email protected]] | ||
Message-ID: <[email protected]> | ||
Return-Path: [email protected] | ||
Date: Tue, 30 Jul 2013 15:56:29 +0300 | ||
From: Martin Rusev <[email protected]> | ||
MIME-Version: 1.0 | ||
To: John Doe <[email protected]> | ||
Subject: Test email - only pdf in body | ||
Content-Type: application/pdf; | ||
name="=?utf-8?B?YV9sb25nX2ZpbGVuYW1lX3dpdGhfc3BlY2lhbF9jaGFyX8O2w6Rf?= | ||
=?utf-8?B?LTAxX28ucGRm?=" | ||
Content-Transfer-Encoding: base64 | ||
Content-Disposition: attachment; | ||
filename="=?utf-8?B?YV9sb25nX2ZpbGVuYW1lX3dpdGhfc3BlY2lhbF9jaGFyX8O2w6Rf?= | ||
=?utf-8?B?LTAxX28ucGRm?=" | ||
JVBERi0xLjQKJcOiw6PDj8OTCjUgMCBvYmoKPDwKL0xlbmd0aCAxCj4+CnN0cmVhbQogCmVuZHN0 | ||
cmVhbQplbmRvYmoKNCAwIG9iago8PAovVHlwZSAvUGFnZQovTWVkaWFCb3ggWzAgMCA2MTIgNzky | ||
XQovUmVzb3VyY2VzIDw8Cj4+Ci9Db250ZW50cyA1IDAgUgovUGFyZW50IDIgMCBSCj4+CmVuZG9i | ||
agoyIDAgb2JqCjw8Ci9UeXBlIC9QYWdlcwovS2lkcyBbNCAwIFJdCi9Db3VudCAxCj4+CmVuZG9i | ||
agoxIDAgb2JqCjw8Ci9UeXBlIC9DYXRhbG9nCi9QYWdlcyAyIDAgUgo+PgplbmRvYmoKMyAwIG9i | ||
ago8PAovQ3JlYXRvciAoUERGIENyZWF0b3IgaHR0cDovL3d3dy5wZGYtdG9vbHMuY29tKQovQ3Jl | ||
YXRpb25EYXRlIChEOjIwMTUwNzAxMTEyNDQ3KzAyJzAwJykKL01vZERhdGUgKEQ6MjAyMjA2MDcx | ||
ODM2MDIrMDInMDAnKQovUHJvZHVjZXIgKDMtSGVpZ2h0c1wyMjIgUERGIE9wdGltaXphdGlvbiBT | ||
aGVsbCA2LjAuMC4wIFwoaHR0cDovL3d3dy5wZGYtdG9vbHMuY29tXCkpCj4+CmVuZG9iagp4cmVm | ||
CjAgNgowMDAwMDAwMDAwIDY1NTM1IGYKMDAwMDAwMDIyNiAwMDAwMCBuCjAwMDAwMDAxNjkgMDAw | ||
MDAgbgowMDAwMDAwMjc1IDAwMDAwIG4KMDAwMDAwMDA2NSAwMDAwMCBuCjAwMDAwMDAwMTUgMDAw | ||
MDAgbgp0cmFpbGVyCjw8Ci9TaXplIDYKL1Jvb3QgMSAwIFIKL0luZm8gMyAwIFIKL0lEIFs8MUMz | ||
NTAwQ0E5RjcyMzJCOTdFMEVGM0Y3ODlFOEI3RjI+IDwyNTRDOEQxNTNGNjU1RDQ5OTQ1RUFENjhE | ||
ODAxRTAxMT5dCj4+CnN0YXJ0eHJlZgo1MDUKJSVFT0Y= | ||
""" | ||
|
||
class TestParser(unittest.TestCase): | ||
|
||
def test_parse_email(self): | ||
|
@@ -423,6 +456,15 @@ def test_parse_attachment_with_long_filename(self): | |
self.assertEqual(71, attachment['size']) | ||
self.assertEqual('abcefghijklmnopqrstuvwxyz01234567890abcefghijklmnopqrstuvwxyz01234567890abcefghijklmnopqrstuvwxyz01234567890.xyz', attachment['filename']) | ||
self.assertTrue(attachment['content']) | ||
|
||
def test_parse_email_single_attachment(self): | ||
parsed_email = parse_email(raw_email_attachment_only) | ||
self.assertEqual(1, len(parsed_email.attachments)) | ||
attachment = parsed_email.attachments[0] | ||
self.assertEqual('application/pdf', attachment['content-type']) | ||
self.assertEqual(773, attachment['size']) | ||
self.assertEqual('a_long_filename_with_special_char_öä_-01_o.pdf', attachment['filename']) | ||
self.assertTrue(attachment['content']) | ||
|
||
def test_parse_email_accept_if_declared_charset_contains_a_minus_character(self): | ||
parsed_email = parse_email(raw_email_encoded_encoding_charset_contains_a_minus) | ||
|