ReporterPlugin.php 1.9KB

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