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 * Does real time reporting of pass/fail for each recipient. 13 * 14 * @author Chris Corbyn 15 */ 16class Swift_Plugins_ReporterPlugin implements Swift_Events_SendListener 17{ 18 /** 19 * The reporter backend which takes notifications. 20 * 21 * @var Swift_Plugins_Reporter 22 */ 23 private $reporter; 24 25 /** 26 * Create a new ReporterPlugin using $reporter. 27 */ 28 public function __construct(Swift_Plugins_Reporter $reporter) 29 { 30 $this->reporter = $reporter; 31 } 32 33 /** 34 * Not used. 35 */ 36 public function beforeSendPerformed(Swift_Events_SendEvent $evt) 37 { 38 } 39 40 /** 41 * Invoked immediately after the Message is sent. 42 */ 43 public function sendPerformed(Swift_Events_SendEvent $evt) 44 { 45 $message = $evt->getMessage(); 46 $failures = array_flip($evt->getFailedRecipients()); 47 foreach ((array) $message->getTo() as $address => $null) { 48 $this->reporter->notify($message, $address, (\array_key_exists($address, $failures) ? Swift_Plugins_Reporter::RESULT_FAIL : Swift_Plugins_Reporter::RESULT_PASS)); 49 } 50 foreach ((array) $message->getCc() as $address => $null) { 51 $this->reporter->notify($message, $address, (\array_key_exists($address, $failures) ? Swift_Plugins_Reporter::RESULT_FAIL : Swift_Plugins_Reporter::RESULT_PASS)); 52 } 53 foreach ((array) $message->getBcc() as $address => $null) { 54 $this->reporter->notify($message, $address, (\array_key_exists($address, $failures) ? Swift_Plugins_Reporter::RESULT_FAIL : Swift_Plugins_Reporter::RESULT_PASS)); 55 } 56 } 57} 58