Permalink
Browse files

Basic port of 2.3.x email helper

  • Loading branch information...
0 parents commit 5af87eb663fa2fef9125eced61340494a65eb7ee @banks banks committed Aug 29, 2009
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
@@ -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
@@ -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
+);
@@ -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);
+ }
+ }
+
+}
@@ -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
+ );
+ }
+
+}
Oops, something went wrong.

0 comments on commit 5af87eb

Please sign in to comment.