This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Bad decoding of encoded-words in unstructured email headers
Type: Stage:
Components: Versions: Python 3.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: r.david.murray Nosy List: barry, fdrake, maxking, r.david.murray
Priority: normal Keywords:

Created on 2019-10-28 16:47 by fdrake, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg355564 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2019-10-28 16:47
I've encountered a problem parsing an email with this Subject: header:

Subject: Be sure to redeem your =?utf-8?Q?$?=201.71 credit card reward
 certificate by the end of the year

email._header_value_parser.get_unstructured defers to get_encoded_word, passing the argument

  '=?utf-8?Q?$?=201.71 credit card reward certificate by the end of the year'

get_encoded_word eventually calls email._encoded_words.decode with the argument

  '=?utf-8?Q?$?=201.71 credit card reward certificate by the end of the year?='

This doesn't seem right, but I'm unsure of the syntactic priority of =XX and ?= in this case.

The policy for this is email.policy.SMTP + email.policy.strict (not sure if that's ideal; I'm retrieving messages from mbox files and over IMAP).
msg355565 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2019-10-28 16:49
It's worth noting that dealing with this header eventually causes the header parser to enter an infinite loop.
msg355654 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2019-10-29 13:43
This problem does not exist in Python 3.6 or Python 3.8; it appears to only exist in Python 3.7.
msg355657 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2019-10-29 15:19
It turns out this was a problem in 3.7.4; Python 3.7.5 seems to have fixed this.

Sorry for the noise.

Guess it's time to update my application to use 3.7.5!
History
Date User Action Args
2022-04-11 14:59:22adminsetgithub: 82802
2019-11-04 15:23:05fdrakesetresolution: fixed -> rejected
stage: resolved ->
2019-10-29 15:19:40fdrakesetstatus: open -> closed
resolution: fixed
messages: + msg355657

stage: resolved
2019-10-29 14:17:13ned.deilysetnosy: fdrake, barry, r.david.murray, maxking
2019-10-29 13:43:32fdrakesetmessages: + msg355654
versions: + Python 3.7
2019-10-28 16:51:07xtreaksetnosy: + maxking
2019-10-28 16:49:11fdrakesetmessages: + msg355565
2019-10-28 16:47:43fdrakecreate