New submission from Andrei Troie <andreitroi...@gmail.com>:

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().

----------
components: email
messages: 353624
nosy: aft90, barry, r.david.murray
priority: normal
severity: normal
status: open
title: invalid content-transfer-encoding in encoded-word causes KeyError
type: crash
versions: Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38332>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to