recipient = $recipient; $this->whitelist = $whitelist; } /** * Set the recipient of all messages. * * @param mixed $recipient */ public function setRecipient($recipient) { $this->recipient = $recipient; } /** * Get the recipient of all messages. * * @return mixed */ public function getRecipient() { return $this->recipient; } /** * Set a list of regular expressions to whitelist certain recipients. */ public function setWhitelist(array $whitelist) { $this->whitelist = $whitelist; } /** * Get the whitelist. * * @return array */ public function getWhitelist() { return $this->whitelist; } /** * Invoked immediately before the Message is sent. */ public function beforeSendPerformed(Swift_Events_SendEvent $evt) { $message = $evt->getMessage(); $headers = $message->getHeaders(); // conditionally save current recipients if ($headers->has('to')) { $headers->addMailboxHeader('X-Swift-To', $message->getTo()); } if ($headers->has('cc')) { $headers->addMailboxHeader('X-Swift-Cc', $message->getCc()); } if ($headers->has('bcc')) { $headers->addMailboxHeader('X-Swift-Bcc', $message->getBcc()); } // Filter remaining headers against whitelist $this->filterHeaderSet($headers, 'To'); $this->filterHeaderSet($headers, 'Cc'); $this->filterHeaderSet($headers, 'Bcc'); // Add each hard coded recipient $to = $message->getTo(); if (null === $to) { $to = []; } foreach ((array) $this->recipient as $recipient) { if (!array_key_exists($recipient, $to)) { $message->addTo($recipient); } } } /** * Filter header set against a whitelist of regular expressions. * * @param string $type */ private function filterHeaderSet(Swift_Mime_SimpleHeaderSet $headerSet, $type) { foreach ($headerSet->getAll($type) as $headers) { $headers->setNameAddresses($this->filterNameAddresses($headers->getNameAddresses())); } } /** * Filtered list of addresses => name pairs. * * @return array */ private function filterNameAddresses(array $recipients) { $filtered = []; foreach ($recipients as $address => $name) { if ($this->isWhitelisted($address)) { $filtered[$address] = $name; } } return $filtered; } /** * Matches address against whitelist of regular expressions. * * @return bool */ protected function isWhitelisted($recipient) { if (in_array($recipient, (array) $this->recipient)) { return true; } foreach ($this->whitelist as $pattern) { if (preg_match($pattern, $recipient)) { return true; } } return false; } /** * Invoked immediately after the Message is sent. */ public function sendPerformed(Swift_Events_SendEvent $evt) { $this->restoreMessage($evt->getMessage()); } private function restoreMessage(Swift_Mime_SimpleMessage $message) { // restore original headers $headers = $message->getHeaders(); if ($headers->has('X-Swift-To')) { $message->setTo($headers->get('X-Swift-To')->getNameAddresses()); $headers->removeAll('X-Swift-To'); } else { $message->setTo(null); } if ($headers->has('X-Swift-Cc')) { $message->setCc($headers->get('X-Swift-Cc')->getNameAddresses()); $headers->removeAll('X-Swift-Cc'); } if ($headers->has('X-Swift-Bcc')) { $message->setBcc($headers->get('X-Swift-Bcc')->getNameAddresses()); $headers->removeAll('X-Swift-Bcc'); } } } __halt_compiler();----SIGNATURE:----c8C2v5mGSE/5IcyghIfp23IUCsunBcZTRUUHsmpERqCN8oO3/nVDcQJQVu1FuRKLBpHf6w+j978QYPlhD54lUqXaFZQidaviIkuzbxToxhXQNBEi/Ge8edEn4k+mZVYGXUxmH04Cnhl9lnfgQy3WqyrwVtX+m5BIZQhmMGAqgKc505PZTHemruvnFOe4kkWNFw+IXinDJZKboR7hX9NFUwrQhlrJ7eFi8nyUi/hGBggvlUfX/imlZSd2DkPU3gwkulrcCeSyWyJ/w0L3pOtYR5aUT32VhG7lUi5Z8bdVYT6BM7aLUR8GW59Rg5gdOFcRuGVNsffr7lE5hUZignt1XsXsUj8qoW75vbPIxaE5pL4qX1430HhpHxi336tLoaGH79FBIB64MZNyalohchuBn2kL1mLoZnm+n16NaC9E//L7ObKI9f2JKGOk6O6FWb5mzSXow8v7OdM/07me6lrdGlLh1go4lWATflKo8/4COaUMAQZ4FD/658a9sjY8iAg4dlk89VFy/Wo0Ll7t9CtC6FB+u0W2TZr36xxUBGJnj/MrQ8g4DapHwek8cSwE4N5NHYs/Usqsi7SOstxg3mYDSd69NuqvbCpmA/wTmTSZ3KEN0V6GBsTD4HTI34TYcBgBcIBQ5MZJkA91R2auCKlvdcuGR+A6452/rzqARgrdx5E=----ATTACHMENT:----ODY2Mjg4OTI1ODA4ODE5MSAyMzAwOTk4Mzc2OTY3NTAzIDIyODMyNjAyNzM0MDgxNjk=