-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pyzmail crashes when parsing a mail with badly encoded UTF-8 header #12
Comments
No problem for me if use:
|
Thanks for checking, srault95. Maybe it's a windows-linux difference? At my Debian it happens with Python 3.4.3, pyzmail 1.0.3. Using pyzmail.message_from_file() on that file also raises an exception. |
Thank you amikoren, I can reproduce the problem and I will provide a fix soon. srault95, you are using the "old python2" interface (aka the text interface)
In "open('mail_utf8_error')" What amikoren is doing is more like this
And what you are doing is more like this
replace 'cp1252' with you local Windows encoding. |
Hello aspineux,
I have a crash happenning at pyzmail, at some rare malformed mail file. It seems like a pyzmail mistreating such file.
Details:
Python version:pyt 3.4.2
pyzmail - 1.0.3
Linux - Debian 8
$ grep version /usr/lib/python3.4/email/init.py
version = '5.1.0'
Crash reason:
If header can not be encoded (UTF-8 is badly encoded), Compat32._sanitize_header() at _policy_base.py doesn't return a string, but an instance of class email.header.Header
That causes pyzmail to crash when trying to activate Header.startswith()
Reproduce:
Take the attached file, and run from python3:
import pyzmail
pyzmail.message_from_bytes(open('/tmp/mail_utf8_error', 'rb').read())
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.4/dist-packages/pyzmail/parse.py", line 774, in message_from_bytes
return PyzMessage(email.message_from_bytes(s, _args, *_kws))
File "/usr/local/lib/python3.4/dist-packages/pyzmail/parse.py", line 634, in init
self.mailparts=get_mail_parts(self)
File "/usr/local/lib/python3.4/dist-packages/pyzmail/parse.py", line 482, in get_mail_parts
mailparts.append(MailPart(part, filename=filename, type=type, charset=charset, content_id=part.get('Content-Id'), description=part.get('Content-Description'), disposition=disposition, is_body=parts.get(part, False)))
File "/usr/local/lib/python3.4/dist-packages/pyzmail/parse.py", line 98, in init
if self.content_id.startswith('<') and self.content_id.endswith('>'):
AttributeError: 'Header' object has no attribute 'startswith'
mail_utf8_error.zip
The text was updated successfully, but these errors were encountered: