Author: Chris Corbyn
Inheritance: extends Swift_Events_EventObject
 public function testBeforeSendPerformedWithInvalidMessage()
 {
     $this->event = $this->getMockBuilder(\Swift_Events_SendEvent::class)->disableOriginalConstructor()->getMock();
     $this->event->expects($this->any())->method('getMessage')->will($this->returnValue(new \stdClass()));
     $this->message->expects($this->never())->method('attachSigner');
     $this->plugin->beforeSendPerformed($this->event);
 }
Example #2
0
 /**
  * @param \Swift_Events_SendEvent $evt
  */
 public function beforeSendPerformed(\Swift_Events_SendEvent $evt)
 {
     $message = $evt->getMessage();
     $this->convert($message);
     $children = $message->getChildren();
     array_walk($children, array($this, 'convert'));
 }
Example #3
0
 /**
  * Part of the interface which is notified when a message has been sent.
  * @param Swift_Events_SendEvent
  */
 public function sendPerformed(Swift_Events_SendEvent $e)
 {
     $recipients = $e->getRecipients();
     $failed = $e->getFailedRecipients();
     $it = $recipients->getIterator("to");
     while ($it->hasNext()) {
         $it->next();
         $address = $it->getValue();
         $pass = !in_array($address->getAddress(), $failed);
         $this->getView()->paintResult($address->getAddress(), $pass);
     }
     $it = $recipients->getIterator("cc");
     while ($it->hasNext()) {
         $it->next();
         $address = $it->getValue();
         $pass = !in_array($address->getAddress(), $failed);
         $this->getView()->paintResult($address->getAddress(), $pass);
     }
     $it = $recipients->getIterator("bcc");
     while ($it->hasNext()) {
         $it->next();
         $address = $it->getValue();
         $pass = !in_array($address->getAddress(), $failed);
         $this->getView()->paintResult($address->getAddress(), $pass);
     }
 }
  /**
   * Invoked immediately before the Message is sent.
   *
   * @param Swift_Events_SendEvent $evt
   */
  public function beforeSendPerformed(Swift_Events_SendEvent $evt)
  {
    $this->messages[] = $message = clone $evt->getMessage();

    $to = null === $message->getTo() ? '' : implode(', ', array_keys($message->getTo()));

    $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Sending email "%s" to "%s"', $message->getSubject(), $to))));
  }
Example #5
0
 public function sendPerformed(\Swift_Events_SendEvent $event)
 {
     // If this was sent through SES, retrieve the data
     if (config('mail.driver') == 'ses') {
         $message = $event->getMessage();
         $this->updateSesMessageId($message);
     }
 }
 /**
  * Gestion des messages apres leur envoi
  * @param  Swift_Events_SendEvent  $event [description]
  * @return [type]        [description]
  */
 public function sendPerformed(\Swift_Events_SendEvent $evt)
 {
     if ($evt->getResult() === \Swift_Events_SendEvent::RESULT_SUCCESS && $this->enabled == true) {
         // Création de l'activity
         $activity = $this->createActivity($evt->getMessage());
         $this->dm->persist($activity);
         $this->dm->flush();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function beforeSendPerformed(\Swift_Events_SendEvent $event)
 {
     $message = $event->getMessage();
     if (!$this->isEnabled() || !$message instanceof \Swift_Message || in_array($message->getId(), $this->performed)) {
         return;
     }
     $signature = new \Swift_Signers_DKIMSigner($this->getPrivateKey(), $this->domain, $this->selector);
     $message->attachSigner($signature);
     $this->performed[] = $message->getId();
 }
 /**
  * Invoked immediately after the Message is sent.
  *
  * @param Swift_Events_SendEvent $evt
  */
 public function sendPerformed(Swift_Events_SendEvent $evt)
 {
     $message = $evt->getMessage();
     // restore original headers
     $headers = $message->getHeaders();
     if ($headers->has('X-Swift-Return-Path')) {
         $message->setReturnPath($headers->get('X-Swift-Return-Path')->getAddress());
         $headers->removeAll('X-Swift-Return-Path');
     }
 }
 /**
  * @param \Swift_Events_SendEvent $evt
  */
 public function beforeSendPerformed(\Swift_Events_SendEvent $evt)
 {
     $message = $evt->getMessage();
     if ($message->getContentType() === 'text/html' || $message->getContentType() === 'multipart/alternative' && $message->getBody() || $message->getContentType() === 'multipart/mixed' && $message->getBody()) {
         $message->setBody($this->converter->convert($message->getBody(), $this->css));
     }
     foreach ($message->getChildren() as $part) {
         if (strpos($part->getContentType(), 'text/html') === 0) {
             $part->setBody($this->converter->convert($part->getBody(), $this->css));
         }
     }
 }
 /**
  * Invoked immediately after the Message is sent.
  *
  * @param \Swift_Events_SendEvent $evt
  */
 public function sendPerformed(\Swift_Events_SendEvent $evt)
 {
     $result = $evt->getResult();
     $failed_recipients = $evt->getFailedRecipients();
     $message = $evt->getMessage();
     if ($result === \Swift_Events_SendEvent::RESULT_SUCCESS) {
         $level = $this->levels['sendPerformed.SUCCESS'];
     } else {
         $level = $this->levels['sendPerformed.NOT_SUCCESS'];
     }
     $this->log($level, 'MESSAGE (sendPerformed): ', array('result' => $result, 'failed_recipients' => $failed_recipients, 'message' => $message->toString()));
 }
Example #11
0
 /**
  * Inline the CSS before an email is sent.
  *
  * @param \Swift_Events_SendEvent $evt
  */
 public function beforeSendPerformed(\Swift_Events_SendEvent $evt)
 {
     $message = $evt->getMessage();
     $properTypes = ['text/html', 'multipart/alternative', 'multipart/mixed'];
     if ($message->getBody() && in_array($message->getContentType(), $properTypes)) {
         $this->inliner->setHtml($message->getBody());
         $message->setBody($this->inliner->emogrify());
     }
     foreach ($message->getChildren() as $part) {
         if (strpos($part->getContentType(), 'text/html') === 0) {
             $this->inliner->setHtml($part->getBody());
             $message->setBody($this->inliner->emogrify());
         }
     }
 }
 /**
  * @param Swift_Events_SendEvent $evt
  */
 public function beforeSendPerformed(\Swift_Events_SendEvent $evt)
 {
     $message = $evt->getMessage();
     $converter = new CssToInlineStyles();
     $converter->setEncoding($message->getCharset());
     $converter->setUseInlineStylesBlock();
     $converter->setCleanup();
     if ($message->getContentType() === 'text/html' || $message->getContentType() === 'multipart/alternative' && $message->getBody() || $message->getContentType() === 'multipart/mixed' && $message->getBody()) {
         $converter->setHTML($message->getBody());
         $message->setBody($converter->convert());
     }
     foreach ($message->getChildren() as $part) {
         if (strpos($part->getContentType(), 'text/html') === 0) {
             $converter->setHTML($part->getBody());
             $part->setBody($converter->convert());
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function beforeSendPerformed(\Swift_Events_SendEvent $event)
 {
     $message = $event->getMessage();
     if (!$this->isEnabled() || !$message instanceof \Swift_Message || in_array($message->getId(), $this->performed) || null === $message->getBody()) {
         return;
     }
     $dom = new \DOMDocument('1.0', 'utf-8');
     $internalErrors = libxml_use_internal_errors(true);
     $dom->loadHTML($message->getBody());
     libxml_use_internal_errors($internalErrors);
     $xpath = new \DOMXPath($dom);
     $nodes = $xpath->query('//img/@src');
     $images = array();
     foreach ($nodes as $node) {
         $this->embedImage($message, $node, $images);
     }
     $message->setBody($dom->saveHTML(), 'text/html');
     $this->performed[] = $message->getId();
 }
Example #14
0
 /**
  * Swift's SendEvent listener.
  * Invoked when Swift sends a message
  * @param Swift_Events_SendEvent The event information
  * @throws Swift_ConnectionException If the connection cannot be rotated
  */
 public function sendPerformed(Swift_Events_SendEvent $e)
 {
     if (!method_exists($e->getSwift()->connection, "nextConnection")) {
         throw new Swift_ConnectionException("The ConnectionRotator plugin cannot be used with connections other than Swift_Connection_Rotator.");
     }
     if (!$this->called) {
         $this->used[] = $e->getSwift()->connection->getActive();
     }
     $this->count++;
     if ($this->count >= $this->getThreshold()) {
         $e->getSwift()->connection->nextConnection();
         if (!in_array($id = $e->getSwift()->connection->getActive(), $this->used)) {
             $e->getSwift()->connect();
             $this->used[] = $id;
         }
         $this->count = 0;
     }
     $this->called = true;
 }
Example #15
0
 /**
  * Invoked immediately after the Message is sent.
  *
  * @param Swift_Events_SendEvent $evt
  */
 public function sendPerformed(Swift_Events_SendEvent $evt)
 {
     $this->_restoreMessage($evt->getMessage());
 }
Example #16
0
 /**
  * Invoked immediately before the Message is sent.
  *
  * @param Swift_Events_SendEvent $evt
  */
 public function beforeSendPerformed(Swift_Events_SendEvent $evt)
 {
     $this->messages[] = clone $evt->getMessage();
 }
 /**
  * Invoked immediately before the Message is sent.
  *
  * @param \Swift_Events_SendEvent $event
  */
 public function beforeSendPerformed(\Swift_Events_SendEvent $event)
 {
     $event->getMessage()->setFrom($this->address, $this->name);
 }
Example #18
0
 /**
  * Swift's SendEvent listener.
  * Invoked when Swift sends a message
  * @param Swift_Events_SendEvent The event information
  * @throws Swift_ConnectionException If the connection cannot be closed/re-opened
  */
 public function sendPerformed(Swift_Events_SendEvent $e)
 {
     $this->count++;
     if ($this->count >= $this->getThreshold()) {
         $e->getSwift()->disconnect();
         $this->wait($this->getWait());
         $e->getSwift()->connect();
         $this->count = 0;
     }
 }
 /**
  * Invoked immediately after the Message is sent.
  * @param Swift_Events_SendEvent $evt
  */
 public function sendPerformed(Swift_Events_SendEvent $event)
 {
     $this->logger->add(sprintf("Sent Emails, Failed Recipients: ", join(', ', $event->getFailedRecipients())));
 }
Example #20
0
 /**
  * Swift's BeforeSendListener required method.
  * Runs just before Swift sends a message.  Here is where we do all the replacements.
  * @param Swift_Events_SendEvent
  */
 public function beforeSendPerformed(Swift_Events_SendEvent $e)
 {
     $this->message = $e->getMessage();
     foreach ($this->message->listChildren() as $id) {
         $part = $this->message->getChild($id);
         $body = $part->getData();
         if (!is_string($body) || substr(strtolower($part->getContentType()), 0, 5) != "text/") {
             continue;
         }
         foreach ($this->definitions as $tag_name => $def) {
             if ($this->getEmbedRemoteFiles()) {
                 $re = $this->getRemoteFilePattern($tag_name);
                 $body = preg_replace_callback($re, array($this, "embedRemoteFile"), $body);
             }
             if ($this->getEmbedLocalFiles()) {
                 $re = $this->getLocalFilePattern($tag_name);
                 $body = preg_replace_callback($re, array($this, "embedLocalFile"), $body);
             }
         }
         $part->setData($body);
     }
 }
 /**
  * Invoked immediately after the Message is sent.
  *
  * @param \Swift_Events_SendEvent $sendEvent
  */
 public function sendPerformed(\Swift_Events_SendEvent $sendEvent)
 {
     $this->restoreMessage($sendEvent->getMessage());
 }
Example #22
0
 /**
  * Called just before Swift sends a message.
  * We perform operations on the message here.
  * @param Swift_Events_SendEvent The event object for sending a message
  */
 public function beforeSendPerformed(Swift_Events_SendEvent $e)
 {
     $message = $e->getMessage();
     $this->recursiveRestore($message, $this->store);
     //3.3.3 bugfix
     $recipients = $e->getRecipients();
     $to = array_keys($recipients->getTo());
     if (count($to) > 0) {
         $to = $to[0];
     } else {
         return;
     }
     $replacements = (array) $this->replacements->getReplacementsFor($to);
     $this->store = array("headers" => array(), "body" => false, "children" => array());
     $this->recursiveReplace($message, $replacements, $this->store);
 }
Example #23
0
 /**
  * Invoked immediately before the Message is sent.
  * @param Swift_Events_SendEvent $evt
  */
 public function beforeSendPerformed(Swift_Events_SendEvent $evt)
 {
     $evt->cancelBubble();
 }
Example #24
0
 /**
  * Called just after Swift sends a message.
  * We restore the message here.
  * @param Swift_Events_SendEvent The event object for sending a message
  */
 public function sendPerformed(Swift_Events_SendEvent $e)
 {
     $message = $e->getMessage();
     $this->recursiveRestore($message, $this->store);
     $this->store = null;
 }
Example #25
0
 /**
  * Swift's SendEvent listener.
  * Invoked when Swift sends a message
  * @param Swift_Events_SendEvent The event information
  * @throws Swift_ConnectionException If mail() returns false
  */
 public function sendPerformed(Swift_Events_SendEvent $e)
 {
     $message = $e->getMessage();
     $recipients = $e->getRecipients();
     $to = array();
     foreach ($recipients->getTo() as $addr) {
         if ($this->isWindows()) {
             $to[] = substr($addr->build(true), 1, -1);
         } else {
             $to[] = $addr->build();
         }
     }
     $to = implode(", ", $to);
     $bcc_orig = $message->headers->has("Bcc") ? $message->headers->get("Bcc") : null;
     $subject_orig = $message->headers->has("Subject") ? $message->headers->get("Subject") : null;
     $to_orig = $message->headers->has("To") ? $message->headers->get("To") : null;
     $bcc = array();
     foreach ($recipients->getBcc() as $addr) {
         $bcc[] = $addr->build();
     }
     if (!empty($bcc)) {
         $message->headers->set("Bcc", $bcc);
     }
     $bcc = null;
     $body_data = $message->buildData();
     $message_body = $body_data->readFull();
     $subject_enc = $message->headers->has("Subject") ? $message->headers->getEncoded("Subject") : "";
     $message->headers->set("To", null);
     $message->headers->set("Subject", null);
     $sender = $e->getSender();
     $this->returnPath = $sender->build();
     if ($message->headers->has("Return-Path")) {
         $this->returnPath = $message->headers->get("Return-Path");
     }
     if (preg_match("~<([^>]+)>[^>]*\$~", $this->returnPath, $matches)) {
         $this->returnPath = $matches[1];
     }
     $this->doMail($to, $subject_enc, $message_body, $message->headers, sprintf($this->getAdditionalParams(), $this->returnPath));
     $message->setLE($this->oldLE);
     $message->headers->set("To", $to_orig);
     $message->headers->set("Subject", $subject_orig);
     $message->headers->set("Bcc", $bcc_orig);
 }
 /**
  * Apply whitelist and blacklist to "to", "cc" and "bcc"
  *
  * @param Swift_Events_SendEvent $evt
  */
 public function beforeSendPerformed(\Swift_Events_SendEvent $evt)
 {
     $message = $evt->getMessage();
     $modifier = $this->modifier;
     $modifier($message);
 }
 /**
  * Invoked immediately after the Message is sent.
  *
  * @param Swift_Events_SendEvent $evt
  */
 public function sendPerformed(Swift_Events_SendEvent $evt)
 {
     $message = $evt->getMessage();
     $message->toByteStream($this);
 }
 /**
  * {@inheritdoc}
  */
 public function sendPerformed(\Swift_Events_SendEvent $evt)
 {
     $contents = $this->findAll();
     $contents[] = $evt->getMessage();
     file_put_contents($this->filename, serialize($contents));
 }
 /**
  * Invoked immediately after the Message is sent.
  *
  * @param Swift_Events_SendEvent $evt
  */
 public function sendPerformed(Swift_Events_SendEvent $evt)
 {
     ++$this->_counter;
     if ($this->_counter >= $this->_threshold) {
         $transport = $evt->getTransport();
         $transport->stop();
         if ($this->_sleep) {
             $this->sleep($this->_sleep);
         }
         $transport->start();
         $this->_counter = 0;
     }
 }
Example #30
-1
 /**
  * Invoked immediately after the Message is sent.
  * @param Swift_Events_SendEvent $evt
  */
 public function sendPerformed(Swift_Events_SendEvent $evt)
 {
   $message = $evt->getMessage();
   $failures = array_flip($evt->getFailedRecipients());
   foreach ((array) $message->getTo() as $address => $null)
   {
     $this->_reporter->notify(
       $message, $address, (array_key_exists($address, $failures)
       ? Swift_Plugins_Reporter::RESULT_FAIL
       : Swift_Plugins_Reporter::RESULT_PASS)
       );
   }
   foreach ((array) $message->getCc() as $address => $null)
   {
     $this->_reporter->notify(
       $message, $address, (array_key_exists($address, $failures)
       ? Swift_Plugins_Reporter::RESULT_FAIL
       : Swift_Plugins_Reporter::RESULT_PASS)
       );
   }
   foreach ((array) $message->getBcc() as $address => $null)
   {
     $this->_reporter->notify(
       $message, $address, (array_key_exists($address, $failures)
       ? Swift_Plugins_Reporter::RESULT_FAIL
       : Swift_Plugins_Reporter::RESULT_PASS)
       );
   }
 }