ReporterPlugin.php 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 implements Swift_Events_SendListener
  16. {
  17. /**
  18. * The reporter backend which takes notifications.
  19. * @var Swift_Plugin_Reporter
  20. * @access private
  21. */
  22. private $_reporter;
  23. /**
  24. * Create a new ReporterPlugin using $reporter.
  25. * @param Swift_Plugins_Reporter $reporter
  26. */
  27. public function __construct(Swift_Plugins_Reporter $reporter)
  28. {
  29. $this->_reporter = $reporter;
  30. }
  31. /**
  32. * Not used.
  33. */
  34. public function beforeSendPerformed(Swift_Events_SendEvent $evt)
  35. {
  36. }
  37. /**
  38. * Invoked immediately after the Message is sent.
  39. * @param Swift_Events_SendEvent $evt
  40. */
  41. public function sendPerformed(Swift_Events_SendEvent $evt)
  42. {
  43. $message = $evt->getMessage();
  44. $failures = array_flip($evt->getFailedRecipients());
  45. foreach ((array) $message->getTo() as $address => $null) {
  46. $this->_reporter->notify(
  47. $message, $address, (array_key_exists($address, $failures)
  48. ? Swift_Plugins_Reporter::RESULT_FAIL
  49. : Swift_Plugins_Reporter::RESULT_PASS)
  50. );
  51. }
  52. foreach ((array) $message->getCc() as $address => $null) {
  53. $this->_reporter->notify(
  54. $message, $address, (array_key_exists($address, $failures)
  55. ? Swift_Plugins_Reporter::RESULT_FAIL
  56. : Swift_Plugins_Reporter::RESULT_PASS)
  57. );
  58. }
  59. foreach ((array) $message->getBcc() as $address => $null) {
  60. $this->_reporter->notify(
  61. $message, $address, (array_key_exists($address, $failures)
  62. ? Swift_Plugins_Reporter::RESULT_FAIL
  63. : Swift_Plugins_Reporter::RESULT_PASS)
  64. );
  65. }
  66. }
  67. }