Skip to content
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

Closed
bpoaugust mannequin opened this issue Sep 19, 2017 · 5 comments
Closed

mailbox._mboxMMDF.get_message throws away From envelope #75705

bpoaugust mannequin opened this issue Sep 19, 2017 · 5 comments
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes easy stdlib Python modules in the Lib dir topic-email type-bug An unexpected behavior, bug, or error

Comments

@bpoaugust
Copy link
Mannequin

bpoaugust mannequin commented Sep 19, 2017

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

@bpoaugust
Copy link
Mannequin Author

bpoaugust mannequin commented Sep 19, 2017

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.

@bpoaugust bpoaugust mannequin added 3.7 (EOL) end of life topic-email type-bug An unexpected behavior, bug, or error labels Sep 19, 2017
@bitdancer
Copy link
Member

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

@bpoaugust
Copy link
Mannequin Author

bpoaugust mannequin commented Sep 20, 2017

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())

@bpoaugust
Copy link
Mannequin Author

bpoaugust mannequin commented Sep 20, 2017

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.

@bitdancer
Copy link
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 :)

@iritkatriel iritkatriel added easy 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes and removed 3.7 (EOL) end of life labels Jan 16, 2022
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Nov 23, 2023
@serhiy-storchaka serhiy-storchaka added 3.12 bugs and security fixes 3.13 bugs and security fixes and removed 3.10 only security fixes 3.9 only security fixes labels Feb 1, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 6, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 6, 2024
serhiy-storchaka pushed a commit that referenced this issue Feb 6, 2024
serhiy-storchaka pushed a commit that referenced this issue Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes easy stdlib Python modules in the Lib dir topic-email type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants