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

Email header refolding adds additional \r in nested parse trees #79238

Closed
mhthies mannequin opened this issue Oct 24, 2018 · 2 comments
Closed

Email header refolding adds additional \r in nested parse trees #79238

mhthies mannequin opened this issue Oct 24, 2018 · 2 comments
Labels
3.7 (EOL) end of life topic-email type-bug An unexpected behavior, bug, or error

Comments

@mhthies
Copy link
Mannequin

mhthies mannequin commented Oct 24, 2018

BPO 35057
Nosy @warsaw, @bitdancer, @mhthies

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 = <Date 2018-10-24.17:05:43.292>
created_at = <Date 2018-10-24.11:54:52.915>
labels = ['type-bug', '3.7', 'expert-email']
title = 'Email header refolding adds additional \\r in nested parse trees'
updated_at = <Date 2018-10-24.17:05:43.291>
user = 'https://github.com/mhthies'

bugs.python.org fields:

activity = <Date 2018-10-24.17:05:43.291>
actor = 'r.david.murray'
assignee = 'none'
closed = True
closed_date = <Date 2018-10-24.17:05:43.292>
closer = 'r.david.murray'
components = ['email']
creation = <Date 2018-10-24.11:54:52.915>
creator = 'michael.thies'
dependencies = []
files = []
hgrepos = []
issue_num = 35057
keywords = []
message_count = 2.0
messages = ['328362', '328380']
nosy_count = 3.0
nosy_names = ['barry', 'r.david.murray', 'michael.thies']
pr_nums = []
priority = 'normal'
resolution = 'duplicate'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue35057'
versions = ['Python 3.7']

@mhthies
Copy link
Mannequin Author

mhthies mannequin commented Oct 24, 2018

Email header refolding in email._header_value_parser adds additional carriage return symbols to the end of nested parse trees, when used with an EmailPolicy with linesep='\r\n'. This leads to broken email headers when composing an email with a "To:" or "CC:" header having a comma-separated list of recipients with some of them containing non-ASCII characters in their DisplayName.

The bug seems to be caused by the following line (in Python 3.7):
encoded_part = part.fold(policy=policy)[:-1] # strip nl
(email/_header_value_parser.py, line 2629)

This line calls part.fold() / _refold_parse_tree() recursively and tries to remove the trailing newline, which is added by the recursive call of _refold_parse_tree(). Unfortunately, it fails to do so, if the length of the policy's line separator sequence does not equal 1. Thus, this line should be corrected to something like
encoded_part = part.fold(policy=policy)[:-len(policy.linesep)] # strip nl

@mhthies mhthies mannequin added 3.7 (EOL) end of life topic-email type-bug An unexpected behavior, bug, or error labels Oct 24, 2018
@bitdancer
Copy link
Member

Thank you for the report. This is a duplicate of bpo-34424, which has a PR.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life topic-email type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant