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.

Author aft90
Recipients aft90, barry, r.david.murray
Date 2019-09-30.20:57:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1569877053.41.0.568400002445.issue38332@roundup.psfhosted.org>
In-reply-to
Content
The following will cause a KeyError on email.message.get()

import email
import email.policy

text = "Subject: =?us-ascii?X?somevalue?="
eml = email.message_from_string(text, policy=email.policy.default)
eml.get('Subject')

This is caused by the fact that the code in _encoded_words.py assumes the content-transfer-encoding of an encoded-word is always 'q' or 'b' (after lowercasing): https://github.com/python/cpython/blob/aca8c406ada3bb547765b262bed3ac0cc6be8dd3/Lib/email/_encoded_words.py#L178

I realise it's probably a silly edge case and I haven't (yet) encountered something like this in the wild, but it does seem contrary to the spirit of the email library to raise an exception like this that can propagate all the way to email.message.get().
History
Date User Action Args
2019-09-30 20:57:33aft90setrecipients: + aft90, barry, r.david.murray
2019-09-30 20:57:33aft90setmessageid: <1569877053.41.0.568400002445.issue38332@roundup.psfhosted.org>
2019-09-30 20:57:33aft90linkissue38332 messages
2019-09-30 20:57:33aft90create