Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ETES-Stuttgart opened this issue May 16, 2025 · 1 comment
Labels
bug Something isn't working validating

Comments

@ETES-Stuttgart
Copy link

ETES-Stuttgart commented May 16, 2025

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: <[email protected]>
Date: Thu, 20 Feb 2025 03:44:22 +0100 (CET)
From: [email protected]
To: [email protected], [email protected]
Message-ID: <[email protected]>
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.
@Webklex Webklex added bug Something isn't working validating labels May 27, 2025
@mrhewitt
Copy link

FYI, it seems this is related to my issue #582

If I revert change commited in commit fad09ad and return line 116 in Struture.php to original
return $this->detectParts($boundary, $body, $part_number);
his example mail returns a body

So it seems PR for issue #455 may be affecting this too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working validating
Projects
None yet
Development

No branches or pull requests

3 participants