|
20 | 20 | import datetime |
21 | 21 | import logging |
22 | 22 | import os |
| 23 | +import shutil |
23 | 24 | import six |
24 | 25 | import sys |
25 | 26 | import unittest |
|
42 | 43 | ported_string, |
43 | 44 | receiveds_parsing, |
44 | 45 | parse_received, |
| 46 | + random_string, |
45 | 47 | ) |
46 | 48 |
|
47 | 49 | from mailparser.exceptions import MailParserEnvironmentError |
@@ -87,6 +89,27 @@ def setUp(self): |
87 | 89 | mail_malformed_2, |
88 | 90 | mail_malformed_3) |
89 | 91 |
|
| 92 | + def test_write_attachments(self): |
| 93 | + attachments = [ |
| 94 | + "<_1_0B4E44A80B15F6FC005C1243C12580DD>", |
| 95 | + "<_1_0B4E420C0B4E3DD0005C1243C12580DD>", |
| 96 | + "<_1_0B4E24640B4E1564005C1243C12580DD>", |
| 97 | + "Move To Eight ZWEP6227F.pdf"] |
| 98 | + random_path = os.path.join(root, "tests", random_string()) |
| 99 | + mail = mailparser.parse_from_file(mail_test_10) |
| 100 | + os.makedirs(random_path) |
| 101 | + mail.write_attachments(random_path) |
| 102 | + for i in attachments: |
| 103 | + self.assertTrue(os.path.exists(os.path.join(random_path, i))) |
| 104 | + shutil.rmtree(random_path) |
| 105 | + |
| 106 | + def test_issue62(self): |
| 107 | + mail = mailparser.parse_from_file(mail_test_14) |
| 108 | + received_spf = mail.Received_SPF |
| 109 | + self.assertIsInstance(received_spf, list) |
| 110 | + self.assertIn("custom_header1", received_spf) |
| 111 | + self.assertIn("custom_header2", received_spf) |
| 112 | + |
90 | 113 | def test_html_field(self): |
91 | 114 | mail = mailparser.parse_from_file(mail_malformed_1) |
92 | 115 | self.assertIsInstance(mail.text_html, list) |
@@ -117,6 +140,8 @@ def test_mail_partial(self): |
117 | 140 | self.assertNotIn("x-ibm-av-version", mail.mail_partial) |
118 | 141 | result = mail.mail_partial_json |
119 | 142 | self.assertIsInstance(result, six.text_type) |
| 143 | + nr_attachments = len(mail._attachments) |
| 144 | + self.assertEqual(nr_attachments, 4) |
120 | 145 |
|
121 | 146 | def test_not_parsed_received(self): |
122 | 147 | mail = mailparser.parse_from_file(mail_test_9) |
|
0 commit comments