Skip to content
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

__toString Messing Up SMTP From Header #243

Open
mwyres opened this issue Sep 3, 2024 · 2 comments
Open

__toString Messing Up SMTP From Header #243

mwyres opened this issue Sep 3, 2024 · 2 comments

Comments

@mwyres
Copy link

mwyres commented Sep 3, 2024

Weird modification to the "From" line:

$content = "From user@example.com   ".@date("D M d H:i:s Y")."\n";
$content .= stream_get_content(STDIN);
$parser = new MailMimeParser();
$message = $parser->parse($content,FALSE);

<perform actions on $message>

$result .= $message->__toString();

The resulting "From" line in $result comes back with weird additional spaces in the date - (note the weird space in between hours and minutes in the formatted date string?)

From user@example.com  Wed Sep 04 01: 31:55 2024 

Workaround is not to pass the content with the "From" line through the __toString() function, that is:

$content = stream_get_content(STDIN);
$parser = new MailMimeParser();
$message = $parser->parse($content,FALSE);

<perform actions on $message>

$output = $message->__toString();
$result = "From user@example.com   ".@date("D M d H:i:s Y")."\n";
$result .= $output;

This gives the "From" line correctly, without the weird space:

From user@example.com  Wed Sep 04 01:31:55 2024 

Given there is a workaround, this is not a critical issue, but somewhere between the creation of MimeMailParser object, and the output using __toString, the "From" line is being handled weirdly.

Note, this is not the "From:" header from further down - this is the very first line that appears at the top of emails after processing via Postfix, and needs to exist if you are post-processing back through Postfix.

Happy to explain further if this isn't completely clear.

@zbateson
Copy link
Owner

zbateson commented Sep 4, 2024

This library only parses mime messages, the first "SMTP" line shouldn't be passed to $parser->parse in your example, it should be filtered out.

@mwyres
Copy link
Author

mwyres commented Sep 5, 2024

As in it is treating that first line as:

From user@example.com Wed Sep 04 01:

...as the header name, adding the space, and then:

31:55 2024

...as the value of the header, given it's after the first colon.

Make sense - relatively easy to workaround, but would be a "nice to have" if it could work around it.

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

No branches or pull requests

2 participants