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

Fixed "emails are displayed incorrectly" with PHP 8.1+ #344

Merged
merged 2 commits into from
Aug 9, 2023

Conversation

fballiano
Copy link

@fballiano fballiano commented Apr 18, 2023

This PR should fix issue #274 and issue OpenMage/magento-lts#3174 in OpenMage.

EDIT: this PR ports the fix used by laminas in https://github.com/laminas/laminas-mail/blob/2.23.x/src/Transport/Sendmail.php#L142-L147

Copy link

@kiatng kiatng left a comment

Choose a reason for hiding this comment

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

Tested on PHP7.3 and PHP8, Linux.

@ADDISON74
Copy link

I used DDEV and as PHP versions 7.4, 8 and 8.1. No issuess occurred. What was reported related to OpenMage is now resolved.

@glensc
Copy link
Collaborator

glensc commented Apr 18, 2023

Is this fixed in zendframework 2 and/or laminas the same way?

@fballiano
Copy link
Author

i've no idea, I don't know much about those two

@glensc
Copy link
Collaborator

glensc commented Apr 18, 2023

those are both successors of zf1, so they might have fixed this too.

this may safe change, i.e change for all users, could break some other agents:

you probably should set the property yourself, as it's public property,
unless you find they have fixed it same way or some rfc supports that \r\n must be used or PHP 8.1 own docs?

@fballiano
Copy link
Author

since multiple people in #274 are facing this problem I think it should be fixed at a framework level anyway.

@fballiano
Copy link
Author

There's also this: php/php-src#8086

@kiatng
Copy link

kiatng commented Apr 18, 2023

I know nothing about Laminas, but the fix is about the same. First, the EOL const is defined same as this PR:

https://github.com/laminas/laminas-mail/blob/2.23.x/src/Headers.php#L51
image

Second, it is converted to "\n" for non-WIN OS:

https://github.com/laminas/laminas-mail/blob/2.23.x/src/Transport/Sendmail.php#L142-L147
image

This PR doesn't check for WIN OS and PHP ver.

[edit] But when testing PHP 7.3 and 7.4 in Linux, the fix in this PR works. So, this PR seems good.

@glensc
Copy link
Collaborator

glensc commented Apr 18, 2023

since multiple people in #274 are facing this problem I think it should be fixed at a framework level anyway.

this not a good excuse. because if this is a breaking change the rest of the users start to complain for whom it worked before.

@fballiano
Copy link
Author

did you check php/php-src#8086?

I see the worry about the possible BC, but not doing anything is BC for an opposite equal amount of people...

@fballiano
Copy link
Author

would you like a PR which is more similar to laminas?

@ADDISON74
Copy link

@glensc - My personal opinion is that ZF1-Future must have the source code related to this issue similar to Laminas-Mail. It is obvious that this change is necessary, but the one in Laminas-Mail covers all the issues that could arise with its adoption.

@glensc
Copy link
Collaborator

glensc commented Apr 18, 2023

I've read along:

mostly people are frustrated by the change, but PHP devs say \r\n is standards conformant. but really standards is for smtp saying must be \r\n terminated, no standard how one should talk to /usr/lib/sendmail.

perhaps introduce similar behavior to:
-php/php-src#10191

i.e respect mail.mixed_lf_and_crlf in setting, so if that option is set, go back to previous behavior otherwise go with \r\n.
must consider that the option may be missing on older PHP versions.

not sure what is "similar to laminas", you just linked to a line. maybe commit or pull request making the change has more context?

@fballiano
Copy link
Author

Most similar to laminas i mean the code posted by @kiatng obviously.

I’m doing it if you’ll consider it, otherwise I’ll check other solutions internally, sorry but time is precious for everybody.

@glensc
Copy link
Collaborator

glensc commented Apr 18, 2023

phpmailer seems has taken totally different approach. tells to use smtp rather sendmail driver :)

@glensc
Copy link
Collaborator

glensc commented Apr 18, 2023

php mail() and mb_send_mail() also say (now) to use \r\n, and as last result fall back to \n:

@glensc
Copy link
Collaborator

glensc commented Apr 18, 2023

Seems checking mail.mixed_lf_and_crlf is not a viable solution. it's not present in any release PHP version

php -d mail.mixed_lf_and_crlf=1 -r 'var_dump([ini_get("mail.mixed_lf_and_crlf"), PHP_VERSION]);'        
array(2) {
  [0]=>
  bool(false)
  [1]=>
  string(5) "8.2.3"
}

See also:

@glensc
Copy link
Collaborator

glensc commented Apr 18, 2023

@fballiano laminas way is the recommended solution, I said as first note here:

likely battle-tested by them as the changes already seem 3yr old.

but it may be more changes than just those lines printed here:

@fballiano
Copy link
Author

I rewrote the PR, not sure about the $fromEmailHeader, which shouldn't contain an EOL anyway...

@glensc
Copy link
Collaborator

glensc commented Apr 18, 2023

What abuot EOL constant? in zf2/laminas it's there since 2012:

Describe your changes and thinking logic in PR body.

@fballiano
Copy link
Author

I see no other EOL constant in the Zend/Mail folder.

@ADDISON74
Copy link

ADDISON74 commented Apr 18, 2023

I guess @glensc wants to use self::EOL instead of "\r\n", like here

zendframework/zendframework@5f899d3#diff-cd2e235ede76dad36d06a755991777edb55781b2fc4321c74fb7d17605522834

@glensc
Copy link
Collaborator

glensc commented Apr 18, 2023

Indeed, somehow I looked only the new commit, and assumed it was force pushed, but the original commit is still here:

@fballiano
Copy link
Author

I’d keep it this way in case somebody extends the class. I think it’s the same thought the laminas people did

@fballiano
Copy link
Author

any news on the merge of this PR?

@develart-projects develart-projects added the enhancement New feature or request label Aug 9, 2023
@develart-projects
Copy link
Collaborator

@fballiano I'll review that in comming days, now focusing on the bugfix release.

@develart-projects develart-projects added this to the 1.23.0 milestone Aug 9, 2023
@develart-projects
Copy link
Collaborator

Checked all information presented, I think we are good to go here.

@develart-projects develart-projects merged commit ae9e5df into Shardj:master Aug 9, 2023
@fballiano fballiano deleted the patch-1 branch August 9, 2023 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants