[issue43554] email: encoded headers lose their quoting when refolded

2021-03-19 Thread hai shi


Change by hai shi :


--
nosy: +barry, maxking, r.david.murray

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43554] email: encoded headers lose their quoting when refolded

2021-03-19 Thread Emil Styrke


New submission from Emil Styrke :

When a header with an encoded (QP or Base64) display_name is refolded, it may 
lose (some of) its encoding.  If it then contains illegal "atext" tokens, an 
invalid header will result.

For example, `From: =?utf-8?Q?a=2C=20123456789012345678901234567890123456?= 
` will become `From: a, 123456789012345678901234567890123456 
`  This contains a comma character which needs to be quoted: 
correct rendering would be `From: "a, 123456789012345678901234567890123456" 
`. Note that this example isn't even folded to multiple 
lines, since the decoded text is short enough to fit in one line.

This can be triggered by `BytesParser(policy=policy.default).parsebytes("From: 
=?utf-8?Q?a=2C=20123456789012345678901234567890123456?= 
").as_bytes()`, but the offending code seems to be in or 
below `email.policy.EmailPolicy.fold`.  See attached file for examples with and 
without folding.

--
components: Library (Lib)
files: test_folding_bug.py
messages: 389061
nosy: Emil.Styrke
priority: normal
severity: normal
status: open
title: email: encoded headers lose their quoting when refolded
type: behavior
versions: Python 3.9
Added file: https://bugs.python.org/file49893/test_folding_bug.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com