-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Mime] allow non-ASCII characters in local part of email #36178
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
Conversation
961bc6a
to
a359737
Compare
a359737
to
2a1e6b0
Compare
@fabpot seeing that you wrote this component: Any idea from your side about this issue? |
@symfony/mergers anyone able to help with this one? |
@dmaicher Python supports this too via the Go supports it too:
And that's the RFC that describes this: https://www.ietf.org/rfc/rfc2047.txt |
@javiereguiluz as far as I understand rfc 2047 does not apply for email addresses?
It would only apply for the "name" part of some recipient address header. But not the address itself. |
@dmaicher I read too fast then. Sorry 😞 |
@javiereguiluz any idea how to move this forward? This issue keeps me from using the |
I think we can do this change, but only if we also forbid non-ASCII chars in the local part of the envelope sender. The reason is that there always must be a path to receive bounces, and the envelope-sender is their destination. |
@nicolas-grekas first of all thank you for taking to time to look into this! 😊
Not sure I follow this comment. So currently this change should impact the envelope sender as well, right? Seeing that the envelope sender is also an So you mean we should change this behavior for the envelope sender? |
We shouldn't necessarily change the behavior of going through the encoder, but we should add a check, in Mailer, to reject any local part with non-ASCII characters. This will ensure that any bounce message will be able to come back to the sender independently of whether SMTP hops are able to deal with UTF-8 or not. This looks like a critical property to me. |
Ok fair enough. That seems good to me 👍 How should we do this? Inside |
Inside Envelope? this would allow reusing |
3f1ee9b
to
7609bac
Compare
@fabpot would have been great to see this change in 4.4 LTS... but ok. Why do you think this cannot be treated as a bugfix? Anyway I rebased it 😉 |
Thank you @dmaicher. |
It looks like this broke some tests for bridges, could you please have a look @dmaicher? |
@nicolas-grekas ah sorry I missed those test fails. @fabpot I could simply fix those test fails but not sure the change in behavior is really correct 😕 For example the test fail in $transport = new MandrillApiTransport('KEY', $client);
$mail = new Email();
$mail->subject('Hello!')
->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
->from(new Address('fabpot@symfony.com', 'Fabien'))
->text('Hello There!');
$message = $transport->send($mail); Now with my changes the name "Fabien" is dropped from the sender address and before it was passed on to Mandrill as EDIT: or maybe the mandrill transport (and others) should not use the sender as "from"? As per RFC the "Sender" can only be an email address without a name as @fabpot mentioned here: #36178 (comment) EDIT: So for example diff --git a/src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillApiTransport.php b/src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillApiTransport.php
index 50be4e02cb..027c67cd10 100644
--- a/src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillApiTransport.php
+++ b/src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillApiTransport.php
@@ -72,19 +72,25 @@ class MandrillApiTransport extends AbstractApiTransport
private function getPayload(Email $email, Envelope $envelope): array
{
+ $fromAddresses = $email->getFrom();
+ $from = reset($fromAddresses);
+
$payload = [
'key' => $this->key,
'message' => [
'html' => $email->getHtmlBody(),
'text' => $email->getTextBody(),
'subject' => $email->getSubject(),
- 'from_email' => $envelope->getSender()->getAddress(),
'to' => $this->getRecipients($email, $envelope),
],
];
- if ('' !== $envelope->getSender()->getName()) {
- $payload['message']['from_name'] = $envelope->getSender()->getName();
+ if ($from) {
+ $payload['message']['from_email'] = $from->getAddress();
+
+ if ('' !== $from->getName()) {
+ $payload['message']['from_name'] = $from->getName();
+ }
}
foreach ($email->getAttachments() as $attachment) { |
Dunno if it helps decide, but this affects deps=high on 4.4 also. |
How does Mandrill use the |
@xabbuh not sure how Mandrill is handling that but Mailgun seems to use it for the See https://documentation.mailgun.com/en/latest/api-sending.html#sending
And there we also use the envelope sender: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Mailer/Bridge/Mailgun/Transport/MailgunApiTransport.php#L94 But that means the "Sender customization feature" using EnvelopeListener would then not work anymore if we change that? 😕 |
…sports (fabpot) This PR was merged into the 4.4 branch. Discussion ---------- [Mime] Keep Sender full address when used by non-SMTP transports | Q | A | ------------- | --- | Branch? | 4.4 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | n/a <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | n/a refs #36178 The `Envelope` is an SMTP concept. The Sender is used in the `MAIL FROM` SMTP command, where only an address is supported. But we are also supporting non-SMTP transports, where the Sender might also be used as the `From` header, where a full mailbox is supported. To take into account the 2 usages, this PR keeps the full mailbox in the Envelope and let the SMTP class only use the address (which was already the case anyway). Commits ------- 1ca9be7 [Mime] Keep Sender full address when used by non-SMTP transports
I'am sorry but i have to ask, will this "feature" be part of the 5.2 release or will it be an addition to 5.1.4? Another Question is there currently any way to temporarily replace/bypass the \Symfony\Component\Mime\Encoder\IdnAddressEncoder or worse the \Symfony\Component\Mime\Address to create an workaround for this issue? |
@MaSpeng this was merged as a feature in According to the Symfony Release Process minor versions (e.g. 5.1.4) only contains bug fixes and never new features. So, this will be included only in 5.2 and higher versions, but not in 5.1.*. The good news is that Symfony 5.2 release is just a few months ago (feature freeze starts in just 6 weeks!) and you can upgrade your app from 5.1 to 5.2 without breaking changes. |
@javiereguiluz Many thanks for the explanations. |
This fixes #34932 by allowing non-ASCII characters in the local part of emails.
I tried this using 3 different smtp servers (gmail, mailgun and local postfix) and for me this just works in case there are non-ASCII characters in the local part of emails. Emails are correctly delivered.
PHPMailer does this in the same way: https://github.com/PHPMailer/PHPMailer/blob/master/src/PHPMailer.php#L1411
This is also in line with the behavior of Swiftmailer (< 6.1) before this commit that introduced the
IdnAddressEncoder
: swiftmailer/swiftmailer@6a87efd#diff-e5f85d26733017e183b2633ae3c433f0R31I'm not an expert when it comes to SMTP and all the different RFCs out there 😕 But for me this exception seems not needed.
Maybe @c960657 can help here?