ReporterPlugin.php 2.1 KB

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. *
  12. * @author Chris Corbyn
  13. */
  14. class Swift_Plugins_ReporterPlugin implements Swift_Events_SendListener
  15. {
  16. /**
  17. * The reporter backend which takes notifications.
  18. *
  19. * @var Swift_Plugins_Reporter
  20. */
  21. private $_reporter;
  22. /**
  23. * Create a new ReporterPlugin using $reporter.
  24. *
  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. *
  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. $this->_reporter->notify(
  48. $message, $address, (array_key_exists($address, $failures)
  49. ? Swift_Plugins_Reporter::RESULT_FAIL
  50. : Swift_Plugins_Reporter::RESULT_PASS)
  51. );
  52. }
  53. foreach ((array) $message->getCc() as $address => $null) {
  54. $this->_reporter->notify(
  55. $message, $address, (array_key_exists($address, $failures)
  56. ? Swift_Plugins_Reporter::RESULT_FAIL
  57. : Swift_Plugins_Reporter::RESULT_PASS)
  58. );
  59. }
  60. foreach ((array) $message->getBcc() as $address => $null) {
  61. $this->_reporter->notify(
  62. $message, $address, (array_key_exists($address, $failures)
  63. ? Swift_Plugins_Reporter::RESULT_FAIL
  64. : Swift_Plugins_Reporter::RESULT_PASS)
  65. );
  66. }
  67. }
  68. }