You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Hi, I would like to use mailparser on a BytesIO() object in python 3 but fail to load the message.
I have to use the object of class 'bytes' because I get the data handed this way.
I also tried with the other parse_from_ functions. All fail.
To Reproduce
Steps to reproduce the behavior:
Minimal working example
from io import BytesIO
from os import read
import mailparser
fp = BytesIO()
with open('mail_file.eml', 'rb') as f:
filecontent = f.read()
print("type(filecontent)= ", type(filecontent))
fp.write(filecontent)
mail = mailparser.parse_from_bytes(fp)
print(mail.body)
this results in
$ python testparser.py
type(filecontent)= <class 'bytes'>
Traceback (most recent call last):
File "testparser.py", line 15, in <module>
mail = mailparser.parse_from_bytes(fp)
File "/home/xxx/.local/lib/python3.8/site-packages/mailparser/mailparser.py", line 118, in parse_from_bytes
return MailParser.from_bytes(bt)
File "/home/xxx/.local/lib/python3.8/site-packages/mailparser/mailparser.py", line 240, in from_bytes
message = email.message_from_bytes(bt)
File "/usr/lib/python3.8/email/__init__.py", line 46, in message_from_bytes
return BytesParser(*args, **kws).parsebytes(s)
File "/usr/lib/python3.8/email/parser.py", line 122, in parsebytes
text = text.decode('ASCII', errors='surrogateescape')
AttributeError: '_io.BytesIO' object has no attribute 'decode'
Expected behavior
mailparser.parse_from_bytes(fp) to load the object and be able to parse the message
Raw mail
Do you need the raw message? This is a pre parser problem so the message should be irrelevant.
Environment:
OS: Linux Ubuntu 20.04
Docker: no
mail-parser version: 3.15.0
python: 3.8.10
Thansk for your response.
The text was updated successfully, but these errors were encountered:
Describe the bug
Hi, I would like to use mailparser on a BytesIO() object in python 3 but fail to load the message.
I have to use the object of class 'bytes' because I get the data handed this way.
I also tried with the other
parse_from_
functions. All fail.https://docs.python.org/3/glossary.html#term-bytes-like-object explizit mentions Objects of type bytes as a "bytes-like object".
Is there another way I'm not aware of?
To Reproduce
Steps to reproduce the behavior:
Minimal working example
this results in
Expected behavior
mailparser.parse_from_bytes(fp) to load the object and be able to parse the message
Raw mail
Do you need the raw message? This is a pre parser problem so the message should be irrelevant.
Environment:
Thansk for your response.
The text was updated successfully, but these errors were encountered: