[ Index ]

MailPress 7.2

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/composer/vendor/swiftmailer/swiftmailer/lib/classes/Swift/ -> MemorySpool.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of SwiftMailer.
   5   * (c) 2011 Fabien Potencier <fabien.potencier@gmail.com>
   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   * Stores Messages in memory.
  13   *
  14   * @author Fabien Potencier
  15   */
  16  class Swift_MemorySpool implements Swift_Spool
  17  {
  18      protected $messages = [];
  19      private $flushRetries = 3;
  20  
  21      /**
  22       * Tests if this Transport mechanism has started.
  23       *
  24       * @return bool
  25       */
  26      public function isStarted()
  27      {
  28          return true;
  29      }
  30  
  31      /**
  32       * Starts this Transport mechanism.
  33       */
  34      public function start()
  35      {
  36      }
  37  
  38      /**
  39       * Stops this Transport mechanism.
  40       */
  41      public function stop()
  42      {
  43      }
  44  
  45      /**
  46       * @param int $retries
  47       */
  48      public function setFlushRetries($retries)
  49      {
  50          $this->flushRetries = $retries;
  51      }
  52  
  53      /**
  54       * Stores a message in the queue.
  55       *
  56       * @param Swift_Mime_SimpleMessage $message The message to store
  57       *
  58       * @return bool Whether the operation has succeeded
  59       */
  60      public function queueMessage(Swift_Mime_SimpleMessage $message)
  61      {
  62          //clone the message to make sure it is not changed while in the queue
  63          $this->messages[] = clone $message;
  64  
  65          return true;
  66      }
  67  
  68      /**
  69       * Sends messages using the given transport instance.
  70       *
  71       * @param Swift_Transport $transport        A transport instance
  72       * @param string[]        $failedRecipients An array of failures by-reference
  73       *
  74       * @return int The number of sent emails
  75       */
  76      public function flushQueue(Swift_Transport $transport, &$failedRecipients = null)
  77      {
  78          if (!$this->messages) {
  79              return 0;
  80          }
  81  
  82          if (!$transport->isStarted()) {
  83              $transport->start();
  84          }
  85  
  86          $count = 0;
  87          $retries = $this->flushRetries;
  88          while ($retries--) {
  89              try {
  90                  while ($message = array_pop($this->messages)) {
  91                      $count += $transport->send($message, $failedRecipients);
  92                  }
  93              } catch (Swift_TransportException $exception) {
  94                  if ($retries) {
  95                      // re-queue the message at the end of the queue to give a chance
  96                      // to the other messages to be sent, in case the failure was due to
  97                      // this message and not just the transport failing
  98                      array_unshift($this->messages, $message);
  99  
 100                      // wait half a second before we try again
 101                      usleep(500000);
 102                  } else {
 103                      throw $exception;
 104                  }
 105              }
 106          }
 107  
 108          return $count;
 109      }
 110  }


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1