Skip to content

Conversation

mrhewitt
Copy link

I implemented a fix here for Issue 582 and related (issues of bodies not being decoded etc) as follows:

  1. Added new config option, "allow_single_parts", bool defaulting to true

  2. Altered Structure::parsePart to alter "fix" commited in issue Fix bug when multipart message getHTMLBody() method returns null #455 to rather be:

if ( count($parts) > 1 || $config->get("options")['allow_single_parts'] ) {

This will now always return parts if there are multiple but allows it to optionally also return if only a single part is found.

I believe the default here should be true (always return recursive part even if only one part is found in a multipart block) as this how it operated for years before, and it would seem in most cases looking at all issues raised since this commit was pulled in this is valid behavior (otherwise we get undecoded parts).

For edge cases such as experienced by @michalkortas there is the possiblity of setting "allow_single_parts" to false in thier configuration, thus still achieving what they set out to in the PR but in a way that does not affect most users.

@mrhewitt mrhewitt changed the title Issue 582 - Default to returning all parts, add allow_single_parts op… Resolves #582 - Default to returning all parts, add allow_single_parts op… May 30, 2025
Copy link

@ETES-Stuttgart ETES-Stuttgart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this change and can confirm that it also fixes issue #580.

// we return these parts if there are multiple or if configured to allow a single part here (default)
// isolated cases a single part here causes an empty body, to workaround this set
// allow_single_parts to false in your config
if ( count($parts) > 1 || $config->get("options")['allow_single_parts'] ) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ( count($parts) > 1 || $config->get("options")['allow_single_parts'] ) {
if ( count($parts) > 1 || $config->get("options.allow_single_parts") ) {

Copy link

@radek-hill radek-hill Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to check, if there are some parts, otherwise it will return empty parts when it is empty
if ( count($parts) > ($config->get("options.allow_single_parts") ? 0 : 1) ) {

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not always allow single parts? I think just 'count() == 0' needs to be disregarded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants