[ Index ]

MailPress 7.2

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/composer/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Plugins/ -> ImpersonatePlugin.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of SwiftMailer.
   5   * (c) 2009 Fabien Potencier
   6   *
   7   * For the full copyright and license information, please view the LICENSE
   8   * file that was distributed with this source code.
   9   */
  10  
  11  /**
  12   * Replaces the sender of a message.
  13   *
  14   * @author Arjen Brouwer
  15   */
  16  class Swift_Plugins_ImpersonatePlugin implements Swift_Events_SendListener
  17  {
  18      /**
  19       * The sender to impersonate.
  20       *
  21       * @var string
  22       */
  23      private $sender;
  24  
  25      /**
  26       * Create a new ImpersonatePlugin to impersonate $sender.
  27       *
  28       * @param string $sender address
  29       */
  30      public function __construct($sender)
  31      {
  32          $this->sender = $sender;
  33      }
  34  
  35      /**
  36       * Invoked immediately before the Message is sent.
  37       */
  38      public function beforeSendPerformed(Swift_Events_SendEvent $evt)
  39      {
  40          $message = $evt->getMessage();
  41          $headers = $message->getHeaders();
  42  
  43          // save current recipients
  44          $headers->addPathHeader('X-Swift-Return-Path', $message->getReturnPath());
  45  
  46          // replace them with the one to send to
  47          $message->setReturnPath($this->sender);
  48      }
  49  
  50      /**
  51       * Invoked immediately after the Message is sent.
  52       */
  53      public function sendPerformed(Swift_Events_SendEvent $evt)
  54      {
  55          $message = $evt->getMessage();
  56  
  57          // restore original headers
  58          $headers = $message->getHeaders();
  59  
  60          if ($headers->has('X-Swift-Return-Path')) {
  61              $message->setReturnPath($headers->get('X-Swift-Return-Path')->getAddress());
  62              $headers->removeAll('X-Swift-Return-Path');
  63          }
  64      }
  65  }


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1