Commit 4ad8b85f authored by Adam Shepherd's avatar Adam Shepherd
Browse files

Issue #3276863 by AdamPS: Calculate langcode and account from to address

parent 8bdd0fab
Loading
Loading
Loading
Loading
+4 −15
Changes for modules/symfony_mailer_bc/src/MailManagerReplacement.php: 4 added lines, 15 removed lines.
Original line number Diff line number Diff line
@@ -118,12 +118,9 @@ class MailManagerReplacement extends MailManager {
   *   The email to fill.
   * @param array $message
   *   The array to fill from.
   * @param array $original
   *   (Optional) The original message array.
   */
  public function emailFromArray(EmailInterface $email, array $message, array $original = []) {
    $email->setLangcode($message['langcode'])
      ->setSubject($message['subject']);
  public function emailFromArray(EmailInterface $email, array $message) {
    $email->setSubject($message['subject']);

    if ($email->getPhase() == EmailInterface::PHASE_INIT) {
      $email->setParams($message['params']);
@@ -132,17 +129,9 @@ class MailManagerReplacement extends MailManager {
    // Address headers.
    $headers = $email->getHeaders();
    foreach (self::HEADERS as $name => $key) {
      // If the header hasn't change then no need to parse it.
      $encoded = $message['headers'][$name] ?? $message[$key] ?? NULL;
      $encoded_original = $original['headers'][$name] ?? $original[$key] ?? NULL;
      if (isset($encoded) && ($encoded != $encoded_original)) {
        $addresses = $this->mailerHelper->parseAddress($encoded);
        if ($header = $headers->get($name)) {
          $header->setAddresses($addresses);
        }
        else {
          $headers->addMailboxListHeader($name, $addresses);
        }
      if (isset($encoded)) {
        $email->setAddress($name, $this->mailerHelper->parseAddress($encoded, $message['langcode']));
      }
    }

+1 −2
Changes for modules/symfony_mailer_bc/src/Plugin/EmailBuilder/ContactEmailBuilder.php: 1 added line, 2 removed lines.
Original line number Diff line number Diff line
@@ -71,8 +71,7 @@ class ContactEmailBuilder extends ContactEmailBuilderBase {
      ->setVariable('recipient_edit_url', $recipient->toUrl('edit-form')->toString());

    if ($email->getSubType() == 'mail') {
      // Set the account from the recipient.
      $email->setAccount($recipient);
      $email->setTo($recipient);
    }
  }

+2 −4
Changes for modules/symfony_mailer_bc/src/Plugin/EmailBuilder/ContactEmailBuilderBase.php: 2 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -20,8 +20,6 @@ class ContactEmailBuilderBase extends EmailBuilderBase {
    $sender = $email->getParam('sender');
    $contact_message = $email->getParam('contact_message');

    // The contact entity cannot contain private information so we don't need
    // to switch account for rendering it.
    $email->appendBodyEntity($contact_message, 'mail')
      ->addLibrary('symfony_mailer_bc/contact')
      ->setVariable('subject', $contact_message->getSubject())
@@ -30,10 +28,10 @@ class ContactEmailBuilderBase extends EmailBuilderBase {
      ->setVariable('sender_url', $sender->isAuthenticated() ? $sender->toUrl('canonical')->toString() : Url::fromUri('mailto:' . $sender->getEmail()));

    if ($email->getSubType() == 'mail') {
      $email->setReplyTo($sender->getEmail());
      $email->setReplyTo($sender);
    }
    else {
      $email->setAccount($sender);
      $email->setTo($sender);
    }
  }

+0 −4
Changes for modules/symfony_mailer_bc/src/Plugin/EmailBuilder/ContactPageEmailBuilder.php: 0 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -56,10 +56,6 @@ class ContactPageEmailBuilder extends ContactEmailBuilderBase {
    $email->setVariable('form', $email->getEntity()->label())
      ->setVariable('form_url', Url::fromRoute('<current>')->toString());

    if ($email->getSubType() == 'mail') {
      // Set the account from the recipient to set langcode.
      $email->setAccount();
    }
    if ($email->getSubType() == 'autoreply') {
      $email->setBody($email->getEntity()->getReply());
    }
+1 −16
Changes for modules/symfony_mailer_bc/src/Plugin/EmailBuilder/SimplenewsEmailBuilder.php: 1 added line, 16 removed lines.
Original line number Diff line number Diff line
@@ -6,9 +6,6 @@ use Drupal\simplenews\SubscriberInterface;
use Drupal\symfony_mailer\EmailFactoryInterface;
use Drupal\symfony_mailer\EmailInterface;
use Drupal\symfony_mailer\Entity\MailerPolicy;
use Drupal\symfony_mailer\MailerHelperTrait;
use Drupal\symfony_mailer\Processor\EmailBuilderBase;
use Drupal\symfony_mailer\Processor\TokenProcessorTrait;

/**
 * Defines the Email Builder plug-in for simplenews module.
@@ -24,10 +21,7 @@ use Drupal\symfony_mailer\Processor\TokenProcessorTrait;
 *   import_warning = @Translation("This overrides the default HTML messages with imported plain text versions."),
 * )
 */
class SimplenewsEmailBuilder extends EmailBuilderBase {

  use MailerHelperTrait;
  use TokenProcessorTrait;
class SimplenewsEmailBuilder extends SimplenewsEmailBuilderBase {

  /**
   * Saves the parameters for a newly created email.
@@ -55,15 +49,6 @@ class SimplenewsEmailBuilder extends EmailBuilderBase {
    return $factory->newModuleEmail('simplenews', $key, $params['context']['simplenews_subscriber']);
  }

  /**
   * {@inheritdoc}
   */
  public function build(EmailInterface $email) {
    $subscriber = $email->getParam('simplenews_subscriber');
    $email->setTo($subscriber->getMail())
      ->setLangcode($subscriber->getLangcode());
  }

  /**
   * {@inheritdoc}
   */
Loading