[New-bugs-announce] [issue43530] email.parser.BytesParser failed to parse mail when it is with BOM

tzing report at bugs.python.org
Wed Mar 17 11:45:56 EDT 2021


New submission from tzing <tzingshih at gmail.com>:

Python's builtin `email.parser.BytesParser` could not properly parse the message when the bytes starts with BOM.

Not 100% ensured- but this issue seems cause by that `FeedParser._parsegen` could not match any of the header line after the data is decoded.

Steps to reproduce:
1. get email sample. any from https://github.com/python/cpython/tree/master/Lib/test/test_email/data. I use msg_01.txt in following code
2. re-encoded the mail sample to some encoding with BOM
3. use `email.parser.BytesParser` to parse it

```py
import email
with open('msg_01.txt', 'rb') as fp:
    msg = email.parser.BytesParser().parse(fp)
print(msg.get('Message-ID'))
```

Expect output `<15090.61304.110929.45684 at aaa.zzz.org>`, got `None`

----------
components: Library (Lib)
messages: 388929
nosy: tzing
priority: normal
severity: normal
status: open
title: email.parser.BytesParser failed to parse mail when it is with BOM
type: behavior
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43530>
_______________________________________


More information about the New-bugs-announce mailing list