Skip to content

Bad Content-type value causes crash #234

@da4089

Description

@da4089

I'm a new user of offlineimap3.

OS: Debian 13 / trixie
offlineimap3: 8.0.0
Python: 3.13.5 (Debian standard package)

While trying to make a local (maildir) backup of my IMAP folders, offlineimap exits with an exception:

ERROR: Exceptions occurred during the run!
ERROR: Copying message 1079 [acc: pobox]
  TypeError: utf7m_decode() takes 1 positional argument but 2 were given
decoding with 'iso-8859-1from:auctions@tigergroupllc.com' codec failed


Traceback:
  File "/usr/share/offlineimap3/offlineimap/folder/Base.py", line 822, in copymessageto
    message = self.getmessage(uid)
  File "/usr/share/offlineimap3/offlineimap/folder/IMAP.py", line 352, in getmessage
    msg_s = msg.as_string(policy=self.policy['8bit-RFC'])
  File "/usr/lib/python3.13/email/message.py", line 1004, in as_string
    return super().as_string(unixfrom, maxheaderlen, policy)
           ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/email/message.py", line 188, in as_string
    g.flatten(self, unixfrom=unixfrom)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/email/generator.py", line 117, in flatten
    self._write(msg)
    ~~~~~~~~~~~^^^^^
  File "/usr/lib/python3.13/email/generator.py", line 182, in _write
    self._dispatch(msg)
    ~~~~~~~~~~~~~~^^^^^
  File "/usr/lib/python3.13/email/generator.py", line 219, in _dispatch
    meth(msg)
    ~~~~^^^^^
  File "/usr/lib/python3.13/email/generator.py", line 245, in _handle_text
    payload = msg.get_payload()
  File "/usr/lib/python3.13/email/message.py", line 301, in get_payload
    payload = bpayload.decode(self.get_content_charset('ascii'), 'replace')

I dug out what seems to be the email that triggers the bug, and indeed, its Content-type header is bogus:

MIME-version: 1.0
Content-transfer-encoding: 8BIT
Content-type: text/html; charset="iso-8859-1From:auctions@tigergroupllc.com"

(It's been 12 years, and numerous email systems since it was first sent: it might have been corrupt from the start, or somehow broken over the years since)

Regardless of how it got that way, it'd be great if offlineimap3 was able to carry on processing (as my various MUAs seem to do).

I can write Python, so I can probably do most of the work for a patch, but I'm looking for some guidance as to how I should approach the situation.

Thanks in advance for any assistance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions