diff --git a/mailparser/mailparser.py b/mailparser/mailparser.py index 5ea1654..c6ba0f5 100644 --- a/mailparser/mailparser.py +++ b/mailparser/mailparser.py @@ -448,9 +448,7 @@ def received(self): """ Return a list of all received headers parsed """ - output = [] - for i in self.message.get_all("received", []): - output.append(decode_header_part(i)) + output = self.received_raw return receiveds_parsing(output) @property diff --git a/mailparser/utils.py b/mailparser/utils.py index d9c7954..e5b3f4d 100644 --- a/mailparser/utils.py +++ b/mailparser/utils.py @@ -261,6 +261,9 @@ def receiveds_format(receiveds): # Add UTC date if i.get("date"): + # Modify date to manage strange header like: + # "for ; Tue, 7 Mar 2017 14:29:24 -0800", + i["date"] = i["date"].split(";")[-1] j["date_utc"] = convert_mail_date(i["date"]) # Add delay diff --git a/mailparser/version.py b/mailparser/version.py index 64089e8..1c67994 100644 --- a/mailparser/version.py +++ b/mailparser/version.py @@ -17,7 +17,7 @@ limitations under the License. """ -__version__ = "3.2.1" +__version__ = "3.2.2" if __name__ == "__main__": print(__version__) diff --git a/tests/mails/mail_test_8 b/tests/mails/mail_test_8 new file mode 100644 index 0000000..d9263a9 --- /dev/null +++ b/tests/mails/mail_test_8 @@ -0,0 +1,163 @@ +Return-Path: +Delivered-To: eboktor@romolo.com +Received: (qmail 23530 invoked from network); 7 Mar 2017 22:29:25 -0000 +Received: from host.colocrossing.com (HELO 04d930f1.moneytrack.top) (198.23.142.158) + by smtp.dakota.net with SMTP; 7 Mar 2017 22:29:25 -0000 +Received: from 04d930f1.lyeo00hp.moneytrack.top ([127.0.0.1]:8615 helo=lyeo00hp.moneytrack.top) + by lyeo00hp.moneytrack.top with ESMTP id 04EKOWYD930WHFJSF1; + for ; Tue, 7 Mar 2017 14:29:24 -0800 +Message-ID: <3615343813390903615122237013831979@lyeo00hp.moneytrack.top> +To: +Date: Tue, 7 Mar 2017 14:29:24 -0800 +From: "Helicopter_flight_simulator" +Subject: Have you ever wanted to land on an Aircraft Carrier +Content-Language: en-us +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Content-Type: multipart/alternative; + boundary="----=Part.335.4745.1488925764" + +------=Part.335.4745.1488925764 +Content-Transfer-Encoding: 8bit +Content-Type: text/plain; charset="UTF-8" + +"The Perfect Filler Between Real World Flying" +Imagine "Real Life" Flying At The Comfort Of Your Home... +Click here + +http://www.moneytrack.top/l/lt10VX3615QP370UC/1222A1383JJ1979TG249B81339090GF3323432606 + + With 120+ Aircraft to Master, From the 1903 Wright Flyer to the Latest Military Fighter Jets. + 20,000+ Real Airports With changeable Weather and NASA Flight Models. + Realistic Worldwide Terrain Based On US Defense Mapping Agency + Lifetime FREE updates/upgrades. + Used On Television Episodes & Professional Flight Schools - The Most Realistic Flight Sim To Date... + +http://www.moneytrack.top/l/lt10YC3615UB370FH/1222R1383JC1979CT249C81339090FD3323432606 + +Meet up online with other ProFlightSimulator Users to fly in formation, put on an +air show or just to have fun. You can easily locate other pilots or yourself with +Google Map integration - Multiplayer map server shows all the active pilots +superimposed on top of a Google map. +Enjoy Real-Life Flying Today + +http://www.moneytrack.top/l/lt10SG3615LD370EN/1222O1383GD1979LL249Y81339090AK3323432606 + + + + + + + + +If you do not want to receive any further mail click here. +82023 Peters Road, Suite 1000 Plantation, FL 33324 + +http://www.moneytrack.top/l/lc13NE3615MS370NH/1222I1383VY1979GM249T81339090TL3323432606 + +------=Part.335.4745.1488925764 +Content-Transfer-Encoding: 8bit +Content-Type: text/html; charset="UTF-8" + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
"The Perfect Filler Between Real World Flying"
+ + + +
+ Imagine "Real Life" Flying At The Comfort Of Your Home...
+ + + + + + + + +
+ +Click here + + + + + + + + + + + + + + + + + + + + + +
 With 120+ Aircraft to Master, From the 1903 Wright Flyer to the Latest Military Fighter Jets.
 20,000+ Real Airports With changeable Weather and NASA Flight Models.
 Realistic Worldwide Terrain Based On US Defense Mapping Agency + Lifetime FREE updates/upgrades.
 Used On Television Episodes & Professional Flight Schools - The Most Realistic Flight Sim To Date...
+
+ Meet up online with other ProFlightSimulator Users to fly in formation, put on an
+ air show or just to have fun. You can easily locate other pilots or yourself with
Google Map integration - Multiplayer map server shows all the active pilots
superimposed on top of a Google map.
+ + + +
+ Enjoy Real-Life Flying Today + +

+

+

+ +
+ +
+ +If you do not want to receive any further mail click here.
82023 Peters Road, Suite 1000 Plantation, FL 33324 +
+

+

+

+
+
T%]/Earth /Wheel/Highway / +
God /Guitar /Sandar /Sandpaper /Typewriter ar /Post-office /Pepper /Hat /Earth /Spiral /Garden /Tennis rectcity /Pants /Sphere /Table /Comet / /Bee /Button /Map /Dhroom /Eyes /Train /Hat /Planet /Web /Girl /Surveyor /Rocket /Slave /Software /Vampi /God /od /Guitar /Sandpaper /Typewriter ar /Post-office /Pepper /Hat /Earth /Spiral /Garden /Tennis ract +
/Earth /Wheel/Highway / +
God /Guitar /Sandpaper /Typewriter /Finpaper /Typewriter /Finuum /Sun /Egg /Leg /Ice /Guitar /Post-office /Pepper +
/Hat /Eartricity /Pants /Sphere /Table /Comet / /Bee /Button /Map /Dhroom /Eyes /Train /Hat /Planet /Web /Girl /Surveyor /Rocket /Slave /Software /Vampi /God /Guitar /Sandpaper /Typewriter ar /Post-office /Pepper /Hat /Earth /Spiral /Garden /Tennis rectcity /Pants /Sphere /Table /Comet / /Bee /Button /Map /Dhroom /Eyes /Train /Hat /Planet /Web /Girl /Surveyor /Rocket /Slave /Software /Vampi /God /Guitar /Sandpaper /Typewriter ar /Post-office /Pepper /Hat /Earth /Spiral /Garden /Tennis ract +
/Earth /Wheel/Highway / +
God /Guitar /Sandpaper /Typewriter /Finger /Feather /Salt
+ + + + + +------=Part.335.4745.1488925764-- + diff --git a/tests/test_mail_parser.py b/tests/test_mail_parser.py index da83cef..42ebe9d 100644 --- a/tests/test_mail_parser.py +++ b/tests/test_mail_parser.py @@ -33,6 +33,7 @@ mail_test_5 = os.path.join(base_path, 'mails', 'mail_test_5') mail_test_6 = os.path.join(base_path, 'mails', 'mail_test_6') mail_test_7 = os.path.join(base_path, 'mails', 'mail_test_7') +mail_test_8 = os.path.join(base_path, 'mails', 'mail_test_8') mail_malformed_1 = os.path.join(base_path, 'mails', 'mail_malformed_1') mail_malformed_2 = os.path.join(base_path, 'mails', 'mail_malformed_2') mail_malformed_3 = os.path.join(base_path, 'mails', 'mail_malformed_3') @@ -60,6 +61,12 @@ def setUp(self): mail_malformed_2, mail_malformed_3) + def test_issue_received(self): + mail = mailparser.parse_from_file(mail_test_8) + for i in mail.received: + self.assertIn("date_utc", i) + self.assertIsNotNone(i["date_utc"]) + def test_get_header(self): mail = mailparser.parse_from_file(mail_test_1) h1 = get_header(mail.message, "from")