1: <?php
2:
3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14: 15: 16:
17: class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener
18: {
19: 20: 21: 22: 23:
24: private $_recipient;
25:
26: 27: 28: 29:
30: public function __construct($recipient)
31: {
32: $this->_recipient = $recipient;
33: }
34:
35: 36: 37: 38:
39: public function setRecipient($recipient)
40: {
41: $this->_recipient = $recipient;
42: }
43:
44: 45: 46: 47:
48: public function getRecipient()
49: {
50: return $this->_recipient;
51: }
52:
53: 54: 55: 56:
57: public function beforeSendPerformed(Swift_Events_SendEvent $evt)
58: {
59: $message = $evt->getMessage();
60: $headers = $message->getHeaders();
61:
62:
63: $headers->addMailboxHeader('X-Swift-To', $message->getTo());
64: $headers->addMailboxHeader('X-Swift-Cc', $message->getCc());
65: $headers->addMailboxHeader('X-Swift-Bcc', $message->getBcc());
66:
67:
68: $message->setTo($this->_recipient);
69: $headers->removeAll('Cc');
70: $headers->removeAll('Bcc');
71: }
72:
73: 74: 75: 76: 77:
78: public function sendPerformed(Swift_Events_SendEvent $evt)
79: {
80: $this->_restoreMessage($evt->getMessage());
81: }
82:
83:
84:
85: private function _restoreMessage(Swift_Mime_Message $message)
86: {
87:
88: $headers = $message->getHeaders();
89:
90: if ($headers->has('X-Swift-To')) {
91: $message->setTo($headers->get('X-Swift-To')->getNameAddresses());
92: $headers->removeAll('X-Swift-To');
93: }
94:
95: if ($headers->has('X-Swift-Cc')) {
96: $message->setCc($headers->get('X-Swift-Cc')->getNameAddresses());
97: $headers->removeAll('X-Swift-Cc');
98: }
99:
100: if ($headers->has('X-Swift-Bcc')) {
101: $message->setBcc($headers->get('X-Swift-Bcc')->getNameAddresses());
102: $headers->removeAll('X-Swift-Bcc');
103: }
104: }
105: }
106: