From 07f5140771388c9e0c8a99b0dd2e5d950bdb173b Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 14 Oct 2021 15:16:42 +1100 Subject: moving h-source subdir out. --- .../lib/classes/Swift/Plugins/AntiFloodPlugin.php | 147 +++++++++++ .../Swift/Plugins/BandwidthMonitorPlugin.php | 173 +++++++++++++ .../Swift/Plugins/Decorator/Replacements.php | 36 +++ .../lib/classes/Swift/Plugins/DecoratorPlugin.php | 201 ++++++++++++++ .../lib/classes/Swift/Plugins/Logger.php | 37 +++ .../lib/classes/Swift/Plugins/LoggerPlugin.php | 160 ++++++++++++ .../classes/Swift/Plugins/Loggers/ArrayLogger.php | 73 ++++++ .../classes/Swift/Plugins/Loggers/EchoLogger.php | 64 +++++ .../classes/Swift/Plugins/Pop/Pop3Connection.php | 36 +++ .../classes/Swift/Plugins/Pop/Pop3Exception.php | 34 +++ .../classes/Swift/Plugins/PopBeforeSmtpPlugin.php | 288 +++++++++++++++++++++ .../lib/classes/Swift/Plugins/Reporter.php | 36 +++ .../lib/classes/Swift/Plugins/ReporterPlugin.php | 82 ++++++ .../Swift/Plugins/Reporters/HitReporter.php | 63 +++++ .../Swift/Plugins/Reporters/HtmlReporter.php | 47 ++++ .../lib/classes/Swift/Plugins/Sleeper.php | 26 ++ .../lib/classes/Swift/Plugins/ThrottlerPlugin.php | 188 ++++++++++++++ .../lib/classes/Swift/Plugins/Timer.php | 26 ++ 18 files changed, 1717 insertions(+) create mode 100755 External/swiftmailer/lib/classes/Swift/Plugins/AntiFloodPlugin.php create mode 100755 External/swiftmailer/lib/classes/Swift/Plugins/BandwidthMonitorPlugin.php create mode 100755 External/swiftmailer/lib/classes/Swift/Plugins/Decorator/Replacements.php create mode 100755 External/swiftmailer/lib/classes/Swift/Plugins/DecoratorPlugin.php create mode 100755 External/swiftmailer/lib/classes/Swift/Plugins/Logger.php create mode 100755 External/swiftmailer/lib/classes/Swift/Plugins/LoggerPlugin.php create mode 100755 External/swiftmailer/lib/classes/Swift/Plugins/Loggers/ArrayLogger.php create mode 100755 External/swiftmailer/lib/classes/Swift/Plugins/Loggers/EchoLogger.php create mode 100755 External/swiftmailer/lib/classes/Swift/Plugins/Pop/Pop3Connection.php create mode 100755 External/swiftmailer/lib/classes/Swift/Plugins/Pop/Pop3Exception.php create mode 100755 External/swiftmailer/lib/classes/Swift/Plugins/PopBeforeSmtpPlugin.php create mode 100755 External/swiftmailer/lib/classes/Swift/Plugins/Reporter.php create mode 100755 External/swiftmailer/lib/classes/Swift/Plugins/ReporterPlugin.php create mode 100755 External/swiftmailer/lib/classes/Swift/Plugins/Reporters/HitReporter.php create mode 100755 External/swiftmailer/lib/classes/Swift/Plugins/Reporters/HtmlReporter.php create mode 100755 External/swiftmailer/lib/classes/Swift/Plugins/Sleeper.php create mode 100755 External/swiftmailer/lib/classes/Swift/Plugins/ThrottlerPlugin.php create mode 100755 External/swiftmailer/lib/classes/Swift/Plugins/Timer.php (limited to 'External/swiftmailer/lib/classes/Swift/Plugins') diff --git a/External/swiftmailer/lib/classes/Swift/Plugins/AntiFloodPlugin.php b/External/swiftmailer/lib/classes/Swift/Plugins/AntiFloodPlugin.php new file mode 100755 index 0000000..46a7f44 --- /dev/null +++ b/External/swiftmailer/lib/classes/Swift/Plugins/AntiFloodPlugin.php @@ -0,0 +1,147 @@ +setThreshold($threshold); + $this->setSleepTime($sleep); + $this->_sleeper = $sleeper; + } + + /** + * Set the number of emails to send before restarting. + * @param int $threshold + */ + public function setThreshold($threshold) + { + $this->_threshold = $threshold; + } + + /** + * Get the number of emails to send before restarting. + * @return int + */ + public function getThreshold() + { + return $this->_threshold; + } + + /** + * Set the number of seconds to sleep for during a restart. + * @param int $sleep time + */ + public function setSleepTime($sleep) + { + $this->_sleep = $sleep; + } + + /** + * Get the number of seconds to sleep for during a restart. + * @return int + */ + public function getSleepTime() + { + return $this->_sleep; + } + + /** + * Invoked immediately before the Message is sent. + * @param Swift_Events_SendEvent $evt + */ + public function beforeSendPerformed(Swift_Events_SendEvent $evt) + { + } + + /** + * 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; + } + } + + /** + * Sleep for $seconds. + * @param int $seconds + */ + public function sleep($seconds) + { + if (isset($this->_sleeper)) + { + $this->_sleeper->sleep($seconds); + } + else + { + sleep($seconds); + } + } + +} diff --git a/External/swiftmailer/lib/classes/Swift/Plugins/BandwidthMonitorPlugin.php b/External/swiftmailer/lib/classes/Swift/Plugins/BandwidthMonitorPlugin.php new file mode 100755 index 0000000..501cd80 --- /dev/null +++ b/External/swiftmailer/lib/classes/Swift/Plugins/BandwidthMonitorPlugin.php @@ -0,0 +1,173 @@ +getMessage(); + $message->toByteStream($this); + } + + /** + * Invoked immediately following a command being sent. + * @param Swift_Events_ResponseEvent $evt + */ + public function commandSent(Swift_Events_CommandEvent $evt) + { + $command = $evt->getCommand(); + $this->_out += strlen($command); + } + + /** + * Invoked immediately following a response coming back. + * @param Swift_Events_ResponseEvent $evt + */ + public function responseReceived(Swift_Events_ResponseEvent $evt) + { + $response = $evt->getResponse(); + $this->_in += strlen($response); + } + + /** + * Called when a message is sent so that the outgoing counter can be increased. + * @param string $bytes + */ + public function write($bytes) + { + $this->_out += strlen($bytes); + foreach ($this->_mirrors as $stream) + { + $stream->write($bytes); + } + } + + /** + * Not used. + */ + public function commit() + { + } + + /** + * Attach $is to this stream. + * The stream acts as an observer, receiving all data that is written. + * All {@link write()} and {@link flushBuffers()} operations will be mirrored. + * + * @param Swift_InputByteStream $is + */ + public function bind(Swift_InputByteStream $is) + { + $this->_mirrors[] = $is; + } + + /** + * Remove an already bound stream. + * If $is is not bound, no errors will be raised. + * If the stream currently has any buffered data it will be written to $is + * before unbinding occurs. + * + * @param Swift_InputByteStream $is + */ + public function unbind(Swift_InputByteStream $is) + { + foreach ($this->_mirrors as $k => $stream) + { + if ($is === $stream) + { + unset($this->_mirrors[$k]); + } + } + } + + /** + * Not used. + */ + public function flushBuffers() + { + foreach ($this->_mirrors as $stream) + { + $stream->flushBuffers(); + } + } + + /** + * Get the total number of bytes sent to the server. + * @return int + */ + public function getBytesOut() + { + return $this->_out; + } + + /** + * Get the total number of bytes received from the server. + * @return int + */ + public function getBytesIn() + { + return $this->_in; + } + + /** + * Reset the internal counters to zero. + */ + public function reset() + { + $this->_out = 0; + $this->_in = 0; + } + +} diff --git a/External/swiftmailer/lib/classes/Swift/Plugins/Decorator/Replacements.php b/External/swiftmailer/lib/classes/Swift/Plugins/Decorator/Replacements.php new file mode 100755 index 0000000..9735d0a --- /dev/null +++ b/External/swiftmailer/lib/classes/Swift/Plugins/Decorator/Replacements.php @@ -0,0 +1,36 @@ + + * $replacements = array( + * "address1@domain.tld" => array("{a}" => "b", "{c}" => "d"), + * "address2@domain.tld" => array("{a}" => "x", "{c}" => "y") + * ) + * + * + * When using an instance of {@link Swift_Plugins_Decorator_Replacements}, + * the object should return just the array of replacements for the address + * given to {@link Swift_Plugins_Decorator_Replacements::getReplacementsFor()}. + * + * @param mixed $replacements + */ + public function __construct($replacements) + { + if (!($replacements instanceof Swift_Plugins_Decorator_Replacements)) + { + $this->_replacements = (array) $replacements; + } + else + { + $this->_replacements = $replacements; + } + } + + /** + * Invoked immediately before the Message is sent. + * + * @param Swift_Events_SendEvent $evt + */ + public function beforeSendPerformed(Swift_Events_SendEvent $evt) + { + $message = $evt->getMessage(); + $this->_restoreMessage($message); + $to = array_keys($message->getTo()); + $address = array_shift($to); + if ($replacements = $this->getReplacementsFor($address)) + { + $body = $message->getBody(); + $search = array_keys($replacements); + $replace = array_values($replacements); + $bodyReplaced = str_replace( + $search, $replace, $body + ); + if ($body != $bodyReplaced) + { + $this->_originalBody = $body; + $message->setBody($bodyReplaced); + } + $subject = $message->getSubject(); + $subjectReplaced = str_replace( + $search, $replace, $subject + ); + if ($subject != $subjectReplaced) + { + $this->_originalSubject = $subject; + $message->setSubject($subjectReplaced); + } + $children = (array) $message->getChildren(); + foreach ($children as $child) + { + list($type, ) = sscanf($child->getContentType(), '%[^/]/%s'); + if ('text' == $type) + { + $body = $child->getBody(); + $bodyReplaced = str_replace( + $search, $replace, $body + ); + if ($body != $bodyReplaced) + { + $child->setBody($bodyReplaced); + $this->_originalChildBodies[$child->getId()] = $body; + } + } + } + $this->_lastMessage = $message; + } + } + + /** + * Find a map of replacements for the address. + * + * If this plugin was provided with a delegate instance of + * {@link Swift_Plugins_Decorator_Replacements} then the call will be + * delegated to it. Otherwise, it will attempt to find the replacements + * from the array provided in the constructor. + * + * If no replacements can be found, an empty value (NULL) is returned. + * + * @param string $address + * + * @return array + */ + public function getReplacementsFor($address) + { + if ($this->_replacements instanceof Swift_Plugins_Decorator_Replacements) + { + return $this->_replacements->getReplacementsFor($address); + } + else + { + return isset($this->_replacements[$address]) + ? $this->_replacements[$address] + : null + ; + } + } + + /** + * Invoked immediately after the Message is sent. + * + * @param Swift_Events_SendEvent $evt + */ + public function sendPerformed(Swift_Events_SendEvent $evt) + { + $this->_restoreMessage($evt->getMessage()); + } + + // -- Private methods + + /** Restore a changed message back to its original state */ + private function _restoreMessage(Swift_Mime_Message $message) + { + if ($this->_lastMessage === $message) + { + if (isset($this->_originalBody)) + { + $message->setBody($this->_originalBody); + $this->_originalBody = null; + } + if (isset($this->_originalSubject)) + { + $message->setSubject($this->_originalSubject); + $this->_originalSubject = null; + } + if (!empty($this->_originalChildBodies)) + { + $children = (array) $message->getChildren(); + foreach ($children as $child) + { + $id = $child->getId(); + if (array_key_exists($id, $this->_originalChildBodies)) + { + $child->setBody($this->_originalChildBodies[$id]); + } + } + $this->_originalChildBodies = array(); + } + $this->_lastMessage = null; + } + } + +} diff --git a/External/swiftmailer/lib/classes/Swift/Plugins/Logger.php b/External/swiftmailer/lib/classes/Swift/Plugins/Logger.php new file mode 100755 index 0000000..9864da0 --- /dev/null +++ b/External/swiftmailer/lib/classes/Swift/Plugins/Logger.php @@ -0,0 +1,37 @@ +_logger = $logger; + } + + /** + * Add a log entry. + * + * @param string $entry + */ + public function add($entry) + { + $this->_logger->add($entry); + } + + /** + * Clear the log contents. + */ + public function clear() + { + $this->_logger->clear(); + } + + /** + * Get this log as a string. + * + * @return string + */ + public function dump() + { + return $this->_logger->dump(); + } + + /** + * Invoked immediately following a command being sent. + * + * @param Swift_Events_ResponseEvent $evt + */ + public function commandSent(Swift_Events_CommandEvent $evt) + { + $command = $evt->getCommand(); + $this->_logger->add(sprintf(">> %s", $command)); + } + + /** + * Invoked immediately following a response coming back. + * + * @param Swift_Events_ResponseEvent $evt + */ + public function responseReceived(Swift_Events_ResponseEvent $evt) + { + $response = $evt->getResponse(); + $this->_logger->add(sprintf("<< %s", $response)); + } + + /** + * Invoked just before a Transport is started. + * + * @param Swift_Events_TransportChangeEvent $evt + */ + public function beforeTransportStarted(Swift_Events_TransportChangeEvent $evt) + { + $transportName = get_class($evt->getSource()); + $this->_logger->add(sprintf("++ Starting %s", $transportName)); + } + + /** + * Invoked immediately after the Transport is started. + * + * @param Swift_Events_TransportChangeEvent $evt + */ + public function transportStarted(Swift_Events_TransportChangeEvent $evt) + { + $transportName = get_class($evt->getSource()); + $this->_logger->add(sprintf("++ %s started", $transportName)); + } + + /** + * Invoked just before a Transport is stopped. + * + * @param Swift_Events_TransportChangeEvent $evt + */ + public function beforeTransportStopped(Swift_Events_TransportChangeEvent $evt) + { + $transportName = get_class($evt->getSource()); + $this->_logger->add(sprintf("++ Stopping %s", $transportName)); + } + + /** + * Invoked immediately after the Transport is stopped. + * + * @param Swift_Events_TransportChangeEvent $evt + */ + public function transportStopped(Swift_Events_TransportChangeEvent $evt) + { + $transportName = get_class($evt->getSource()); + $this->_logger->add(sprintf("++ %s stopped", $transportName)); + } + + /** + * Invoked as a TransportException is thrown in the Transport system. + * + * @param Swift_Events_TransportExceptionEvent $evt + */ + public function exceptionThrown(Swift_Events_TransportExceptionEvent $evt) + { + $e = $evt->getException(); + $message = $e->getMessage(); + $this->_logger->add(sprintf("!! %s", $message)); + $message .= PHP_EOL; + $message .= 'Log data:' . PHP_EOL; + $message .= $this->_logger->dump(); + $evt->cancelBubble(); + throw new Swift_TransportException($message); + } + +} diff --git a/External/swiftmailer/lib/classes/Swift/Plugins/Loggers/ArrayLogger.php b/External/swiftmailer/lib/classes/Swift/Plugins/Loggers/ArrayLogger.php new file mode 100755 index 0000000..930eca2 --- /dev/null +++ b/External/swiftmailer/lib/classes/Swift/Plugins/Loggers/ArrayLogger.php @@ -0,0 +1,73 @@ +_size = $size; + } + + /** + * Add a log entry. + * @param string $entry + */ + public function add($entry) + { + $this->_log[] = $entry; + while (count($this->_log) > $this->_size) + { + array_shift($this->_log); + } + } + + /** + * Clear the log contents. + */ + public function clear() + { + $this->_log = array(); + } + + /** + * Get this log as a string. + * @return string + */ + public function dump() + { + return implode(PHP_EOL, $this->_log); + } + +} diff --git a/External/swiftmailer/lib/classes/Swift/Plugins/Loggers/EchoLogger.php b/External/swiftmailer/lib/classes/Swift/Plugins/Loggers/EchoLogger.php new file mode 100755 index 0000000..83dd54b --- /dev/null +++ b/External/swiftmailer/lib/classes/Swift/Plugins/Loggers/EchoLogger.php @@ -0,0 +1,64 @@ +_isHtml = $isHtml; + } + + /** + * Add a log entry. + * @param string $entry + */ + public function add($entry) + { + if ($this->_isHtml) + { + printf('%s%s%s', htmlspecialchars($entry, ENT_QUOTES), '
', PHP_EOL); + } + else + { + printf('%s%s', $entry, PHP_EOL); + } + } + + /** + * Not implemented. + */ + public function clear() + { + } + + /** + * Not implemented. + */ + public function dump() + { + } + +} diff --git a/External/swiftmailer/lib/classes/Swift/Plugins/Pop/Pop3Connection.php b/External/swiftmailer/lib/classes/Swift/Plugins/Pop/Pop3Connection.php new file mode 100755 index 0000000..1c96dcf --- /dev/null +++ b/External/swiftmailer/lib/classes/Swift/Plugins/Pop/Pop3Connection.php @@ -0,0 +1,36 @@ +_host = $host; + $this->_port = $port; + $this->_crypto = $crypto; + } + + /** + * Create a new PopBeforeSmtpPlugin for $host and $port. + * + * @param string $host + * @param int $port + * @param string $cypto as "tls" or "ssl" + * + * @return Swift_Plugins_PopBeforeSmtpPlugin + */ + public static function newInstance($host, $port = 110, $crypto = null) + { + return new self($host, $port, $crypto); + } + + /** + * Set a Pop3Connection to delegate to instead of connecting directly. + * + * @param Swift_Plugins_Pop_Pop3Connection $connection + */ + public function setConnection(Swift_Plugins_Pop_Pop3Connection $connection) + { + $this->_connection = $connection; + return $this; + } + + /** + * Bind this plugin to a specific SMTP transport instance. + * + * @param Swift_Transport + */ + public function bindSmtp(Swift_Transport $smtp) + { + $this->_transport = $smtp; + } + + /** + * Set the connection timeout in seconds (default 10). + * + * @param int $timeout + */ + public function setTimeout($timeout) + { + $this->_timeout = (int) $timeout; + return $this; + } + + /** + * Set the username to use when connecting (if needed). + * + * @param string $username + */ + public function setUsername($username) + { + $this->_username = $username; + return $this; + } + + /** + * Set the password to use when connecting (if needed). + * + * @param string $password + */ + public function setPassword($password) + { + $this->_password = $password; + return $this; + } + + /** + * Connect to the POP3 host and authenticate. + * + * @throws Swift_Plugins_Pop_Pop3Exception if connection fails + */ + public function connect() + { + if (isset($this->_connection)) + { + $this->_connection->connect(); + } + else + { + if (!isset($this->_socket)) + { + if (!$socket = fsockopen( + $this->_getHostString(), $this->_port, $errno, $errstr, $this->_timeout)) + { + throw new Swift_Plugins_Pop_Pop3Exception( + sprintf('Failed to connect to POP3 host [%s]: %s', $this->_host, $errstr) + ); + } + $this->_socket = $socket; + + if (false === $greeting = fgets($this->_socket)) + { + throw new Swift_Plugins_Pop_Pop3Exception( + sprintf('Failed to connect to POP3 host [%s]', trim($greeting)) + ); + } + + $this->_assertOk($greeting); + + if ($this->_username) + { + $this->_command(sprintf("USER %s\r\n", $this->_username)); + $this->_command(sprintf("PASS %s\r\n", $this->_password)); + } + } + } + } + + /** + * Disconnect from the POP3 host. + */ + public function disconnect() + { + if (isset($this->_connection)) + { + $this->_connection->disconnect(); + } + else + { + $this->_command("QUIT\r\n"); + if (!fclose($this->_socket)) + { + throw new Swift_Plugins_Pop_Pop3Exception( + sprintf('POP3 host [%s] connection could not be stopped', $this->_host) + ); + } + $this->_socket = null; + } + } + + /** + * Invoked just before a Transport is started. + * + * @param Swift_Events_TransportChangeEvent $evt + */ + public function beforeTransportStarted(Swift_Events_TransportChangeEvent $evt) + { + if (isset($this->_transport)) + { + if ($this->_transport !== $evt->getTransport()) + { + return; + } + } + + $this->connect(); + $this->disconnect(); + } + + /** + * Not used. + */ + public function transportStarted(Swift_Events_TransportChangeEvent $evt) + { + } + + /** + * Not used. + */ + public function beforeTransportStopped(Swift_Events_TransportChangeEvent $evt) + { + } + + /** + * Not used. + */ + public function transportStopped(Swift_Events_TransportChangeEvent $evt) + { + } + + // -- Private Methods + + private function _command($command) + { + if (!fwrite($this->_socket, $command)) + { + throw new Swift_Plugins_Pop_Pop3Exception( + sprintf('Failed to write command [%s] to POP3 host', trim($command)) + ); + } + + if (false === $response = fgets($this->_socket)) + { + throw new Swift_Plugins_Pop_Pop3Exception( + sprintf('Failed to read from POP3 host after command [%s]', trim($command)) + ); + } + + $this->_assertOk($response); + + return $response; + } + + private function _assertOk($response) + { + if (substr($response, 0, 3) != '+OK') + { + throw new Swift_Plugins_Pop_Pop3Exception( + sprintf('POP3 command failed [%s]', trim($response)) + ); + } + } + + private function _getHostString() + { + $host = $this->_host; + switch (strtolower($this->_crypto)) + { + case 'ssl': + $host = 'ssl://' . $host; + break; + + case 'tls': + $host = 'tls://' . $host; + break; + } + return $host; + } + +} diff --git a/External/swiftmailer/lib/classes/Swift/Plugins/Reporter.php b/External/swiftmailer/lib/classes/Swift/Plugins/Reporter.php new file mode 100755 index 0000000..00d5765 --- /dev/null +++ b/External/swiftmailer/lib/classes/Swift/Plugins/Reporter.php @@ -0,0 +1,36 @@ +_reporter = $reporter; + } + + /** + * Not used. + */ + public function beforeSendPerformed(Swift_Events_SendEvent $evt) + { + } + + /** + * 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) + ); + } + } + +} diff --git a/External/swiftmailer/lib/classes/Swift/Plugins/Reporters/HitReporter.php b/External/swiftmailer/lib/classes/Swift/Plugins/Reporters/HitReporter.php new file mode 100755 index 0000000..0022f5e --- /dev/null +++ b/External/swiftmailer/lib/classes/Swift/Plugins/Reporters/HitReporter.php @@ -0,0 +1,63 @@ +_failures_cache[$address])) + { + $this->_failures[] = $address; + $this->_failures_cache[$address] = true; + } + } + + /** + * Get an array of addresses for which delivery failed. + * @return array + */ + public function getFailedRecipients() + { + return $this->_failures; + } + + /** + * Clear the buffer (empty the list). + */ + public function clear() + { + $this->_failures = $this->_failures_cache = array(); + } + +} diff --git a/External/swiftmailer/lib/classes/Swift/Plugins/Reporters/HtmlReporter.php b/External/swiftmailer/lib/classes/Swift/Plugins/Reporters/HtmlReporter.php new file mode 100755 index 0000000..7370078 --- /dev/null +++ b/External/swiftmailer/lib/classes/Swift/Plugins/Reporters/HtmlReporter.php @@ -0,0 +1,47 @@ +" . PHP_EOL; + echo "PASS " . $address . PHP_EOL; + echo "" . PHP_EOL; + flush(); + } + else + { + echo "
" . PHP_EOL; + echo "FAIL " . $address . PHP_EOL; + echo "
" . PHP_EOL; + flush(); + } + } + +} diff --git a/External/swiftmailer/lib/classes/Swift/Plugins/Sleeper.php b/External/swiftmailer/lib/classes/Swift/Plugins/Sleeper.php new file mode 100755 index 0000000..148cbd3 --- /dev/null +++ b/External/swiftmailer/lib/classes/Swift/Plugins/Sleeper.php @@ -0,0 +1,26 @@ +_rate = $rate; + $this->_mode = $mode; + $this->_sleeper = $sleeper; + $this->_timer = $timer; + } + + /** + * Invoked immediately before the Message is sent. + * @param Swift_Events_SendEvent $evt + */ + public function beforeSendPerformed(Swift_Events_SendEvent $evt) + { + $time = $this->getTimestamp(); + if (!isset($this->_start)) + { + $this->_start = $time; + } + $duration = $time - $this->_start; + + if (self::BYTES_PER_MINUTE == $this->_mode) + { + $sleep = $this->_throttleBytesPerMinute($duration); + } + else + { + $sleep = $this->_throttleMessagesPerMinute($duration); + } + + if ($sleep > 0) + { + $this->sleep($sleep); + } + } + + /** + * Invoked when a Message is sent. + * @param Swift_Events_SendEvent $evt + */ + public function sendPerformed(Swift_Events_SendEvent $evt) + { + parent::sendPerformed($evt); + ++$this->_messages; + } + + /** + * Sleep for $seconds. + * @param int $seconds + */ + public function sleep($seconds) + { + if (isset($this->_sleeper)) + { + $this->_sleeper->sleep($seconds); + } + else + { + sleep($seconds); + } + } + + /** + * Get the current UNIX timestamp + * @return int + */ + public function getTimestamp() + { + if (isset($this->_timer)) + { + return $this->_timer->getTimestamp(); + } + else + { + return time(); + } + } + + // -- Private methods + + /** + * Get a number of seconds to sleep for. + * @param int $timePassed + * @return int + * @access private + */ + private function _throttleBytesPerMinute($timePassed) + { + $expectedDuration = $this->getBytesOut() / ($this->_rate / 60); + return (int) ceil($expectedDuration - $timePassed); + } + + /** + * Get a number of seconds to sleep for. + * @param int $timePassed + * @return int + * @access private + */ + private function _throttleMessagesPerMinute($timePassed) + { + $expectedDuration = $this->_messages / ($this->_rate / 60); + return (int) ceil($expectedDuration - $timePassed); + } + +} diff --git a/External/swiftmailer/lib/classes/Swift/Plugins/Timer.php b/External/swiftmailer/lib/classes/Swift/Plugins/Timer.php new file mode 100755 index 0000000..92207bf --- /dev/null +++ b/External/swiftmailer/lib/classes/Swift/Plugins/Timer.php @@ -0,0 +1,26 @@ +