-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Mime] Fix undefined array key 0 when empty sender #53565
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
[Mime] Fix undefined array key 0 when empty sender #53565
Conversation
Can you please add a test to make sure that we don’t break this again. |
8fd3d85
to
a5f39b1
Compare
Done. It seems to me that the failing tests are related to cryptography errors and not my code |
@@ -140,7 +140,10 @@ public function generateMessageId(): string | |||
if ($this->headers->has('Sender')) { | |||
$sender = $this->headers->get('Sender')->getAddress(); | |||
} elseif ($this->headers->has('From')) { | |||
$sender = $this->headers->get('From')->getAddresses()[0]; | |||
if (empty($froms = $this->headers->get('From')->getAddresses())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (empty($froms = $this->headers->get('From')->getAddresses())) { | |
if ([] === $froms = $this->headers->get('From')->getAddresses()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used the proposition of Fabien instead, letting you resolve the conversation if it's okay with you
What about forbidding calling |
This is one of the ways I identified to fix this issue, I have no opinion on which is best for DX. I went with fixing it in the Message class because it could (I guess ?) be used by other components than Mailer so I would suggest to still fix this here even if we block this behavior in the |
I would do the fix in |
I adjusted the code with your reviews and added an exception if calling Email::from() with no addres, however the Plus the "add" version of those methods ( |
e94e473
to
ee49a78
Compare
Thank you @0x346e3730. |
Today I managed to produce the following error :

From the following code :
This happens because the
from
method from theSymfony\Component\Mime\Email
class adds the header even if the array of addresses is empty. I identified two ways of fixing this :Symfony\Component\Mime\Message
class before accessing the key 0 and throw a better exception in case the adresses are emptyfrom
method so that it doesn't add the header if the adresses are empty; or throw an exception when trying to do so.I'm unsure what method is the cleaner, I thought that fixing the Message access of an undefined key was the widest fix (as I guess it could happen from somewhere else than the Mailer component). Also not sure how to test that and wanted to make sure this fix was good before testing it.