Repository navigation
Closed
Labels
3.10 (EOL)end of life3.8 (EOL)end of life3.9 (EOL)end of lifetopic-emailtype-bugAn unexpected behavior, bug, or error
Description
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = <Date 2020-10-19.23:02:01.155>
created_at = <Date 2016-06-14.18:52:52.474>
labels = ['type-bug', '3.8', 'expert-email', '3.10', '3.9']
title = "Email parser creates a message object that can't be flattened"
updated_at = <Date 2020-10-19.23:11:42.432>
user = 'https://github.com/msapiro'bugs.python.org fields:
activity = <Date 2020-10-19.23:11:42.432>
actor = 'miss-islington'
assignee = 'none'
closed = True
closed_date = <Date 2020-10-19.23:02:01.155>
closer = 'barry'
components = ['email']
creation = <Date 2016-06-14.18:52:52.474>
creator = 'msapiro'
dependencies = []
files = ['43391', '43394']
hgrepos = []
issue_num = 27321
keywords = ['patch']
message_count = 22.0
messages = ['268580', '268589', '279172', '295080', '295093', '295101', '295105', '295107', '295108', '295430', '295442', '295443', '296293', '310513', '311272', '327136', '336930', '378083', '378088', '379052', '379056', '379057']
nosy_count = 10.0
nosy_names = ['barry', 'msapiro', 'diekhans', 'r.david.murray', 'maciej.szulik', 'matrixise', 'cheryl.sabella', 'Johannes L\xc3\xb6thberg', 'miss-islington', 'edeca']
pr_nums = ['1977', '18074', '22796', '22797']
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue27321'
versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']Metadata
Metadata
Assignees
Labels
3.10 (EOL)end of life3.8 (EOL)end of life3.9 (EOL)end of lifetopic-emailtype-bugAn unexpected behavior, bug, or error
Activity
msapiro commentedon Jun 14, 2016
The attached file, bad_email, can be parsed via
but then msg.as_string() prodices the following:
msapiro commentedon Jun 14, 2016
One additional observation. The original message contained no Content-Transfer-Encoding header even though the message body was raw koi8-r characters. Adding
Content-Transfer-Encoding: 8bit
to the message headers avoids the issue, but that is not a practical solution as the message was Russian spam received by a Mailman list and the resultant KeyError caused problems in Mailman.
We can work on defending against this in Mailman, but I suggest that the munge_cte code in generator._write() avoid the documented possible KeyError raised by replace_header() by using __delitem__() and __setitem__() instead as in the attached generator.patch.
warsaw commentedon Oct 22, 2016
While I was reviewing https://gitlab.com/mailman/mailman/merge_requests/197/diffs I noticed the KeyError and it made me thing "hmm, I wonder if this should be turned into one of the email package errors"?
kyrias commentedon Jun 3, 2017
Any updates on this? I'm having the same problem with some non-spam emails while trying to use some mail-handling tools written in Python.
bitdancer commentedon Jun 3, 2017
replace_header has a different semantic than del-and-set (replace_header leaves the header in the same location in the list, rather than appending it to the end...that's it's purpose). If replace_header is throwing a key error, then I guess we need a look-before-you-leap if statement.
And a test :)
Note that a correct fix would preserve the broken input email, but since we're obviously already doing munging I'm fine with just making this work for now.
msapiro commentedon Jun 3, 2017
I considered look before you leap, but I decided since we're munging the headers anyway, preserving their order is not that critical, but the patch is easy enough. I'll work on that and a test.
kyrias commentedon Jun 3, 2017
Fix: kyrias@a986a82
Testcase: kyrias@9a51042
Can start a PR once my CLA signature goes through I guess.
msapiro commentedon Jun 3, 2017
It looks like Johannes beat me to it. Thanks for that, but see my comments in the diff at kyrias@a986a82
kyrias commentedon Jun 3, 2017
Ah, didn't even see your comment before I did it! Fix to the comments are on the same branch, will be rebased before PR is up.
matrixise commentedon Jun 8, 2017
maybe we could merge the PR, and I could propose a backport for 3.5 and 3.6.
2.7 is affected ?
bitdancer commentedon Jun 8, 2017
I'm going to try to review this this weekend.
matrixise commentedon Jun 8, 2017
ok, I have tested on 3.6 and 3.5, just with the test. and in this case, we get the errors on both.
if we apply the patch of Johannes, the test passes and there is no issues.
+1 the backports for 3.5 and 3.6 is just a git cherry-picking.
1 remaining item
bitdancer commentedon Jan 23, 2018
Note: I reviewed this a while ago but the review comments haven't been addressed.
bitdancer commentedon Jan 30, 2018
Requested a small additional change to the new tests, and then this will be ready to go in.
edeca commentedon Oct 5, 2018
Ping on an ETA for this fix?
csabella commentedon Mar 1, 2019
@r.david.murray, it appears that all your requested changes have been addressed on the PR. Please re-review this when you get a chance. Thanks!
diekhans commentedon Oct 6, 2020
any chance of getting this merged? A work-around is not obvious
msapiro commentedon Oct 6, 2020
I work around it with
This is easy for me because it's Mailman which already subclasses email.message.Message for other reasons. It is perhaps more difficult if you aren't already subclassing email.message.Message for other purposes.
miss-islington commentedon Oct 19, 2020
New changeset bf83822 by Mark Sapiro in branch 'master':
bpo-27321 Fix email.generator.py to not replace a non-existent header. (GH-18074)
bf83822
miss-islington commentedon Oct 19, 2020
New changeset 371146a by Miss Skeleton (bot) in branch '3.8':
bpo-27321 Fix email.generator.py to not replace a non-existent header. (GH-18074)
371146a
miss-islington commentedon Oct 19, 2020
New changeset 72ce82a by Miss Skeleton (bot) in branch '3.9':
bpo-27321 Fix email.generator.py to not replace a non-existent header. (GH-18074)
72ce82a