python / python/cpython

standard library email.parser fails to recognize multipart message

Open
#135,854 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib topic-email type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

If an email message with attachments contain a boundary with the characters "<--- ... --->" the email.parser module fails to recognize the message as being multipart.

I have attached to this bug report an example mailbox file, and when the following snippet is run on it you will see that is_multipart() returns False, although the message is clearly a multipart message.

I found this boundary string used in a real life email I received.

from email.parser import Parser

# Create parser instance
P = Parser()

with open("message-error.mbox") as f:
    msg = P.parse(f)

print(msg.is_multipart())

message-error.txt

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs
  • gh-135891

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied message-error.txt mailbox and the email.parser Parser snippet, then inspect multipart boundary handling in the standard library. Review linked PR gh-135891 for the work already underway. Done means the example is recognized as multipart and msg.is_multipart() returns True.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.