[New-bugs-announce] [issue41157] email.message_from_string() is unable to find the headers for the .msg files
report at bugs.python.org
Mon Jun 29 06:51:06 EDT 2020
New submission from Jay Patel <jay.patel at crestdatasys.com>:
I need to extract the email data from an MSG file on Python v2.7. But as Python v2.7 has been deprecated, I tried to replicate this scenario on Python v3.8 and faced the same issue.
I am trying to extract the message using the "Message" class of the "extract_msg" module. After extracting the text from the "Message" object, I am using email.message_from_string() method to separate the headers and the body (or payload). The same workflow can be observed in the "extract_mail.py" file.
The issue with the attached file, "msgfile_not_working_correctly.msg", is that the headers of this file begin with "Microsoft Mail Internet Headers Version 2.0" which is interpreted as body and not as headers (as it is not in the standard email headers format like "To": "receiver at gmail.com").
According to this (https://support.microsoft.com/en-us/office/view-internet-message-headers-in-outlook-cd039382-dc6e-4264-ac74-c048563d212c) link the message headers in Outlook will begin with "Microsoft Mail Internet Headers Version 2.0" which is added by Outlook (mentioned in the "Interpreting email headers" section of the mentioned link).
The email data can be observed in the "email_data.txt" file.
I have tried omitting the first line, when there are no headers and it works as per the expectation. Can this scenario be handled at the modular level (email module) or is there any other way to extract headers for the .msg files.
title: email.message_from_string() is unable to find the headers for the .msg files
versions: Python 3.8
Added file: https://bugs.python.org/file49273/extract_mail.py
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce