Skip to content

[Mailer] Capitalise From and Bcc header names in global mailer configuration #16428

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

Merged
merged 1 commit into from
Jan 22, 2022

Conversation

andyexeter
Copy link
Contributor

@andyexeter andyexeter commented Jan 21, 2022

If the From header name is not capitalised, the header is replaced by the Sender address in the Mime component's Message object:
https://github.com/symfony/symfony/blob/6a52b66da0d35b21031bb344e79522f73d60e05a/src/Symfony/Component/Mime/Message.php#L76-L81

I capitalised Bcc as well because the component also looks for this header in a case-sensitive way.

@carsonbot carsonbot added this to the 5.4 milestone Jan 21, 2022
@javiereguiluz
Copy link
Member

Andy, thanks a lot for fixing this. In my opinion, this behavior is extremely fragile and dangerous. Couldn't we instead improve code to make these config values case insensitive (and fix casing, if needed, in code transparently to users)?

@andyexeter
Copy link
Contributor Author

I can take a look at creating a PR to make the values case insensitive, but in my opinion that should be done as well as, rather than instead of this PR.

I believe the documentation should show the "correct" way of doing things - and in this case it's correct for the From and Bcc headers to be capitalised as per RFC 2822 and as per Symfony's usage e.g:

https://github.com/symfony/symfony/blob/1ebb5d9605ffecf23124413ea6bde729a223e610/src/Symfony/Component/Mime/Email.php#L121
https://github.com/symfony/symfony/blob/1ebb5d9605ffecf23124413ea6bde729a223e610/src/Symfony/Component/Mime/Email.php#L217

@andyexeter
Copy link
Contributor Author

andyexeter commented Jan 22, 2022

I've done some more digging into this and it appears I was incorrect in my initial diagnosis of this issue.

The Mime component does not replace the From header with the Sender header if the From header is not capitalised. This was actually a red herring caused by me using Mailhog SMTP in dev and the Mailgun API transport in production.

There are a couple of different issues at play here:

In the symfony/mailgun-mailer component, the ApiTransport simply always uses the sender as the from address, ignoring any From headers set regardless of case:

https://github.com/symfony/mailgun-mailer/blob/0c29398dfc1cc55a89247dd3bc5d63fad4e098e5/Transport/MailgunApiTransport.php#L100

The symfony/mailer component just sends the headers as-is, without capitalising them. This causes Mailhog (and perhaps other clients?) to ignore the from header and use the Sender header instead.

Whether the behaviour in the mailer should change and capitalise headers is up for debate but the mailgun-mailer ApiTransport disregarding the From header is a bug IMO - I will open a PR on this.

@carsonbot carsonbot changed the title Capitalise From and Bcc header names in global mailer configuration [Mailer] Capitalise From and Bcc header names in global mailer configuration Jan 22, 2022
@javiereguiluz javiereguiluz modified the milestones: 5.4, 5.3 Jan 22, 2022
@javiereguiluz
Copy link
Member

Andy thanks a lot for taking a look into this in detail. Let's merge this becuase, as you said, this is definitely a bug in docs ... and let's ee if we can fix/improve other things in code. Thanks!

@javiereguiluz javiereguiluz merged commit c0787c7 into symfony:5.3 Jan 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants