[ Index ]

MailPress 544

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

title

Body

[close]

/mp-includes/Swiftmailer/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       * @param Swift_Events_SendEvent $evt
  39       */
  40      public function beforeSendPerformed(Swift_Events_SendEvent $evt)
  41      {
  42          $message = $evt->getMessage();
  43          $headers = $message->getHeaders();
  44  
  45          // save current recipients
  46          $headers->addPathHeader('X-Swift-Return-Path', $message->getReturnPath());
  47  
  48          // replace them with the one to send to
  49          $message->setReturnPath($this->_sender);
  50      }
  51  
  52      /**
  53       * Invoked immediately after the Message is sent.
  54       *
  55       * @param Swift_Events_SendEvent $evt
  56       */
  57      public function sendPerformed(Swift_Events_SendEvent $evt)
  58      {
  59          $message = $evt->getMessage();
  60  
  61          // restore original headers
  62          $headers = $message->getHeaders();
  63  
  64          if ($headers->has('X-Swift-Return-Path')) {
  65              $message->setReturnPath($headers->get('X-Swift-Return-Path')->getAddress());
  66              $headers->removeAll('X-Swift-Return-Path');
  67          }
  68      }
  69  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1