Skip to content

email.message_from_string() is unable to find the headers for the .msg files #85329

Open

Description

@jpatel
mannequin
BPO 41157
Nosy @warsaw, @bitdancer, @maxking, @websurfer5
Files
  • extract_mail.py
  • msgfile_not_working_correctly.msg
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2020-06-29.10:51:06.594>
    labels = ['3.8', 'type-feature', 'library']
    title = 'email.message_from_string() is unable to find the headers for the .msg files'
    updated_at = <Date 2020-08-07.05:50:46.185>
    user = 'https://bugs.python.org/jpatel'

    bugs.python.org fields:

    activity = <Date 2020-08-07.05:50:46.185>
    actor = 'Jeffrey.Kintscher'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2020-06-29.10:51:06.594>
    creator = 'jpatel'
    dependencies = []
    files = ['49273', '49274']
    hgrepos = []
    issue_num = 41157
    keywords = []
    message_count = 1.0
    messages = ['372560']
    nosy_count = 5.0
    nosy_names = ['barry', 'r.david.murray', 'maxking', 'Jeffrey.Kintscher', 'jpatel']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue41157'
    versions = ['Python 3.8']

    Activity

    1. jpatel commented on Jun 29, 2020

      jpatelmannequin
      MannequinAuthor

      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@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.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Jul 2, 2020
    3. transferred this issue fromon Apr 10, 2022
    4. added a commit that references this issue on Aug 30, 2023
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.8 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytopic-emailtype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions