diff --git a/lib/classes/Swift/MemorySpool.php b/lib/classes/Swift/MemorySpool.php index 5b239694d..2cafb6751 100644 --- a/lib/classes/Swift/MemorySpool.php +++ b/lib/classes/Swift/MemorySpool.php @@ -16,6 +16,7 @@ class Swift_MemorySpool implements Swift_Spool { protected $messages = array(); + private $flushRetries = 3; /** * Tests if this Transport mechanism has started. @@ -41,6 +42,14 @@ public function stop() { } + /** + * @param int $retries + */ + public function setFlushRetries($retries) + { + $this->flushRetries = $retries; + } + /** * Stores a message in the queue. * @@ -75,8 +84,25 @@ public function flushQueue(Swift_Transport $transport, &$failedRecipients = null } $count = 0; - while ($message = array_pop($this->messages)) { - $count += $transport->send($message, $failedRecipients); + $retries = $this->flushRetries; + while ($retries--) { + try { + while ($message = array_pop($this->messages)) { + $count += $transport->send($message, $failedRecipients); + } + } catch (Swift_TransportException $exception) { + if ($retries) { + // re-queue the message at the end of the queue to give a chance + // to the other messages to be sent, in case the failure was due to + // this message and not just the transport failing + array_unshift($this->messages, $message); + + // wait half a second before we try again + usleep(500000); + } else { + throw $exception; + } + } } return $count;