[New-bugs-announce] [issue38332] invalid content-transfer-encoding in encoded-word causes KeyError
report at bugs.python.org
Mon Sep 30 16:57:33 EDT 2019
New submission from Andrei Troie <andreitroie90 at gmail.com>:
The following will cause a KeyError on email.message.get()
text = "Subject: =?us-ascii?X?somevalue?="
eml = email.message_from_string(text, policy=email.policy.default)
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().
nosy: aft90, barry, r.david.murray
title: invalid content-transfer-encoding in encoded-word causes KeyError
versions: Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce