|
1 <?php |
|
2 |
|
3 /* |
|
4 * This file is part of SwiftMailer. |
|
5 * (c) 2004-2009 Chris Corbyn |
|
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 /** |
|
13 * Does real time reporting of pass/fail for each recipient. |
|
14 * @package Swift |
|
15 * @subpackage Plugins |
|
16 * @author Chris Corbyn |
|
17 */ |
|
18 class Swift_Plugins_ReporterPlugin |
|
19 implements Swift_Events_SendListener |
|
20 { |
|
21 |
|
22 /** |
|
23 * The reporter backend which takes notifications. |
|
24 * @var Swift_Plugin_Reporter |
|
25 * @access private |
|
26 */ |
|
27 private $_reporter; |
|
28 |
|
29 /** |
|
30 * Create a new ReporterPlugin using $reporter. |
|
31 * @param Swift_Plugins_Reporter $reporter |
|
32 */ |
|
33 public function __construct(Swift_Plugins_Reporter $reporter) |
|
34 { |
|
35 $this->_reporter = $reporter; |
|
36 } |
|
37 |
|
38 /** |
|
39 * Not used. |
|
40 */ |
|
41 public function beforeSendPerformed(Swift_Events_SendEvent $evt) |
|
42 { |
|
43 } |
|
44 |
|
45 /** |
|
46 * Invoked immediately after the Message is sent. |
|
47 * @param Swift_Events_SendEvent $evt |
|
48 */ |
|
49 public function sendPerformed(Swift_Events_SendEvent $evt) |
|
50 { |
|
51 $message = $evt->getMessage(); |
|
52 $failures = array_flip($evt->getFailedRecipients()); |
|
53 foreach ((array) $message->getTo() as $address => $null) |
|
54 { |
|
55 $this->_reporter->notify( |
|
56 $message, $address, (array_key_exists($address, $failures) |
|
57 ? Swift_Plugins_Reporter::RESULT_FAIL |
|
58 : Swift_Plugins_Reporter::RESULT_PASS) |
|
59 ); |
|
60 } |
|
61 foreach ((array) $message->getCc() as $address => $null) |
|
62 { |
|
63 $this->_reporter->notify( |
|
64 $message, $address, (array_key_exists($address, $failures) |
|
65 ? Swift_Plugins_Reporter::RESULT_FAIL |
|
66 : Swift_Plugins_Reporter::RESULT_PASS) |
|
67 ); |
|
68 } |
|
69 foreach ((array) $message->getBcc() as $address => $null) |
|
70 { |
|
71 $this->_reporter->notify( |
|
72 $message, $address, (array_key_exists($address, $failures) |
|
73 ? Swift_Plugins_Reporter::RESULT_FAIL |
|
74 : Swift_Plugins_Reporter::RESULT_PASS) |
|
75 ); |
|
76 } |
|
77 } |
|
78 |
|
79 } |