Skip to content

pyzmail crashes when parsing a mail with badly encoded UTF-8 header #12

@amikoren

Description

@amikoren

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions