[issue36180] mboxMessage.get_payload throws TypeError on malformed content type

Karthikeyan Singaravelan report at bugs.python.org
Sun Apr 14 02:40:20 EDT 2019


Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:

A simplified reproducer as below. The tuple is returned from here https://github.com/python/cpython/blob/830b43d03cc47a27a22a50d777f23c8e60820867/Lib/email/message.py#L93 and perhaps is an untested code path? The charset gets a tuple value of ('utf-8��', '', '"utf-8Â\xa0"') . 


import mailbox
import tempfile

broken_message = """
>From list at murphy.debian.org Wed Sep 24 01:22:15 2003
Date: Wed, 24 Sep 2003 07:05:50 +0200
From: Test test <test at example.or>
To: debian-devel-french at lists.debian.org
Subject: Re: Test
Mime-Version: 1.0
Content-Type: text/plain; charset*=utf-8†''utf-8%C2%A0

trés intéressé
"""

with tempfile.NamedTemporaryFile() as f:
    f.write(broken_message.encode())
    f.seek(0)
    msg = mailbox.mbox(f.name)
    for m in msg:
        print(m.get_payload())

$ ../cpython/python.exe bpo36180.py
Traceback (most recent call last):
  File "bpo36180.py", line 21, in <module>
    print(m.get_payload())
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/email/message.py", line 267, in get_payload
    payload = bpayload.decode(self.get_param('charset', 'ascii'), 'replace')
TypeError: decode() argument 1 must be str, not tuple
sys:1: ResourceWarning: unclosed file <_io.BufferedRandom name='/var/folders/2b/mhgtnnpx4z943t4cc9yvw4qw0000gn/T/tmp4ddavb6g'>

----------
nosy: +xtreak

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


More information about the Python-bugs-list mailing list