TYPO3  7.6
ImpersonatePlugin.php
Go to the documentation of this file.
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 
17 {
23  private $_sender;
24 
30  public function __construct($sender)
31  {
32  $this->_sender = $sender;
33  }
34 
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 
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 }