-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mailbox._mboxMMDF.get_message throws away From envelope #75705
Comments
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. |
It looks like it is saving it (the set_from line). Do you have a test that proves otherwise? |
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()) |
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. |
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 :) |
…GH-107117) (cherry picked from commit 76108b8) Co-authored-by: Matthieu Caneill <[email protected]>
…GH-107117) (cherry picked from commit 76108b8) Co-authored-by: Matthieu Caneill <[email protected]>
…7117) (GH-115098) (cherry picked from commit 76108b8) Co-authored-by: Matthieu Caneill <[email protected]>
…7117) (GH-115099) (cherry picked from commit 76108b8) Co-authored-by: Matthieu Caneill <[email protected]>
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:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: