1<?php
2
3/**
4 * Swift Mailer Verbose Sending Plugin.
5 * Please read the LICENSE file
6 * @author Chris Corbyn <chris@w3style.co.uk>
7 * @package Swift_Plugin
8 * @subpackage VerboseSending
9 * @license GNU Lesser General Public License
10 */
11
12require_once dirname(__FILE__) . "/../ClassLoader.php";
13Swift_ClassLoader::load("Swift_Events_SendListener");
14Swift_ClassLoader::load("Swift_Plugin_VerboseSending_DefaultView");
15
16/**
17 * Verbose Sending plugin for Swift Mailer.
18 * Displays "pass" or "fail" messages in realtime as the messages are sent.
19 * @package Swift_Plugin
20 * @subpackage VerboseSending
21 * @author Chris Corbyn <chris@w3style.co.uk>
22 */
23class Swift_Plugin_VerboseSending implements Swift_Events_SendListener
24{
25  /**
26   * The view layer which displays the results.
27   * @var Swift_Plugin_VerboseSending_AbstractView
28   */
29  protected $view;
30
31  /**
32   * Ctor.
33   * @param Swift_Plugin_VerboseSending_AbstractView The view object to display the result
34   */
35  public function __construct(Swift_Plugin_VerboseSending_AbstractView $view)
36  {
37    $this->setView($view);
38  }
39  /**
40   * Part of the interface which is notified when a message has been sent.
41   * @param Swift_Events_SendEvent
42   */
43  public function sendPerformed(Swift_Events_SendEvent $e)
44  {
45    $recipients = $e->getRecipients();
46    $failed = $e->getFailedRecipients();
47    $it = $recipients->getIterator("to");
48    while ($it->hasNext())
49    {
50      $it->next();
51      $address = $it->getValue();
52      $pass = !in_array($address->getAddress(), $failed);
53      $this->getView()->paintResult($address->getAddress(), $pass);
54    }
55    $it = $recipients->getIterator("cc");
56    while ($it->hasNext())
57    {
58      $it->next();
59      $address = $it->getValue();
60      $pass = !in_array($address->getAddress(), $failed);
61      $this->getView()->paintResult($address->getAddress(), $pass);
62    }
63    $it = $recipients->getIterator("bcc");
64    while ($it->hasNext())
65    {
66      $it->next();
67      $address = $it->getValue();
68      $pass = !in_array($address->getAddress(), $failed);
69      $this->getView()->paintResult($address->getAddress(), $pass);
70    }
71  }
72  /**
73   * Set the View component to display results.
74   * @param Swift_Plugin_VerboseSending_AbstractView The view object to display the result
75   */
76  public function setView(Swift_Plugin_VerboseSending_AbstractView $view)
77  {
78    $this->view = $view;
79  }
80  /**
81   * Get the View component.
82   * @return Swift_Plugin_VerboseSending_AbstractView
83   */
84  public function getView()
85  {
86    return $this->view;
87  }
88}
89