function OriginatorSubscriber::removeRedundantSender

Removes the Sender address if it is redundant.

Rules according to RFC 5322 section 3.6.2 (Originator Fields):

  • If the from field contains more than one mailbox specification in the mailbox-list, then the sender field, containing the field name "Sender" and a single mailbox specification, MUST appear in the message.
  • The "Sender:" field specifies the mailbox of the agent responsible for the actual transmission of the message.
  • If the originator of the message can be indicated by a single mailbox and the author and transmitter are identical, the "Sender:" field SHOULD NOT be used.

Parameters

\Symfony\Component\Mime\Email $message: The email message.

See also

https://www.rfc-editor.org/rfc/rfc5322.html#section-3.6.2

1 call to OriginatorSubscriber::removeRedundantSender()
OriginatorSubscriber::onMessage in core/lib/Drupal/Core/Mailer/EventSubscriber/OriginatorSubscriber.php
Sets the default from header and a sender header if necessary.

File

core/lib/Drupal/Core/Mailer/EventSubscriber/OriginatorSubscriber.php, line 88

Class

OriginatorSubscriber
Message subscriber which sets the from and sender headers.

Namespace

Drupal\Core\Mailer\EventSubscriber

Code

protected function removeRedundantSender(Email $message) : void {
  $from = $message->getFrom();
  $sender = $message->getSender();
  $senderRedundant = count($from) === 1 && $sender !== NULL && $from[0]->getAddress() === $sender->getAddress();
  if ($senderRedundant) {
    $message->getHeaders()
      ->remove('Sender');
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.