classification
Title: Email header refolding adds additional \r in nested parse trees
Type: behavior Stage: resolved
Components: email Versions: Python 3.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: barry, michael.thies, r.david.murray
Priority: normal Keywords:

Created on 2018-10-24 11:54 by michael.thies, last changed 2018-10-24 17:05 by r.david.murray. This issue is now closed.

Messages (2)
msg328362 - (view) Author: Michael Thies (michael.thies) Date: 2018-10-24 11:54
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`
msg328380 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2018-10-24 17:05
Thank you for the report.  This is a duplicate of #34424, which has a PR.
History
Date User Action Args
2018-10-24 17:05:43r.david.murraysetstatus: open -> closed
resolution: duplicate
messages: + msg328380

stage: resolved
2018-10-24 11:54:52michael.thiescreate