Repository navigation
mailbox.mbox fails on non ASCII characters #86599
Description
Activity
I'm importing some mbox archives into my maildirs, and use
mailbox.mboxto parse archives created by pipermail.Some of these archives seem to contain non-ascii characters, and python just throws a
UnicodeDecodeErrorand refuses to process the archive.Reproducer: (successful on 3.7.9, 3.8.5, 3.9.0)
curl https://lists.freedesktop.org/archives/systemd-devel/2016-January.txt.gz | zcat > mbox.txt python3 -c "import mailbox; mb = mailbox.mbox('mbox.txt');mb.items()"- added3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of life
on Nov 22, 2020 The problem with that archive is that it is not in proper mbox format. It contains the following line (5689):
From here I was hoping to run something like “dbus-send –system –dest=Test.Me –print-reply /Japan Japan.Reset.Test string:”Hello””You will note that there is no leading '>' on that line to escape that 'From '. So mbox tries to build a 'From ' line from it, and fails because 'From ' lines should not contain any non-ascii characters. It can be argued that that failure is sub-optimal...it should probably be calling decode('ascii', errors='replace') so that the parse doesn't fail, just like it would not fail if there were no non-ascii in the unescaped 'From ' line.
Yeah, not questioning here this might be badly formatted, but given these files are out there, and the parser is somewhat forgiving in other cases, it should be tolerant there as well.
9 remaining items
Based on https://bugs.python.org/issue42433#msg382169 I added back the versions that bug is present.
The PR is up to and appropriately linked (I think?) - let me know if there's anything left to be done from my side.
- added3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of life
on Dec 5, 2020 3.7 only gets security fixes. If and when someone merges something, that person will decide whether to backport.
- removed3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of life
on Dec 5, 2020
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:
bugs.python.org fields: