Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Basic port of 2.3.x email helper

  • Loading branch information...
commit 5af87eb663fa2fef9125eced61340494a65eb7ee 0 parents
@banks banks authored
Showing with 17,288 additions and 0 deletions.
  1. +147 −0 classes/email.php
  2. +29 −0 config/email.php
  3. +77 −0 vendor/swift/classes/Swift.php
  4. +85 −0 vendor/swift/classes/Swift/Attachment.php
  5. +188 −0 vendor/swift/classes/Swift/ByteStream/AbstractFilterableInputStream.php
  6. +197 −0 vendor/swift/classes/Swift/ByteStream/ArrayByteStream.php
  7. +187 −0 vendor/swift/classes/Swift/ByteStream/FileByteStream.php
  8. +49 −0 vendor/swift/classes/Swift/CharacterReader.php
  9. +76 −0 vendor/swift/classes/Swift/CharacterReader/GenericFixedWidthReader.php
  10. +64 −0 vendor/swift/classes/Swift/CharacterReader/UsAsciiReader.php
  11. +84 −0 vendor/swift/classes/Swift/CharacterReader/Utf8Reader.php
  12. +39 −0 vendor/swift/classes/Swift/CharacterReaderFactory.php
  13. +129 −0 vendor/swift/classes/Swift/CharacterReaderFactory/SimpleCharacterReaderFactory.php
  14. +96 −0 vendor/swift/classes/Swift/CharacterStream.php
  15. +329 −0 vendor/swift/classes/Swift/CharacterStream/ArrayCharacterStream.php
  16. +359 −0 vendor/swift/classes/Swift/DependencyContainer.php
  17. +40 −0 vendor/swift/classes/Swift/DependencyException.php
  18. +83 −0 vendor/swift/classes/Swift/EmbeddedFile.php
  19. +42 −0 vendor/swift/classes/Swift/Encoder.php
  20. +73 −0 vendor/swift/classes/Swift/Encoder/Base64Encoder.php
  21. +273 −0 vendor/swift/classes/Swift/Encoder/QpEncoder.php
  22. +100 −0 vendor/swift/classes/Swift/Encoder/Rfc2231Encoder.php
  23. +80 −0 vendor/swift/classes/Swift/Encoding.php
  24. +77 −0 vendor/swift/classes/Swift/Events/CommandEvent.php
  25. +39 −0 vendor/swift/classes/Swift/Events/CommandListener.php
  26. +50 −0 vendor/swift/classes/Swift/Events/Event.php
  27. +91 −0 vendor/swift/classes/Swift/Events/EventDispatcher.php
  28. +30 −0 vendor/swift/classes/Swift/Events/EventListener.php
  29. +76 −0 vendor/swift/classes/Swift/Events/EventObject.php
  30. +75 −0 vendor/swift/classes/Swift/Events/ResponseEvent.php
  31. +39 −0 vendor/swift/classes/Swift/Events/ResponseListener.php
  32. +137 −0 vendor/swift/classes/Swift/Events/SendEvent.php
  33. +45 −0 vendor/swift/classes/Swift/Events/SendListener.php
  34. +185 −0 vendor/swift/classes/Swift/Events/SimpleEventDispatcher.php
  35. +41 −0 vendor/swift/classes/Swift/Events/TransportChangeEvent.php
  36. +63 −0 vendor/swift/classes/Swift/Events/TransportChangeListener.php
  37. +60 −0 vendor/swift/classes/Swift/Events/TransportExceptionEvent.php
  38. +40 −0 vendor/swift/classes/Swift/Events/TransportExceptionListener.php
  39. +58 −0 vendor/swift/classes/Swift/FailoverTransport.php
  40. +38 −0 vendor/swift/classes/Swift/FileStream.php
  41. +44 −0 vendor/swift/classes/Swift/Filterable.php
  42. +72 −0 vendor/swift/classes/Swift/Image.php
  43. +82 −0 vendor/swift/classes/Swift/InputByteStream.php
  44. +40 −0 vendor/swift/classes/Swift/IoException.php
  45. +109 −0 vendor/swift/classes/Swift/KeyCache.php
  46. +219 −0 vendor/swift/classes/Swift/KeyCache/ArrayKeyCache.php
  47. +326 −0 vendor/swift/classes/Swift/KeyCache/DiskKeyCache.php
  48. +63 −0 vendor/swift/classes/Swift/KeyCache/KeyCacheInputStream.php
  49. +120 −0 vendor/swift/classes/Swift/KeyCache/NullKeyCache.php
  50. +141 −0 vendor/swift/classes/Swift/KeyCache/SimpleKeyCacheInputStream.php
  51. +58 −0 vendor/swift/classes/Swift/LoadBalancedTransport.php
  52. +58 −0 vendor/swift/classes/Swift/MailTransport.php
  53. +183 −0 vendor/swift/classes/Swift/Mailer.php
  54. +69 −0 vendor/swift/classes/Swift/Mailer/ArrayRecipientIterator.php
  55. +45 −0 vendor/swift/classes/Swift/Mailer/RecipientIterator.php
  56. +92 −0 vendor/swift/classes/Swift/Message.php
  57. +153 −0 vendor/swift/classes/Swift/Mime/Attachment.php
  58. +36 −0 vendor/swift/classes/Swift/Mime/CharsetObserver.php
  59. +51 −0 vendor/swift/classes/Swift/Mime/ContentEncoder.php
  60. +91 −0 vendor/swift/classes/Swift/Mime/ContentEncoder/Base64ContentEncoder.php
  61. +185 −0 vendor/swift/classes/Swift/Mime/ContentEncoder/PlainContentEncoder.php
  62. +127 −0 vendor/swift/classes/Swift/Mime/ContentEncoder/QpContentEncoder.php
  63. +61 −0 vendor/swift/classes/Swift/Mime/EmbeddedFile.php
  64. +38 −0 vendor/swift/classes/Swift/Mime/EncodingObserver.php
  65. +96 −0 vendor/swift/classes/Swift/Mime/Header.php
  66. +38 −0 vendor/swift/classes/Swift/Mime/HeaderEncoder.php
  67. +46 −0 vendor/swift/classes/Swift/Mime/HeaderEncoder/Base64HeaderEncoder.php
  68. +109 −0 vendor/swift/classes/Swift/Mime/HeaderEncoder/QpHeaderEncoder.php
  69. +82 −0 vendor/swift/classes/Swift/Mime/HeaderFactory.php
  70. +180 −0 vendor/swift/classes/Swift/Mime/HeaderSet.php
  71. +594 −0 vendor/swift/classes/Swift/Mime/Headers/AbstractHeader.php
  72. +128 −0 vendor/swift/classes/Swift/Mime/Headers/DateHeader.php
  73. +171 −0 vendor/swift/classes/Swift/Mime/Headers/IdentificationHeader.php
  74. +326 −0 vendor/swift/classes/Swift/Mime/Headers/MailboxHeader.php
  75. +284 −0 vendor/swift/classes/Swift/Mime/Headers/ParameterizedHeader.php
  76. +136 −0 vendor/swift/classes/Swift/Mime/Headers/PathHeader.php
  77. +118 −0 vendor/swift/classes/Swift/Mime/Headers/UnstructuredHeader.php
  78. +240 −0 vendor/swift/classes/Swift/Mime/Message.php
  79. +118 −0 vendor/swift/classes/Swift/Mime/MimeEntity.php
  80. +206 −0 vendor/swift/classes/Swift/Mime/MimePart.php
  81. +45 −0 vendor/swift/classes/Swift/Mime/ParameterizedHeader.php
  82. +197 −0 vendor/swift/classes/Swift/Mime/SimpleHeaderFactory.php
  83. +394 −0 vendor/swift/classes/Swift/Mime/SimpleHeaderSet.php
  84. +607 −0 vendor/swift/classes/Swift/Mime/SimpleMessage.php
  85. +791 −0 vendor/swift/classes/Swift/Mime/SimpleMimeEntity.php
  86. +75 −0 vendor/swift/classes/Swift/MimePart.php
  87. +52 −0 vendor/swift/classes/Swift/OutputByteStream.php
  88. +157 −0 vendor/swift/classes/Swift/Plugins/AntiFloodPlugin.php
  89. +183 −0 vendor/swift/classes/Swift/Plugins/BandwidthMonitorPlugin.php
  90. +46 −0 vendor/swift/classes/Swift/Plugins/Decorator/Replacements.php
  91. +211 −0 vendor/swift/classes/Swift/Plugins/DecoratorPlugin.php
  92. +47 −0 vendor/swift/classes/Swift/Plugins/Logger.php
  93. +170 −0 vendor/swift/classes/Swift/Plugins/LoggerPlugin.php
  94. +83 −0 vendor/swift/classes/Swift/Plugins/Loggers/ArrayLogger.php
  95. +74 −0 vendor/swift/classes/Swift/Plugins/Loggers/EchoLogger.php
  96. +47 −0 vendor/swift/classes/Swift/Plugins/Pop/Pop3Connection.php
  97. +44 −0 vendor/swift/classes/Swift/Plugins/Pop/Pop3Exception.php
  98. +298 −0 vendor/swift/classes/Swift/Plugins/PopBeforeSmtpPlugin.php
  99. +46 −0 vendor/swift/classes/Swift/Plugins/Reporter.php
  100. +92 −0 vendor/swift/classes/Swift/Plugins/ReporterPlugin.php
  101. +73 −0 vendor/swift/classes/Swift/Plugins/Reporters/HitReporter.php
  102. +57 −0 vendor/swift/classes/Swift/Plugins/Reporters/HtmlReporter.php
  103. +37 −0 vendor/swift/classes/Swift/Plugins/Sleeper.php
  104. +198 −0 vendor/swift/classes/Swift/Plugins/ThrottlerPlugin.php
  105. +37 −0 vendor/swift/classes/Swift/Plugins/Timer.php
  106. +86 −0 vendor/swift/classes/Swift/Preferences.php
  107. +38 −0 vendor/swift/classes/Swift/ReplacementFilterFactory.php
  108. +40 −0 vendor/swift/classes/Swift/RfcComplianceException.php
  109. +58 −0 vendor/swift/classes/Swift/SendmailTransport.php
  110. +66 −0 vendor/swift/classes/Swift/SmtpTransport.php
  111. +44 −0 vendor/swift/classes/Swift/StreamFilter.php
  112. +198 −0 vendor/swift/classes/Swift/StreamFilters/ByteArrayReplacementFilter.php
  113. +76 −0 vendor/swift/classes/Swift/StreamFilters/StringReplacementFilter.php
  114. +63 −0 vendor/swift/classes/Swift/StreamFilters/StringReplacementFilterFactory.php
  115. +39 −0 vendor/swift/classes/Swift/SwiftException.php
  116. +70 −0 vendor/swift/classes/Swift/Transport.php
  117. +553 −0 vendor/swift/classes/Swift/Transport/AbstractSmtpTransport.php
  118. +98 −0 vendor/swift/classes/Swift/Transport/Esmtp/Auth/CramMd5Authenticator.php
  119. +68 −0 vendor/swift/classes/Swift/Transport/Esmtp/Auth/LoginAuthenticator.php
  120. +67 −0 vendor/swift/classes/Swift/Transport/Esmtp/Auth/PlainAuthenticator.php
  121. +222 −0 vendor/swift/classes/Swift/Transport/Esmtp/AuthHandler.php
  122. +48 −0 vendor/swift/classes/Swift/Transport/Esmtp/Authenticator.php
  123. +92 −0 vendor/swift/classes/Swift/Transport/EsmtpHandler.php
  124. +349 −0 vendor/swift/classes/Swift/Transport/EsmtpTransport.php
  125. +107 −0 vendor/swift/classes/Swift/Transport/FailoverTransport.php
  126. +75 −0 vendor/swift/classes/Swift/Transport/IoBuffer.php
  127. +198 −0 vendor/swift/classes/Swift/Transport/LoadBalancedTransport.php
  128. +46 −0 vendor/swift/classes/Swift/Transport/MailInvoker.php
  129. +252 −0 vendor/swift/classes/Swift/Transport/MailTransport.php
  130. +183 −0 vendor/swift/classes/Swift/Transport/SendmailTransport.php
  131. +58 −0 vendor/swift/classes/Swift/Transport/SimpleMailInvoker.php
  132. +46 −0 vendor/swift/classes/Swift/Transport/SmtpAgent.php
  133. +286 −0 vendor/swift/classes/Swift/Transport/StreamBuffer.php
  134. +41 −0 vendor/swift/classes/Swift/TransportException.php
  135. +25 −0 vendor/swift/dependency_maps/cache_deps.php
  136. +97 −0 vendor/swift/dependency_maps/mime_deps.php
  137. +62 −0 vendor/swift/dependency_maps/transport_deps.php
  138. +82 −0 vendor/swift/mime_types.php
  139. +20 −0 vendor/swift/preferences.php
  140. +34 −0 vendor/swift/swift_init.php
  141. +35 −0 vendor/swift/swift_required.php
147 classes/email.php
@@ -0,0 +1,147 @@
+<?php defined('SYSPATH') OR die('No direct access allowed.');
+/**
+ * Email module
+ *
+ * Ported from Kohana 2.2.3 Core to Kohana 3.0 module
+ *
+ * Updated to use Swiftmailer 4.0.4
+ *
+ * @package Core
+ * @author Kohana Team
+ * @copyright (c) 2007-2008 Kohana Team
+ * @license http://kohanaphp.com/license.html
+ */
+class Email {
+
+ // SwiftMailer instance
+ protected static $mail;
+
+ /**
+ * Creates a SwiftMailer instance.
+ *
+ * @param string DSN connection string
+ * @return object Swift object
+ */
+ public static function connect($config = NULL)
+ {
+ if ( ! class_exists('Swift_Mailer', FALSE))
+ {
+ // Load SwiftMailer
+ require Kohana::find_file('vendor', 'swift/swift_required');
+ }
+
+ // Load default configuration
+ ($config === NULL) and $config = Kohana::config('email');
+
+ switch ($config['driver'])
+ {
+ case 'smtp':
+ // Set port
+ $port = empty($config['options']['port']) ? 25 : (int) $config['options']['port'];
+
+ // Create SMTP Transport
+ $transport = Swift_SmtpTransport::newInstance($config['options']['hostname'], $port);
+
+ if ( ! empty($config['options']['encryption']))
+ {
+ // Set encryption
+ $transport->setEncryption($config['options']['encryption']);
+ }
+
+ // Do authentication, if part of the DSN
+ empty($config['options']['username']) or $transport->setUsername($config['options']['username']);
+ empty($config['options']['password']) or $transport->setPassword($config['options']['password']);
+
+ // Set the timeout to 5 seconds
+ $transport->setTimeout(empty($config['options']['timeout']) ? 5 : (int) $config['options']['timeout']);
+ break;
+ case 'sendmail':
+ // Create a sendmail connection
+ $transport = Swift_SendmailTransport::newInstance(empty($config['options']) ? "/usr/sbin/sendmail -bs" : $config['options']);
+
+ // Set the timeout to 5 seconds
+ $transport->setTimeout(5);
+ break;
+ default:
+ // Use the native connection
+ $transport = Swift_MailTransport::newInstance($config['options']);
+ break;
+ }
+
+ // Create the SwiftMailer instance
+ return Email::$mail = Swift_Mailer::newInstance($transport);
+ }
+
+ /**
+ * Send an email message.
+ *
+ * @param string|array recipient email (and name), or an array of To, Cc, Bcc names
+ * @param string|array sender email (and name)
+ * @param string message subject
+ * @param string message body
+ * @param boolean send email as HTML
+ * @return integer number of emails sent
+ */
+ public static function send($to, $from, $subject, $message, $html = FALSE)
+ {
+ // Connect to SwiftMailer
+ (Email::$mail === NULL) and email::connect();
+
+ // Determine the message type
+ $html = ($html === TRUE) ? 'text/html' : 'text/plain';
+
+ // Create the message
+ $message = Swift_Message::newInstance($subject, $message, $html, 'utf-8');
+
+ if (is_string($to))
+ {
+ // Single recipient
+ $message->setTo($to);
+ }
+ elseif (is_array($to))
+ {
+ if (isset($to[0]) AND isset($to[1]))
+ {
+ // Create To: address set
+ $to = array('to' => $to);
+ }
+
+ foreach ($to as $method => $set)
+ {
+ if ( ! in_array($method, array('to', 'cc', 'bcc')))
+ {
+ // Use To: by default
+ $method = 'to';
+ }
+
+ // Create method name
+ $method = 'add'.ucfirst($method);
+
+ if (is_array($set))
+ {
+ // Add a recipient with name
+ $message->$method($set[0], $set[1]);
+ }
+ else
+ {
+ // Add a recipient without name
+ $message->$method($set);
+ }
+ }
+ }
+
+ if (is_string($from))
+ {
+ // From without a name
+ $message->setFrom($from);
+ }
+ elseif (is_array($from))
+ {
+ // From with a name
+ $message->setFrom($from[0], $from[1]);
+ }
+
+ return Email::$mail->send($message);
+ }
+
+} // End email
29 config/email.php
@@ -0,0 +1,29 @@
+<?php defined('SYSPATH') OR die('No direct access allowed.');
+return array(
+ /**
+ * SwiftMailer driver, used with the email module.
+ *
+ * Valid drivers are: native, sendmail, smtp
+ */
+ 'driver' => 'native',
+
+ /**
+ * To use secure connections with SMTP, set "port" to 465 instead of 25.
+ * To enable TLS, set "encryption" to "tls".
+ *
+ * Note for SMTP, 'auth' key no longer exists as it did in 2.3.x helper
+ * Simply specifying a username and password is enough for all normal auth methods
+ * as they are autodeteccted in Swiftmailer 4
+ *
+ * PopB4Smtp is not supported in this module as I had no way to test it but
+ * SwiftMailer 4 does have a PopBeforeSMTP plugin so it shouldn't be hard to implement
+ *
+ * Encryption can be one of 'ssl' or 'tls' (both require non-default PHP extensions
+ *
+ * Driver options:
+ * @param null native: no options
+ * @param string sendmail: executable path, with -bs or equivalent attached
+ * @param array smtp: hostname, (username), (password), (port), (encryption)
+ */
+ 'options' => NULL
+);
77 vendor/swift/classes/Swift.php
@@ -0,0 +1,77 @@
+<?php
+
+/*
+ General utility class from Swift Mailer.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ */
+
+/**
+ * General utility class in Swift Mailer, not to be instantiated.
+ *
+ * @package Swift
+ *
+ * @author Chris Corbyn
+ */
+abstract class Swift
+{
+
+ /** Swift Mailer Version number generated during dist release process */
+ const VERSION = '4.0.4';
+
+ /**
+ * Internal autoloader for spl_autoload_register().
+ *
+ * @param string $class
+ */
+ public static function autoload($class)
+ {
+ //Don't interfere with other autoloaders
+ if (substr($class, 0, strlen(__CLASS__)) != __CLASS__)
+ {
+ return;
+ }
+
+ $path = SWIFT_CLASS_DIRECTORY . '/' . str_replace('_', '/', $class) . '.php';
+
+ if (file_exists($path))
+ {
+ require_once $path;
+ }
+ }
+
+ /**
+ * Configure autoloading using Swift Mailer.
+ *
+ * This is designed to play nicely with other autoloaders.
+ */
+ public static function registerAutoload()
+ {
+ if (!$callbacks = spl_autoload_functions())
+ {
+ $callbacks = array();
+ }
+ foreach ($callbacks as $callback)
+ {
+ spl_autoload_unregister($callback);
+ }
+ spl_autoload_register(array('Swift', 'autoload'));
+ foreach ($callbacks as $callback)
+ {
+ spl_autoload_register($callback);
+ }
+ }
+
+}
85 vendor/swift/classes/Swift/Attachment.php
@@ -0,0 +1,85 @@
+<?php
+
+/*
+ Attachment wrapper class in Swift Mailer.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ */
+
+//@require 'Swift/Mime/Attachment.php';
+//@require 'Swift/ByteStream/FileByteStream.php';
+//@require 'Swift/DependencyContainer.php';
+
+/**
+ * Attachment class for attaching files to a {@link Swift_Mime_Message}.
+ * @package Swift
+ * @subpackage Mime
+ * @author Chris Corbyn
+ */
+class Swift_Attachment extends Swift_Mime_Attachment
+{
+
+ /**
+ * Create a new Attachment.
+ * Details may be optionally provided to the constructor.
+ * @param string|Swift_OutputByteStream $data
+ * @param string $filename
+ * @param string $contentType
+ */
+ public function __construct($data = null, $filename = null,
+ $contentType = null)
+ {
+ call_user_func_array(
+ array($this, 'Swift_Mime_Attachment::__construct'),
+ Swift_DependencyContainer::getInstance()
+ ->createDependenciesFor('mime.attachment')
+ );
+
+ $this->setBody($data);
+ $this->setFilename($filename);
+ if ($contentType)
+ {
+ $this->setContentType($contentType);
+ }
+ }
+
+ /**
+ * Create a new Attachment.
+ * @param string|Swift_OutputByteStream $data
+ * @param string $filename
+ * @param string $contentType
+ * @return Swift_Mime_Attachment
+ */
+ public static function newInstance($data = null, $filename = null,
+ $contentType = null)
+ {
+ return new self($data, $filename, $contentType);
+ }
+
+ /**
+ * Create a new Attachment from a filesystem path.
+ * @param string $path
+ * @param string $contentType optional
+ * @return Swift_Mime_Attachment
+ */
+ public static function fromPath($path, $contentType = null)
+ {
+ return self::newInstance()->setFile(
+ new Swift_ByteStream_FileByteStream($path),
+ $contentType
+ );
+ }
+
+}
188 vendor/swift/classes/Swift/ByteStream/AbstractFilterableInputStream.php
@@ -0,0 +1,188 @@
+<?php
+
+/*
+ Bi-Directional FileStream in Swift Mailer.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ */
+
+//@require 'Swift/InputByteStream.php';
+//@require 'Swift/Filterable.php';
+//@require 'Swift/StreamFilter.php';
+
+/**
+ * Provides the base functionality for an InputStream supporting filters.
+ * @package Swift
+ * @subpackage ByteStream
+ * @author Chris Corbyn
+ */
+abstract class Swift_ByteStream_AbstractFilterableInputStream
+ implements Swift_InputByteStream, Swift_Filterable
+{
+
+ /** Write sequence */
+ private $_sequence = 0;
+
+ /** StreamFilters */
+ private $_filters = array();
+
+ /** A buffer for writing */
+ private $_writeBuffer = '';
+
+ /** Bound streams */
+ private $_mirrors = array();
+
+ /**
+ * Commit the given bytes to the storage medium immediately.
+ * @param string $bytes
+ * @access protected
+ */
+ abstract protected function _commit($bytes);
+
+ /**
+ * Flush any buffers/content with immediate effect.
+ * @access protected
+ */
+ abstract protected function _flush();
+
+ /**
+ * Add a StreamFilter to this InputByteStream.
+ * @param Swift_StreamFilter $filter
+ * @param string $key
+ */
+ public function addFilter(Swift_StreamFilter $filter, $key)
+ {
+ $this->_filters[$key] = $filter;
+ }
+
+ /**
+ * Remove an already present StreamFilter based on its $key.
+ * @param string $key
+ */
+ public function removeFilter($key)
+ {
+ unset($this->_filters[$key]);
+ }
+
+ /**
+ * Writes $bytes to the end of the stream.
+ * @param string $bytes
+ * @throws Swift_IoException
+ */
+ public function write($bytes)
+ {
+ $this->_writeBuffer .= $bytes;
+ foreach ($this->_filters as $filter)
+ {
+ if ($filter->shouldBuffer($this->_writeBuffer))
+ {
+ return;
+ }
+ }
+ $this->_doWrite($this->_writeBuffer);
+ return ++$this->_sequence;
+ }
+
+ /**
+ * For any bytes that are currently buffered inside the stream, force them
+ * off the buffer.
+ *
+ * @throws Swift_IoException
+ */
+ public function commit()
+ {
+ $this->_doWrite($this->_writeBuffer);
+ }
+
+ /**
+ * 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)
+ {
+ if ($this->_writeBuffer !== '')
+ {
+ $stream->write($this->_filter($this->_writeBuffer));
+ }
+ unset($this->_mirrors[$k]);
+ }
+ }
+ }
+
+ /**
+ * Flush the contents of the stream (empty it) and set the internal pointer
+ * to the beginning.
+ * @throws Swift_IoException
+ */
+ public function flushBuffers()
+ {
+ if ($this->_writeBuffer !== '')
+ {
+ $this->_doWrite($this->_writeBuffer);
+ }
+ $this->_flush();
+
+ foreach ($this->_mirrors as $stream)
+ {
+ $stream->flushBuffers();
+ }
+ }
+
+ // -- Private methods
+
+ /** Run $bytes through all filters */
+ private function _filter($bytes)
+ {
+ foreach ($this->_filters as $filter)
+ {
+ $bytes = $filter->filter($bytes);
+ }
+ return $bytes;
+ }
+
+ /** Just write the bytes to the stream */
+ private function _doWrite($bytes)
+ {
+ $this->_commit($this->_filter($bytes));
+
+ foreach ($this->_mirrors as $stream)
+ {
+ $stream->write($bytes);
+ }
+
+ $this->_writeBuffer = '';
+ }
+
+}
197 vendor/swift/classes/Swift/ByteStream/ArrayByteStream.php
@@ -0,0 +1,197 @@
+<?php
+
+/*
+ Bi-Directional ByteStream using an array in Swift Mailer.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ */
+
+//@require 'Swift/InputByteStream.php';
+//@require 'Swift/OutputByteStream.php';
+
+/**
+ * Allows reading and writing of bytes to and from an array.
+ * @package Swift
+ * @subpackage ByteStream
+ * @author Chris Corbyn
+ */
+class Swift_ByteStream_ArrayByteStream
+ implements Swift_InputByteStream, Swift_OutputByteStream
+{
+
+ /**
+ * The internal stack of bytes.
+ * @var string[]
+ * @access private
+ */
+ private $_array = array();
+
+ /**
+ * The size of the stack
+ * @var int
+ * @access private
+ */
+ private $_arraySize = 0;
+
+ /**
+ * The internal pointer offset.
+ * @var int
+ * @access private
+ */
+ private $_offset = 0;
+
+ /** Bound streams */
+ private $_mirrors = array();
+
+ /**
+ * Create a new ArrayByteStream.
+ * If $stack is given the stream will be populated with the bytes it contains.
+ * @param mixed $stack of bytes in string or array form, optional
+ */
+ public function __construct($stack = null)
+ {
+ if (is_array($stack))
+ {
+ $this->_array = $stack;
+ $this->_arraySize = count($stack);
+ }
+ elseif (is_string($stack))
+ {
+ $this->write($stack);
+ }
+ else
+ {
+ $this->_array = array();
+ }
+ }
+
+ /**
+ * Reads $length bytes from the stream into a string and moves the pointer
+ * through the stream by $length. If less bytes exist than are requested the
+ * remaining bytes are given instead. If no bytes are remaining at all, boolean
+ * false is returned.
+ * @param int $length
+ * @return string
+ */
+ public function read($length)
+ {
+ if ($this->_offset == $this->_arraySize)
+ {
+ return false;
+ }
+
+ // Don't use array slice
+ $end = $length + $this->_offset;
+ $end = $this->_arraySize<$end
+ ?$this->_arraySize
+ :$end;
+ $ret = '';
+ for (; $this->_offset < $end; ++$this->_offset)
+ {
+ $ret .= $this->_array[$this->_offset];
+ }
+ return $ret;
+ }
+
+ /**
+ * Writes $bytes to the end of the stream.
+ * @param string $bytes
+ */
+ public function write($bytes)
+ {
+ $to_add = str_split($bytes);
+ array_unshift($to_add, &$this->_array);
+ $this->_arraySize = call_user_func_array('array_push', $to_add);
+
+ 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]);
+ }
+ }
+ }
+
+ /**
+ * Move the internal read pointer to $byteOffset in the stream.
+ * @param int $byteOffset
+ * @return boolean
+ */
+ public function setReadPointer($byteOffset)
+ {
+ if ($byteOffset > $this->_arraySize)
+ {
+ $byteOffset = $this->_arraySize;
+ }
+ elseif ($byteOffset < 0)
+ {
+ $byteOffset = 0;
+ }
+
+ $this->_offset = $byteOffset;
+ }
+
+ /**
+ * Flush the contents of the stream (empty it) and set the internal pointer
+ * to the beginning.
+ */
+ public function flushBuffers()
+ {
+ $this->_offset = 0;
+ $this->_array = array();
+ $this->_arraySize = 0;
+
+ foreach ($this->_mirrors as $stream)
+ {
+ $stream->flushBuffers();
+ }
+ }
+
+}
187 vendor/swift/classes/Swift/ByteStream/FileByteStream.php
@@ -0,0 +1,187 @@
+<?php
+
+/*
+ Bi-Directional FileStream in Swift Mailer.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ */
+
+//@require 'Swift/ByteStream/AbstractFilterableInputStream.php';
+//@require 'Swift/InputByteStream.php';
+//@require 'Swift/FileStream.php';
+//@require 'Swift/IoException.php';
+
+/**
+ * Allows reading and writing of bytes to and from a file.
+ * @package Swift
+ * @subpackage ByteStream
+ * @author Chris Corbyn
+ */
+class Swift_ByteStream_FileByteStream
+ extends Swift_ByteStream_AbstractFilterableInputStream
+ implements Swift_FileStream
+{
+
+ /** The internal pointer offset */
+ private $_offset = 0;
+
+ /** The path to the file */
+ private $_path;
+
+ /** The mode this file is opened in for writing */
+ private $_mode;
+
+ /** A lazy-loaded resource handle for reading the file */
+ private $_reader;
+
+ /** A lazy-loaded resource handle for writing the file */
+ private $_writer;
+
+ /** If magic_quotes_runtime is on, this will be true */
+ private $_quotes = false;
+
+ /**
+ * Create a new FileByteStream for $path.
+ * @param string $path
+ * @param string $writable if true
+ */
+ public function __construct($path, $writable = false)
+ {
+ $this->_path = $path;
+ $this->_mode = $writable ? 'w+b' : 'rb';
+ $this->_quotes = get_magic_quotes_runtime();
+ }
+
+ /**
+ * Get the complete path to the file.
+ * @return string
+ */
+ public function getPath()
+ {
+ return $this->_path;
+ }
+
+ /**
+ * Reads $length bytes from the stream into a string and moves the pointer
+ * through the stream by $length. If less bytes exist than are requested the
+ * remaining bytes are given instead. If no bytes are remaining at all, boolean
+ * false is returned.
+ * @param int $length
+ * @return string
+ * @throws Swift_IoException
+ */
+ public function read($length)
+ {
+ $fp = $this->_getReadHandle();
+ if (!feof($fp))
+ {
+ if ($this->_quotes)
+ {
+ set_magic_quotes_runtime(0);
+ }
+ $bytes = fread($fp, $length);
+ if ($this->_quotes)
+ {
+ set_magic_quotes_runtime(1);
+ }
+ $this->_offset = ftell($fp);
+ return $bytes;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Move the internal read pointer to $byteOffset in the stream.
+ * @param int $byteOffset
+ * @return boolean
+ */
+ public function setReadPointer($byteOffset)
+ {
+ if (isset($this->_reader))
+ {
+ fseek($this->_reader, $byteOffset, SEEK_SET);
+ }
+ $this->_offset = $byteOffset;
+ }
+
+ // -- Private methods
+
+ /** Just write the bytes to the file */
+ protected function _commit($bytes)
+ {
+ fwrite($this->_getWriteHandle(), $bytes);
+ $this->_resetReadHandle();
+ }
+
+ /** Not used */
+ protected function _flush()
+ {
+ }
+
+ /** Get the resource for reading */
+ private function _getReadHandle()
+ {
+ if (!isset($this->_reader))
+ {
+ if (!$this->_reader = fopen($this->_path, 'rb'))
+ {
+ throw new Swift_IoException(
+ 'Unable to open file for reading [' . $this->_path . ']'
+ );
+ }
+ fseek($this->_reader, $this->_offset, SEEK_SET);
+ }
+ return $this->_reader;
+ }
+
+ /** Get the resource for writing */
+ private function _getWriteHandle()
+ {
+ if (!isset($this->_writer))
+ {
+ if (!$this->_writer = fopen($this->_path, $this->_mode))
+ {
+ throw new Swift_IoException(
+ 'Unable to open file for writing [' . $this->_path . ']'
+ );
+ }
+ }
+ return $this->_writer;
+ }
+
+ /** Force a reload of the resource for writing */
+ private function _resetWriteHandle()
+ {
+ if (isset($this->_writer))
+ {
+ fclose($this->_writer);
+ $this->_writer = null;
+ }
+ }
+
+ /** Force a reload of the resource for reading */
+ private function _resetReadHandle()
+ {
+ if (isset($this->_reader))
+ {
+ fclose($this->_reader);
+ $this->_reader = null;
+ }
+ }
+
+}
49 vendor/swift/classes/Swift/CharacterReader.php
@@ -0,0 +1,49 @@
+<?php
+
+/*
+ Analyzes characters for a specific character set.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ */
+
+/**
+ * Analyzes characters for a specific character set.
+ * @package Swift
+ * @subpackage Encoder
+ * @author Chris Corbyn
+ */
+interface Swift_CharacterReader
+{
+
+ /**
+ * Returns an integer which specifies how many more bytes to read.
+ * A positive integer indicates the number of more bytes to fetch before invoking
+ * this method again.
+ * A value of zero means this is already a valid character.
+ * A value of -1 means this cannot possibly be a valid character.
+ * @param int[] $bytes
+ * @return int
+ */
+ public function validateByteSequence($bytes, $size);
+
+ /**
+ * Returns the number of bytes which should be read to start each character.
+ * For fixed width character sets this should be the number of
+ * octets-per-character. For multibyte character sets this will probably be 1.
+ * @return int
+ */
+ public function getInitialByteSize();
+
+}
76 vendor/swift/classes/Swift/CharacterReader/GenericFixedWidthReader.php
@@ -0,0 +1,76 @@
+<?php
+
+/*
+ Provides fixed-width byte sizes for reading fixed-width character sets.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ */
+
+//@require 'Swift/CharacterReader.php';
+
+/**
+ * Provides fixed-width byte sizes for reading fixed-width character sets.
+ * @package Swift
+ * @subpackage Encoder
+ * @author Chris Corbyn
+ */
+class Swift_CharacterReader_GenericFixedWidthReader
+ implements Swift_CharacterReader
+{
+
+ /**
+ * The number of bytes in a single character.
+ * @var int
+ * @access private
+ */
+ private $_width;
+
+ /**
+ * Creates a new GenericFixedWidthReader using $width bytes per character.
+ * @param int $width
+ */
+ public function __construct($width)
+ {
+ $this->_width = $width;
+ }
+
+ /**
+ * Returns an integer which specifies how many more bytes to read.
+ * A positive integer indicates the number of more bytes to fetch before invoking
+ * this method again.
+ * A value of zero means this is already a valid character.
+ * A value of -1 means this cannot possibly be a valid character.
+ * @param string $bytes
+ * @return int
+ */
+ public function validateByteSequence($bytes, $size)
+ {
+ $needed = $this->_width - $size;
+ return ($needed > -1)
+ ? $needed
+ : -1
+ ;
+ }
+
+ /**
+ * Returns the number of bytes which should be read to start each character.
+ * @return int
+ */
+ public function getInitialByteSize()
+ {
+ return $this->_width;
+ }
+
+}
64 vendor/swift/classes/Swift/CharacterReader/UsAsciiReader.php
@@ -0,0 +1,64 @@
+<?php
+
+/*
+ Analyzes US-ASCII characters.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ */
+
+//@require 'Swift/CharacterReader.php';
+
+/**
+ * Analyzes US-ASCII characters.
+ * @package Swift
+ * @subpackage Encoder
+ * @author Chris Corbyn
+ */
+class Swift_CharacterReader_UsAsciiReader
+ implements Swift_CharacterReader
+{
+
+ /**
+ * Returns an integer which specifies how many more bytes to read.
+ * A positive integer indicates the number of more bytes to fetch before invoking
+ * this method again.
+ * A value of zero means this is already a valid character.
+ * A value of -1 means this cannot possibly be a valid character.
+ * @param string $bytes
+ * @return int
+ */
+ public function validateByteSequence($bytes, $size)
+ {
+ $byte = reset($bytes);
+ if (1 == count($bytes) && $byte >= 0x00 && $byte <= 0x7F)
+ {
+ return 0;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+
+ /**
+ * Returns the number of bytes which should be read to start each character.
+ * @return int
+ */
+ public function getInitialByteSize()
+ {
+ return 1;
+ }
+
+}
84 vendor/swift/classes/Swift/CharacterReader/Utf8Reader.php
@@ -0,0 +1,84 @@
+<?php
+
+/*
+ Analyzes UTF-8 characters.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ */
+
+//@require 'Swift/CharacterReader.php';
+
+/**
+ * Analyzes UTF-8 characters.
+ * @package Swift
+ * @subpackage Encoder
+ * @author Chris Corbyn
+ */
+class Swift_CharacterReader_Utf8Reader
+ implements Swift_CharacterReader
+{
+
+ /** Pre-computed for optimization */
+ private static $length_map=array(
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x0N
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x1N
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x2N
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x3N
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x4N
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x5N
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x6N
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x7N
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0x8N
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0x9N
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0xAN
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0xBN
+ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, //0xCN
+ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, //0xDN
+ 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, //0xEN
+ 4,4,4,4,4,4,4,4,5,5,5,5,6,6,0,0 //0xFN
+ );
+
+
+ /**
+ * Returns an integer which specifies how many more bytes to read.
+ * A positive integer indicates the number of more bytes to fetch before invoking
+ * this method again.
+ * A value of zero means this is already a valid character.
+ * A value of -1 means this cannot possibly be a valid character.
+ * @param string $bytes
+ * @return int
+ */
+ public function validateByteSequence($bytes, $size)
+ {
+ if ($size<1){
+ return -1;
+ }
+ $needed = self::$length_map[$bytes[0]] - $size;
+ return ($needed > -1)
+ ? $needed
+ : -1
+ ;
+ }
+
+ /**
+ * Returns the number of bytes which should be read to start each character.
+ * @return int
+ */
+ public function getInitialByteSize()
+ {
+ return 1;
+ }
+
+}
39 vendor/swift/classes/Swift/CharacterReaderFactory.php
@@ -0,0 +1,39 @@
+<?php
+
+/*
+ A factory for creating CharacterReaders.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ */
+
+//@require 'Swift/CharacterReader.php';
+
+/**
+ * A factory for creating CharacterReaders.
+ * @package Swift
+ * @subpackage Encoder
+ * @author Chris Corbyn
+ */
+interface Swift_CharacterReaderFactory
+{
+
+ /**
+ * Returns a CharacterReader suitable for the charset applied.
+ * @param string $charset
+ * @return Swift_CharacterReader
+ */
+ public function getReaderFor($charset);
+
+}
129 vendor/swift/classes/Swift/CharacterReaderFactory/SimpleCharacterReaderFactory.php
@@ -0,0 +1,129 @@
+<?php
+
+/*
+ The standard factory for creating CharacterReaders in Swift Mailer.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ */
+
+//@require 'Swift/CharacterReaderFactory.php';
+
+/**
+ * Standard factory for creating CharacterReaders.
+ * @package Swift
+ * @subpackage Encoder
+ * @author Chris Corbyn
+ */
+class Swift_CharacterReaderFactory_SimpleCharacterReaderFactory
+ implements Swift_CharacterReaderFactory
+{
+
+ /**
+ * A map of charset patterns to their implementation classes.
+ * @var array
+ * @access private
+ */
+ private $_map = array();
+
+ /**
+ * Factories which have already been loaded.
+ * @var Swift_CharacterReaderFactory[]
+ * @access private
+ */
+ private $_loaded = array();
+
+ /**
+ * Creates a new CharacterReaderFactory.
+ */
+ public function __construct()
+ {
+ $prefix = 'Swift_CharacterReader_';
+
+ $singleByte = array(
+ 'class' => $prefix . 'GenericFixedWidthReader',
+ 'constructor' => array(1)
+ );
+
+ $doubleByte = array(
+ 'class' => $prefix . 'GenericFixedWidthReader',
+ 'constructor' => array(2)
+ );
+
+ $fourBytes = array(
+ 'class' => $prefix . 'GenericFixedWidthReader',
+ 'constructor' => array(4)
+ );
+
+ //Utf-8
+ $this->_map['utf-?8'] = array(
+ 'class' => $prefix . 'Utf8Reader',
+ 'constructor' => array()
+ );
+
+ //7-8 bit charsets
+ $this->_map['(us-)?ascii'] = $singleByte;
+ $this->_map['(iso|iec)-?8859-?[0-9]+'] = $singleByte;
+ $this->_map['windows-?125[0-9]'] = $singleByte;
+ $this->_map['cp-?[0-9]+'] = $singleByte;
+ $this->_map['ansi'] = $singleByte;
+ $this->_map['macintosh'] = $singleByte;
+ $this->_map['koi-?7'] = $singleByte;
+ $this->_map['koi-?8-?.+'] = $singleByte;
+ $this->_map['mik'] = $singleByte;
+ $this->_map['(cork|t1)'] = $singleByte;
+ $this->_map['v?iscii'] = $singleByte;
+
+ //16 bits
+ $this->_map['(ucs-?2|utf-?16)'] = $doubleByte;
+
+ //32 bits
+ $this->_map['(ucs-?4|utf-?32)'] = $fourBytes;
+
+ //Fallback
+ $this->_map['.*'] = $singleByte;
+ }
+
+ /**
+ * Returns a CharacterReader suitable for the charset applied.
+ * @param string $charset
+ * @return Swift_CharacterReader
+ */
+ public function getReaderFor($charset)
+ {
+ $charset = trim(strtolower($charset));
+ foreach ($this->_map as $pattern => $spec)
+ {
+ $re = '/^' . $pattern . '$/D';
+ if (preg_match($re, $charset))
+ {
+ if (!array_key_exists($pattern, $this->_loaded))
+ {
+ $reflector = new ReflectionClass($spec['class']);
+ if ($reflector->getConstructor())
+ {
+ $reader = $reflector->newInstanceArgs($spec['constructor']);
+ }
+ else
+ {
+ $reader = $reflector->newInstance();
+ }
+ $this->_loaded[$pattern] = $reader;
+ }
+ return $this->_loaded[$pattern];
+ }
+ }
+ }
+
+}
96 vendor/swift/classes/Swift/CharacterStream.php
@@ -0,0 +1,96 @@
+<?php
+
+/*
+ Bi-Directional CharacterStream in Swift Mailer.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ */
+
+require_once dirname(__FILE__) . '/OutputByteStream.php';
+require_once dirname(__FILE__) . '/CharacterReaderFactory.php';
+
+
+/**
+ * An abstract means of reading and writing data in terms of characters as opposed
+ * to bytes.
+ * Classes implementing this interface may use a subsystem which requires less
+ * memory than working with large strings of data.
+ * @package Swift
+ * @subpackage CharacterStream
+ * @author Chris Corbyn
+ */
+interface Swift_CharacterStream
+{
+
+ /**
+ * Set the character set used in this CharacterStream.
+ * @param string $charset
+ */
+ public function setCharacterSet($charset);
+
+ /**
+ * Set the CharacterReaderFactory for multi charset support.
+ * @param Swift_CharacterReaderFactory $factory
+ */
+ public function setCharacterReaderFactory(
+ Swift_CharacterReaderFactory $factory);
+
+ /**
+ * Overwrite this character stream using the byte sequence in the byte stream.
+ * @param Swift_OutputByteStream $os output stream to read from
+ */
+ public function importByteStream(Swift_OutputByteStream $os);
+
+ /**
+ * Import a string a bytes into this CharacterStream, overwriting any existing
+ * data in the stream.
+ * @param string $string
+ */
+ public function importString($string);
+
+ /**
+ * Read $length characters from the stream and move the internal pointer
+ * $length further into the stream.
+ * @param int $length
+ * @return string
+ */
+ public function read($length);
+
+ /**
+ * Read $length characters from the stream and return a 1-dimensional array
+ * containing there octet values.
+ * @param int $length
+ * @return int[]
+ */
+ public function readBytes($length);
+
+ /**
+ * Write $chars to the end of the stream.
+ * @param string $chars
+ */
+ public function write($chars);
+
+ /**
+ * Move the internal pointer to $charOffset in the stream.
+ * @param int $charOffset
+ */
+ public function setPointer($charOffset);
+
+ /**
+ * Empty the stream and reset the internal pointer.
+ */
+ public function flushContents();
+
+}
329 vendor/swift/classes/Swift/CharacterStream/ArrayCharacterStream.php
@@ -0,0 +1,329 @@
+<?php
+
+/*
+ CharacterStream implementation using an array in Swift Mailer.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ */
+
+//@require 'Swift/CharacterStream.php';
+//@require 'Swift/OutputByteStream.php';
+
+
+/**
+ * A CharacterStream implementation which stores characters in an internal array.
+ * @package Swift
+ * @subpackage CharacterStream
+ * @author Chris Corbyn
+ */
+class Swift_CharacterStream_ArrayCharacterStream
+ implements Swift_CharacterStream
+{
+
+ /** A map of byte values and their respective characters */
+ private static $_charMap;
+
+ /** A map of characters and their derivative byte values */
+ private static $_byteMap;
+
+ /** The char reader (lazy-loaded) for the current charset */
+ private $_charReader;
+
+ /** A factory for creatiing CharacterReader instances */
+ private $_charReaderFactory;
+
+ /** The character set this stream is using */
+ private $_charset;
+
+ /** Array of characters */
+ private $_array = array();
+
+ /** Size of the array of character */
+ private $_array_size = array();
+
+ /** The current character offset in the stream */
+ private $_offset = 0;
+
+ /**
+ * Create a new CharacterStream with the given $chars, if set.
+ * @param Swift_CharacterReaderFactory $factory for loading validators
+ * @param string $charset used in the stream
+ */
+ public function __construct(Swift_CharacterReaderFactory $factory,
+ $charset)
+ {
+ self::_initializeMaps();
+ $this->setCharacterReaderFactory($factory);
+ $this->setCharacterSet($charset);
+ }
+
+ /**
+ * Set the character set used in this CharacterStream.
+ * @param string $charset
+ */
+ public function setCharacterSet($charset)
+ {
+ $this->_charset = $charset;
+ $this->_charReader = null;
+ }
+
+ /**
+ * Set the CharacterReaderFactory for multi charset support.
+ * @param Swift_CharacterReaderFactory $factory
+ */
+ public function setCharacterReaderFactory(
+ Swift_CharacterReaderFactory $factory)
+ {
+ $this->_charReaderFactory = $factory;
+ }
+
+ /**
+ * Overwrite this character stream using the byte sequence in the byte stream.
+ * @param Swift_OutputByteStream $os output stream to read from
+ */
+ public function importByteStream(Swift_OutputByteStream $os)
+ {
+ if (!isset($this->_charReader))
+ {
+ $this->_charReader = $this->_charReaderFactory
+ ->getReaderFor($this->_charset);
+ }
+
+ $startLength = $this->_charReader->getInitialByteSize();
+ while (false !== $bytes = $os->read($startLength))
+ {
+ $c = array();
+ for ($i = 0, $len = strlen($bytes); $i < $len; ++$i)
+ {
+ $c[] = self::$_byteMap[$bytes[$i]];
+ }
+ $size = count($c);
+ $need = $this->_charReader
+ ->validateByteSequence($c, $size);
+ if ($need > 0 &&
+ false !== $bytes = $os->read($need))
+ {
+ for ($i = 0, $len = strlen($bytes); $i < $len; ++$i)
+ {
+ $c[] = self::$_byteMap[$bytes[$i]];
+ }
+ }
+ $this->_array[] = $c;
+ ++$this->_array_size;
+ }
+ }
+
+ /**
+ * Import a string a bytes into this CharacterStream, overwriting any existing
+ * data in the stream.
+ * @param string $string
+ */
+ public function importString($string)
+ {
+ $this->flushContents();
+ $this->write($string);
+ }
+
+ /**
+ * Read $length characters from the stream and move the internal pointer
+ * $length further into the stream.
+ * @param int $length
+ * @return string
+ */
+ public function read($length)
+ {
+ if ($this->_offset == $this->_array_size)
+ {
+ return false;
+ }
+
+ // Don't use array slice
+ $arrays = array();
+ $end = $length + $this->_offset;
+ for ($i = $this->_offset; $i < $end; ++$i)
+ {
+ if (!isset($this->_array[$i]))
+ {
+ break;
+ }
+ $arrays[] = $this->_array[$i];
+ }
+ $this->_offset += $i - $this->_offset; // Limit function calls
+ $chars = false;
+ foreach ($arrays as $array)
+ {
+ $chars .= implode('', array_map('chr', $array));
+ }
+ return $chars;
+ }
+
+ /**
+ * Read $length characters from the stream and return a 1-dimensional array
+ * containing there octet values.
+ * @param int $length
+ * @return int[]
+ */
+ public function readBytes($length)
+ {
+ if ($this->_offset == $this->_array_size)
+ {
+ return false;
+ }
+ $arrays = array();
+ $end = $length + $this->_offset;
+ for ($i = $this->_offset; $i < $end; ++$i)
+ {
+ if (!isset($this->_array[$i]))
+ {
+ break;
+ }
+ $arrays[] = $this->_array[$i];
+ }
+ $this->_offset += ($i - $this->_offset); // Limit function calls
+ return call_user_func_array('array_merge', $arrays);
+ }
+
+ /**
+ * Write $chars to the end of the stream.
+ * @param string $chars
+ */
+ public function write($chars)
+ {
+ if (!isset($this->_charReader))
+ {
+ $this->_charReader = $this->_charReaderFactory->getReaderFor(
+ $this->_charset);
+ }
+
+ $startLength = $this->_charReader->getInitialByteSize();
+
+ $fp = fopen('php://memory', 'w+b');
+ fwrite($fp, $chars);
+ unset($chars);
+ fseek($fp, 0, SEEK_SET);
+
+ $buffer = array(0);
+ $buf_pos = 1;
+ $buf_len = 1;
+ $has_datas = true;
+ do
+ {
+ $bytes = array();
+ // Buffer Filing
+ if ($buf_len - $buf_pos < $startLength)
+ {
+ $buf = array_splice($buffer, $buf_pos);
+ $new = $this->_reloadBuffer($fp, 100);
+ if ($new)
+ {
+ $buffer = array_merge($buf, $new);
+ $buf_len = count($buffer);
+ $buf_pos = 0;
+ }
+ else
+ {
+ $has_datas = false;
+ }
+ }
+ if ($buf_len - $buf_pos > 0)
+ {
+ $size = 0;
+ for ($i = 0; $i < $startLength && isset($buffer[$buf_pos]); ++$i)
+ {
+ ++$size;
+ $bytes[] = $buffer[$buf_pos++];
+ }
+ $need = $this->_charReader->validateByteSequence(
+ $bytes, $size);
+ if ($need > 0)
+ {
+ if ($buf_len - $buf_pos < $need)
+ {
+ $new = $this->_reloadBuffer($fp, $need);
+
+ if ($new)
+ {
+ $buffer = array_merge($buffer, $new);
+ $buf_len = count($buffer);
+ }
+ }
+ for ($i = 0; $i < $need && isset($buffer[$buf_pos]); ++$i)
+ {
+ $bytes[] = $buffer[$buf_pos++];
+ }
+ }
+ $this->_array[] = $bytes;
+ ++$this->_array_size;
+ }
+ }
+ while ($has_datas);
+
+ fclose($fp);
+ }
+
+ /**
+ * Move the internal pointer to $charOffset in the stream.
+ * @param int $charOffset
+ */
+ public function setPointer($charOffset)
+ {
+ if ($charOffset > $this->_array_size)
+ {
+ $charOffset = $this->_array_size;
+ }
+ elseif ($charOffset < 0)
+ {
+ $charOffset = 0;
+ }
+ $this->_offset = $charOffset;
+ }
+
+ /**
+ * Empty the stream and reset the internal pointer.
+ */
+ public function flushContents()
+ {
+ $this->_offset = 0;
+ $this->_array = array();
+ $this->_array_size = 0;
+ }
+
+ private function _reloadBuffer($fp, $len)
+ {
+ if (!feof($fp) && ($bytes = fread($fp, $len)) !== false)
+ {
+ $buf = array();
+ for ($i = 0, $len = strlen($bytes); $i < $len; ++$i)
+ {
+ $buf[] = self::$_byteMap[$bytes[$i]];
+ }
+ return $buf;
+ }
+ return false;
+ }
+
+ private static function _initializeMaps()
+ {
+ if (!isset(self::$_charMap))
+ {
+ self::$_charMap = array();
+ for ($byte = 0; $byte < 256; ++$byte)
+ {
+ self::$_charMap[$byte] = chr($byte);
+ }
+ self::$_byteMap = array_flip(self::$_charMap);
+ }
+ }
+}
359 vendor/swift/classes/Swift/DependencyContainer.php
@@ -0,0 +1,359 @@
+<?php
+
+/*
+ Dependency Injection container class Swift Mailer.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ */
+
+//@require 'Swift/DependencyException.php';
+
+/**
+ * Dependency Injection container.
+ * @package Swift
+ * @author Chris Corbyn
+ */
+class Swift_DependencyContainer
+{
+
+ /** Constant for literal value types */
+ const TYPE_VALUE = 0x0001;
+
+ /** Constant for new instance types */
+ const TYPE_INSTANCE = 0x0010;
+
+ /** Constant for shared instance types */
+ const TYPE_SHARED = 0x0100;
+
+ /** Constant for aliases */
+ const TYPE_ALIAS = 0x1000;
+
+ /** Singleton instance */
+ private static $_instance = null;
+
+ /** The data container */
+ private $_store = array();
+
+ /** The current endpoint in the data container */
+ private $_endPoint;
+
+ /**
+ * Constructor should not be used.
+ * Use {@link getInstance()} instead.
+ */
+ public function __construct() { }
+
+ /**
+ * Returns a singleton of the DependencyContainer.
+ * @return Swift_DependencyContainer
+ */
+ public static function getInstance()
+ {
+ if (!isset(self::$_instance))
+ {
+ self::$_instance = new self();
+ }
+ return self::$_instance;
+ }
+
+ /**
+ * List the names of all items stored in the Container.
+ * @return array
+ */
+ public function listItems()
+ {
+ return array_keys($this->_store);
+ }
+
+ /**
+ * Test if an item is registered in this container with the given name.
+ * @param string $itemName
+ * @return boolean
+ * @see register()
+ */
+ public function has($itemName)
+ {
+ return array_key_exists($itemName, $this->_store)
+ && isset($this->_store[$itemName]['lookupType']);
+ }
+
+ /**
+ * Lookup the item with the given $itemName.
+ * @param string $itemName
+ * @return mixed
+ * @throws Swift_DependencyException If the dependency is not found
+ * @see register()
+ */
+ public function lookup($itemName)
+ {
+ if (!$this->has($itemName))
+ {
+ throw new Swift_DependencyException(
+ 'Cannot lookup dependency "' . $itemName . '" since it is not registered.'
+ );
+ }
+
+ switch ($this->_store[$itemName]['lookupType'])
+ {
+ case self::TYPE_ALIAS:
+ return $this->_createAlias($itemName);
+ case self::TYPE_VALUE:
+ return $this->_getValue($itemName);
+ case self::TYPE_INSTANCE:
+ return $this->_createNewInstance($itemName);
+ case self::TYPE_SHARED:
+ return $this->_createSharedInstance($itemName);
+ }
+ }
+
+ /**
+ * Create an array of arguments passed to the constructor of $itemName.
+ * @param string $itemName
+ * @return array
+ */
+ public function createDependenciesFor($itemName)
+ {
+ $args = array();
+ if (isset($this->_store[$itemName]['args']))
+ {
+ $args = $this->_resolveArgs($this->_store[$itemName]['args']);
+ }
+ return $args;
+ }
+
+ /**
+ * Register a new dependency with $itemName.
+ * This method returns the current DependencyContainer instance because it
+ * requires the use of the fluid interface to set the specific details for the
+ * dependency.
+ *
+ * @param string $itemName
+ * @return Swift_DependencyContainer
+ * @see asNewInstanceOf(), asSharedInstanceOf(), asValue()
+ */
+ public function register($itemName)
+ {
+ $this->_store[$itemName] = array();
+ $this->_endPoint =& $this->_store[$itemName];
+ return $this;
+ }
+
+ /**
+ * Specify the previously registered item as a literal value.
+ * {@link register()} must be called before this will work.
+ *
+ * @param mixed $value
+ * @return Swift_DependencyContainer
+ */
+ public function asValue($value)
+ {
+ $endPoint =& $this->_getEndPoint();
+ $endPoint['lookupType'] = self::TYPE_VALUE;
+ $endPoint['value'] = $value;
+ return $this;
+ }
+
+ /**
+ * Specify the previously registered item as an alias of another item.
+ * @param string $lookup
+ * @return Swift_DependencyContainer
+ */
+ public function asAliasOf($lookup)
+ {
+ $endPoint =& $this->_getEndPoint();
+ $endPoint['lookupType'] = self::TYPE_ALIAS;
+ $endPoint['ref'] = $lookup;
+ return $this;
+ }
+
+ /**
+ * Specify the previously registered item as a new instance of $className.
+ * {@link register()} must be called before this will work.
+ * Any arguments can be set with {@link withDependencies()},
+ * {@link addConstructorValue()} or {@link addConstructorLookup()}.
+ *
+ * @param string $className
+ * @return Swift_DependencyContainer
+ * @see withDependencies(), addConstructorValue(), addConstructorLookup()
+ */
+ public function asNewInstanceOf($className)
+ {
+ $endPoint =& $this->_getEndPoint();
+ $endPoint['lookupType'] = self::TYPE_INSTANCE;
+ $endPoint['className'] = $className;
+ return $this;
+ }
+
+ /**
+ * Specify the previously registered item as a shared instance of $className.
+ * {@link register()} must be called before this will work.
+ * @param string $className
+ * @return Swift_DependencyContainer
+ */
+ public function asSharedInstanceOf($className)
+ {
+ $endPoint =& $this->_getEndPoint();
+ $endPoint['lookupType'] = self::TYPE_SHARED;
+ $endPoint['className'] = $className;
+ return $this;
+ }
+
+ /**
+ * Specify a list of injected dependencies for the previously registered item.
+ * This method takes an array of lookup names.
+ *
+ * @param array $lookups
+ * @return Swift_DependencyContainer
+ * @see addConstructorValue(), addConstructorLookup()
+ */
+ public function withDependencies(array $lookups)
+ {
+ $endPoint =& $this->_getEndPoint();
+ $endPoint['args'] = array();
+ foreach ($lookups as $lookup)
+ {
+ $this->addConstructorLookup($lookup);
+ }
+ return $this;
+ }
+
+ /**
+ * Specify a literal (non looked up) value for the constructor of the
+ * previously registered item.
+ *
+ * @param mixed $value
+ * @return Swift_DependencyContainer
+ * @see withDependencies(), addConstructorLookup()
+ */
+ public function addConstructorValue($value)
+ {
+ $endPoint =& $this->_getEndPoint();
+ if (!isset($endPoint['args']))
+ {
+ $endPoint['args'] = array();
+ }
+ $endPoint['args'][] = array('type' => 'value', 'item' => $value);
+ return $this;
+ }
+
+ /**
+ * Specify a dependency lookup for the constructor of the previously