Skip to content

mailbox._mboxMMDF.get_message throws away From envelope #75705

Closed

Description

@bpoaugust
mannequin
BPO 31524
Nosy @warsaw, @bitdancer

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 2017-09-19.23:27:27.205>
labels = ['easy', 'type-bug', 'expert-email', '3.10', '3.11', '3.9']
title = 'mailbox._mboxMMDF.get_message throws away From envelope'
updated_at = <Date 2022-01-16.19:05:51.256>
user = 'https://bugs.python.org/bpoaugust'

bugs.python.org fields:

activity = <Date 2022-01-16.19:05:51.256>
actor = 'iritkatriel'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['email']
creation = <Date 2017-09-19.23:27:27.205>
creator = 'bpoaugust'
dependencies = []
files = []
hgrepos = []
issue_num = 31524
keywords = ['easy']
message_count = 5.0
messages = ['302570', '302575', '302577', '302578', '302582']
nosy_count = 3.0
nosy_names = ['barry', 'r.david.murray', 'bpoaugust']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue31524'
versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

Linked PRs

Activity

  1. bpoaugust commented on Sep 19, 2017

    bpoaugustmannequin
    MannequinAuthor

    https://github.com/python/cpython/blob/master/Lib/mailbox.py#L778

    The code here reads the first line, but fails to save it as the unixfrom line.

    Alternatively perhaps it should reset the file back to the start so the message factory has sight of the envelope.

    The end result is that the envelope is lost.

  2. bitdancer commented on Sep 20, 2017

    @bitdancer
    Member

    It looks like it is saving it (the set_from line). Do you have a test that proves otherwise?

  3. bpoaugust commented on Sep 20, 2017

    bpoaugustmannequin
    MannequinAuthor

    It is not saving the unix from line.

    #!/usr/bin/env python3

    with open("test.mbox",'w') as f:
        f.write("From sender@invalid Thu Nov 17 00:49:30 2016\n")
        f.write("Subject: Test\n")
        f.write("\n")
        f.write("\n")
    
    import mailbox
    messages = mailbox.mbox("test.mbox")
    for msg in messages:
        print(msg.get('subject'))
        print(msg.get_from())
        print(msg.get_unixfrom())
  4. bpoaugust commented on Sep 20, 2017

    bpoaugustmannequin
    MannequinAuthor

    I believe that setting the file back to the start is probably the best solution.

    The message as provided by e.g. postfix will include the From header and the parser is able to deal with that successfully, so I'm not sure why the mbox reader removes it before calling the parser. It only really needs to drop the trailing newline to ensure that the parser gets the same data.

  5. bitdancer commented on Sep 20, 2017

    @bitdancer
    Member

    It just needs to call set_unixfrom as well as set_from. I don't know why the MMDFMessage tracks it separately, but I'm sure the author had a reason that seemed good at the time :)

  6. transferred this issue fromon Apr 10, 2022
  7. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 23, 2023
  8. added
    3.12only security fixes
    3.13only security fixes
    and removed on Feb 1, 2024
  9. added a commit that references this issue on Feb 6, 2024
  10. added 2 commits that reference this issue on Feb 6, 2024
  11. added 2 commits that reference this issue on Feb 6, 2024
  12. added a commit that references this issue on Feb 14, 2024
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.11only security fixes3.12only security fixes3.13only security fixeseasystdlibStandard Library Python modules in the Lib/ directorytopic-emailtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions