This commit is contained in:
2025-05-12 14:25:25 +02:00
parent ab2db755ef
commit 9e378ca2b7
2719 changed files with 46505 additions and 60181 deletions

View File

@@ -24,7 +24,7 @@ class Message extends RawMessage
private Headers $headers;
private ?AbstractPart $body;
public function __construct(Headers $headers = null, AbstractPart $body = null)
public function __construct(?Headers $headers = null, ?AbstractPart $body = null)
{
$this->headers = $headers ? clone $headers : new Headers();
$this->body = $body;
@@ -42,7 +42,7 @@ class Message extends RawMessage
/**
* @return $this
*/
public function setBody(AbstractPart $body = null): static
public function setBody(?AbstractPart $body = null): static
{
if (1 > \func_num_args()) {
trigger_deprecation('symfony/mime', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
@@ -130,11 +130,11 @@ class Message extends RawMessage
*/
public function ensureValidity()
{
if (!$this->headers->has('To') && !$this->headers->has('Cc') && !$this->headers->has('Bcc')) {
if (!$this->headers->get('To')?->getBody() && !$this->headers->get('Cc')?->getBody() && !$this->headers->get('Bcc')?->getBody()) {
throw new LogicException('An email must have a "To", "Cc", or "Bcc" header.');
}
if (!$this->headers->has('From') && !$this->headers->has('Sender')) {
if (!$this->headers->get('From')?->getBody() && !$this->headers->get('Sender')?->getBody()) {
throw new LogicException('An email must have a "From" or a "Sender" header.');
}
@@ -146,7 +146,10 @@ class Message extends RawMessage
if ($this->headers->has('Sender')) {
$sender = $this->headers->get('Sender')->getAddress();
} elseif ($this->headers->has('From')) {
$sender = $this->headers->get('From')->getAddresses()[0];
if (!$froms = $this->headers->get('From')->getAddresses()) {
throw new LogicException('A "From" header must have at least one email address.');
}
$sender = $froms[0];
} else {
throw new LogicException('An email must have a "From" or a "Sender" header.');
}