classification
Title: email.policy.SMTP.fold() mangles long headers
Type: behavior Stage: resolved
Components: Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: barry, chris@arrai.com, jhillacre, r.david.murray
Priority: normal Keywords:

Created on 2017-05-31 22:08 by chris@arrai.com, last changed 2017-07-06 21:30 by r.david.murray. This issue is now closed.

Files
File name Uploaded Description Edit
test_long_mime_headers.py chris@arrai.com, 2017-05-31 22:08 Test case for folding long email headers.
Pull Requests
URL Status Linked Edit
PR 1892 merged jhillacre, 2017-05-31 22:52
PR 2591 merged jhillacre, 2017-07-05 20:00
PR 2592 merged jhillacre, 2017-07-05 20:14
Messages (10)
msg294875 - (view) Author: Chris Bradley (chris@arrai.com) Date: 2017-05-31 22:08
When email.policy.SMTP.fold() attempts to wrap a line in which a chunk that does not contain a space is longer than the maximum line length, two things go wrong:
 - The second line does not begin with a space, creating an invalid header.
 - The space before the long chunk is stripped, causing the line break to occur in an invalid place.

In the attached test case, email.policy.SMTP.fold() is called on a line of the style:
Content-Disposition: attachment; filename="<filename>"

<filename> does not contain any spaces and increases in length with each pass. Everything works correctly when 'filename="<filename>"' fits onto one line. However, once it is longer than the maximum line length, the following happens:
 - the space after the semicolon is dropped
 - the line break often splits up the 'filename' keyword
 - the second line loses the initial whitespace
msg294878 - (view) Author: Joel Hillacre (jhillacre) * Date: 2017-05-31 22:54
I added a pull request that causes Chris's test to pass. I can confirm that the Chris's was not pass for me on master branch.
msg295209 - (view) Author: Joel Hillacre (jhillacre) * Date: 2017-06-05 20:14
Rebased the github PR on latest master to get the windows build passing CI.

Is there anything I need to do to keep the PR moving?
msg295210 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-06-05 20:31
Ping the issue again next week if I don't get to it this weekend.
msg296584 - (view) Author: Joel Hillacre (jhillacre) * Date: 2017-06-21 21:06
> Ping the issue again next week if I don't get to it this weekend.

I am a week late, but here is a ping.
msg296732 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-06-23 18:09
Just as well.  I had no time last weekend.  I should have time this Sunday, though.
msg296948 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-06-26 21:41
New changeset b350c22ebcbb891412e0b334afc9f0db19534e06 by R. David Murray (Joel Hillacre) in branch 'master':
bpo-30532: Fix whitespace folding in certain cases
https://github.com/python/cpython/commit/b350c22ebcbb891412e0b334afc9f0db19534e06
msg297843 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-07-06 21:28
New changeset c60d2f5e8609b040ab58c498fde23928fe9dbef5 by R. David Murray (Joel Hillacre) in branch '3.6':
bpo-30532: Fix whitespace folding in certain cases (#2591)
https://github.com/python/cpython/commit/c60d2f5e8609b040ab58c498fde23928fe9dbef5
msg297844 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-07-06 21:29
New changeset 3bbdf990a2c1b0b303b950058e3177a1bd5f697a by R. David Murray (Joel Hillacre) in branch '3.5':
bpo-30532: Fix whitespace folding in certain cases (#2592)
https://github.com/python/cpython/commit/3bbdf990a2c1b0b303b950058e3177a1bd5f697a
msg297845 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-07-06 21:30
Thanks, Joel!
History
Date User Action Args
2017-07-06 21:30:10r.david.murraysetstatus: open -> closed
type: behavior
messages: + msg297845

resolution: fixed
stage: backport needed -> resolved
2017-07-06 21:29:12r.david.murraysetmessages: + msg297844
2017-07-06 21:28:25r.david.murraysetmessages: + msg297843
2017-07-05 20:14:27jhillacresetpull_requests: + pull_request2663
2017-07-05 20:00:12jhillacresetpull_requests: + pull_request2662
2017-06-26 21:44:06r.david.murraysetstage: backport needed
2017-06-26 21:41:37r.david.murraysetmessages: + msg296948
2017-06-23 18:09:38r.david.murraysetmessages: + msg296732
2017-06-21 21:06:04jhillacresetmessages: + msg296584
2017-06-05 20:31:11r.david.murraysetmessages: + msg295210
2017-06-05 20:14:17jhillacresetmessages: + msg295209
2017-05-31 22:54:51jhillacresetnosy: + jhillacre
messages: + msg294878
2017-05-31 22:52:02jhillacresetpull_requests: + pull_request1968
2017-05-31 22:29:20ned.deilysetnosy: + barry, r.david.murray
2017-05-31 22:08:53chris@arrai.comcreate