Skip to content

HTML Body Inside multipart/related Container Incorrectly Recognized as Attachment #580

Open
@ETES-Stuttgart

Description

@ETES-Stuttgart

Describe the bug
When parsing an email with HTML content inside a multipart/related container, the content is incorrectly recognized as an attachment rather than being parsed as the email's HTML body.

Used config
The default config.

Code to Reproduce

  1. Use the following raw message:
Return-Path: <ggg@example.de>
Date: Thu, 20 Feb 2025 03:44:22 +0100 (CET)
From: ggg@example.de
To: contact@your-company.de, ggg@example.de
Message-ID: <23975424.234.982154931647567.JavaMail.ggg@example.de>
Subject: html body in multipart related container is parsed as attachment
MIME-Version: 1.0
Content-Type: multipart/mixed;
	boundary="----=_Part_255_1307735605.1740019462622"

------=_Part_255_1307735605.1740019462622
Content-Type: multipart/related;
	boundary="----=_Part_256_1484807935.1740019462623"

------=_Part_256_1484807935.1740019462623
Content-Type: text/html;charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html>
<html>
<head>
  <style>
    p {
      font-family: "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
      font-size: 13px;
    }
  </style>
</head>
<body>
<p>
  This is a message in a multipart related container
</p>
</body>
</html>
------=_Part_256_1484807935.1740019462623--

------=_Part_255_1307735605.1740019462622--
  1. Use the following PHP test case:
public function testIssueEmail() {
        $filename = implode(DIRECTORY_SEPARATOR, [__DIR__, "..", "messages", "the-raw-message.eml"]);
        $message = Message::fromFile($filename);

        self::assertNotEmpty($message->getHTMLBody());
        self::assertStringContainsString("This is a message in a multipart related container", $message->getHTMLBody());
        self::assertCount(0, $message->getAttachments());
    }
  1. Execute the test and it will fail.

Expected behavior
The HTML content inside the multipart/related container should be correctly identified and parsed as the email's HTML body, not as an attachment.

Desktop:

  • OS: Manjaro
  • PHP: 8.4
  • laravel-imap version 6.2.0

Additional context:

  • In the example above, the email contains only HTML content, so the use of multipart/related is technically unnecessary. However, this container is often automatically generated by mail systems (e.g., JavaMail) when sending HTML content, even if there are no inline resources (like images or stylesheets) to relate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions