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:----M19NAukotXBdAy+YRsIYHbKjdIuZjTqpEjmWp5Unfj1lqDRuyGIoTULG2K8U3TXk4vbLX6vNgvb7tibonFWSZyxCpwxMj7X3pi3rDMD7TAiFIHlhVEVequmZpMkWwbu1hiJVEK3kCULdU6E6eKZSdxabUmBMTLxYM5fg59Da7ENAstmmelhIEA+Oun/qylYlPR3xbeMYHShrmPxp3z17DfUw58El6XFM9Ry8GRhdesWuV3tQYXyUFfInTuiHEO2kHuz1laJ5x15nYTeEpAKzmM0osaXjpQ392pC3znyQQkFH+17KfacRKDOe+Uo+rx3cl5VgmJ3kyBxt5FEu5MXdTNgpEbzh0+6gFMxrNLjK1E0yZFXL40tu8y41BP25VMhTG/z8wVGx0PFijR7PChja1JZy1C3ood+fTrew9rqYNSwc8G68qLvR8+bEP+k5OXP85G0rpPTD5XqjoRxOU2idgYlG0B+lo8dZk5Sni6nkq8AN3Bkm/r3VWOonQU990yK/uDahYueMBR6vMJQMckpk/FPP1QLXHpH1FGUXBMc3sEhdMyQ+2tcFsvCuCjUgWoTPpVVS4Og578T2JVOlbKAKerhSGhhYwz7ep/ZHjObcrow4uAjs1OAR+gdU9poo9HxnvqwNTsOsKESZtqQwSJS0BPOpCDlQ+618EkNd4o4eQj8=----ATTACHMENT:----MzM0OTIyODkxNDk3MzEyOSAyOTQ2MzQwMDQ2NjkwNzE2IDk1ODU3MjcyNzAwNjExMDk=