Пример #1
0
 public function send()
 {
     //load swift class.
     require_once CLASSES_DIR . "Swift.php";
     Swift_ClassLoader::load("Swift_Connection_SMTP");
     // Create the message, and set the message subject.
     $message =& new Swift_Message($this->get('subject'));
     //create the html / text body
     $message->attach(new Swift_Message_Part($this->get('html_body'), "text/html"));
     $message->attach(new Swift_Message_Part($this->get('text_body'), "text/plain"));
     // Set the from address/name.
     $from =& new Swift_Address(EMAIL_USERNAME, EMAIL_NAME);
     // Create the recipient list.
     $recipients =& new Swift_RecipientList();
     // Add the recipient
     $recipients->addTo($this->get('to_email'), $this->get('to_name'));
     //connect and create mailer
     $smtp =& new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS);
     $smtp->setUsername(EMAIL_USERNAME);
     $smtp->setPassword(EMAIL_PASSWORD);
     $mailer = new Swift($smtp);
     // Attempt to send the email.
     try {
         $result = $mailer->send($message, $recipients, $from);
         $mailer->disconnect();
         $this->set('status', 'sent');
         $this->set('sent_date', date("Y-m-d H:i:s"));
         $this->save();
         return true;
     } catch (Swift_BadResponseException $e) {
         return $e->getMessage();
     }
 }
Пример #2
0
 /**
  * Return a new instance of the cache object
  * @return Swift_Cache
  */
 function &getCache()
 {
     $className = $GLOBALS["_SWIFT_CACHE_CLASS_"];
     Swift_ClassLoader::load($className);
     $instance =& new $className();
     return $instance;
 }
Пример #3
0
 /**
  * Return a new instance of the cache object
  * @return Swift_Cache
  */
 public static function getCache()
 {
     $className = self::$className;
     Swift_ClassLoader::load($className);
     $instance = new $className();
     return $instance;
 }
Пример #4
0
 /**
  * Write data to the cache
  * @param string The cache key
  * @param string The data to write
  */
 public function write($key, $data)
 {
     $handle = fopen(self::$save_path . "/" . $this->prefix . $key, "ab");
     if (false === fwrite($handle, $data)) {
         Swift_ClassLoader::load("Swift_FileException");
         throw new Swift_FileException("Disk Caching failed.  Tried to write to file at [" . self::$save_path . "/" . $this->prefix . $key . "] but failed.  Check the permissions, or don't use disk caching.");
     }
     fclose($handle);
 }
Пример #5
0
 /**
  * Constructor
  * @param mixed Swift_Authenticator_PopB4Smtp_Pop3Connection or string FQDN of POP3 server
  * @param int The remote port number
  * @param int The level of encryption to use
  */
 public function __construct($conn=null, $port=110, $encryption=0)
 {
   if (is_object($conn)) $this->connection = $conn;
   else
   {
     Swift_ClassLoader::load("Swift_Authenticator_PopB4Smtp_Pop3Connection");
     $this->connection = new Swift_Authenticator_PopB4Smtp_Pop3Connection($conn, $port, $encryption);
   }
 }
Пример #6
0
 /**
  * Constructor
  * @param mixed Swift_Authenticator_PopB4Smtp_Pop3Connection or string FQDN of POP3 server
  * @param int The remote port number
  * @param int The level of encryption to use
  */
 function Swift_Authenticator_PopB4Smtp($conn = null, $port = 110, $encryption = 0)
 {
     if (is_object($conn)) {
         $this->connection =& $conn;
     } else {
         Swift_ClassLoader::load("Swift_Authenticator_PopB4Smtp_Pop3Connection");
         $this->connection =& new Swift_Authenticator_PopB4Smtp_Pop3Connection($conn, $port, $encryption);
     }
 }
Пример #7
0
 /**
  * Write data to the cache
  * @param string The cache key
  * @param string The data to write
  */
 function write($key, $data)
 {
     $handle = @fopen($GLOBALS["_SWIFT_FILECACHE_SAVE_PATH_"] . "/" . $this->prefix . $key, "ab");
     if (false === $handle || false === fwrite($handle, $data)) {
         Swift_ClassLoader::load("Swift_FileException");
         Swift_ClassLoader::load("Swift_Errors");
         Swift_Errors::trigger(new Swift_FileException("Disk Caching failed.  Tried to write to file at [" . $GLOBALS["_SWIFT_FILECACHE_SAVE_PATH_"] . "/" . $this->prefix . $key . "] but failed.  Check the permissions, or don't use disk caching."));
         return;
     }
     fclose($handle);
 }
Пример #8
0
 /**
  * 邮件发送
  * @return boolean
  */
 public function send_mail($recipient, $mailsubject, $mailbody)
 {
     apf_require_file("Swift.php");
     Swift_ClassLoader::load("Swift_Connection_SMTP");
     $message = new Swift_Message($mailsubject);
     $message->setFrom("安居客<*****@*****.**>");
     $message->attach(new Swift_Message_Part(strip_tags($mailbody), "text/plain", "base64", "utf-8"));
     $message->attach(new Swift_Message_Part($mailbody, "text/html", "base64", "utf-8"));
     foreach ($recipient as $re) {
         Mail_Queue::put('*****@*****.**', $re, $mailsubject, $message, Const_Mail::TYPE_SWIFT, Const_Mail::TYPE_ID_COMMUNITY_SUBSCRIBE);
     }
     return true;
 }
Пример #9
0
 /**
  * Try to authenticate using the username and password
  * Returns false on failure
  * @param string The username
  * @param string The password
  * @param Swift The instance of Swift this authenticator is used in
  * @return boolean
  */
 function isAuthenticated($user, $pass, &$swift)
 {
     //The authorization string uses ascii null as a separator (See RFC 2554)
     $credentials = base64_encode($user . chr(0) . $user . chr(0) . $pass);
     Swift_ClassLoader::load("Swift_Errors");
     Swift_Errors::expect($e, "Swift_ConnectionException");
     $swift->command("AUTH PLAIN " . $credentials, 235);
     if ($e) {
         $swift->reset();
         return false;
     }
     Swift_Errors::clear("Swift_ConnectionException");
     return true;
 }
Пример #10
0
 /**
  * Try to authenticate using the username and password
  * Returns false on failure
  * @param string The username
  * @param string The password
  * @param Swift The instance of Swift this authenticator is used in
  * @return boolean
  */
 function isAuthenticated($user, $pass, &$swift)
 {
     Swift_ClassLoader::load("Swift_Errors");
     Swift_Errors::expect($e, "Swift_ConnectionException");
     $res =& $swift->command("AUTH CRAM-MD5", 334);
     if (!$e && instance_of($res, 'Swift_Events_ResponseEvent')) {
         $encoded_challenge = substr($res->getString(), 4);
         $challenge = base64_decode($encoded_challenge);
         $response = base64_encode($user . " " . $this->generateCRAMMD5Hash($pass, $challenge));
         $swift->command($response, 235);
     }
     if ($e !== null) {
         $swift->reset();
         return false;
     }
     Swift_Errors::clear("Swift_ConnectionException");
     return true;
 }
Пример #11
0
 /**
  * Constructor
  * @param mixed The data to use in the body
  * @param string Mime type
  * @param string The encoding format used
  * @param string The charset used
  */
 public function __construct($data = null, $type = "text/plain", $encoding = null, $charset = null)
 {
     parent::__construct();
     $this->setContentType($type);
     $this->setEncoding($encoding);
     $this->setCharset($charset);
     $this->setFlowed(false);
     if ($data !== null) {
         $this->setData($data);
         if ($charset === null) {
             Swift_ClassLoader::load("Swift_Message_Encoder");
             if (is_string($data) && Swift_Message_Encoder::instance()->isUTF8($data)) {
                 $this->setCharset("utf-8");
             } else {
                 $this->setCharset("iso-8859-1");
             }
             //The likely encoding
         }
     }
 }
Пример #12
0
 protected function sentMail($mailSubject, $mailBody)
 {
     if ($this->mailSwitch == true && !empty($this->mailAddress)) {
         $mailto = $this->mailAddress;
         apf_require_file("Swift.php");
         Swift_ClassLoader::load("Swift_Connection_SMTP");
         $smtpuser = APF::get_instance()->get_config("SmtpUser");
         $smtpemailto = $mailto;
         $message = new Swift_Message($mailSubject);
         $message->setFrom("安居客<" . $smtpuser . ">");
         $message->setTo($smtpemailto);
         $message->attach(new Swift_Message_Part(strip_tags($mailBody), "text/plain", "base64", "utf-8"));
         $message->attach(new Swift_Message_Part($mailBody, "text/html", "base64", "utf-8"));
         foreach ($smtpemailto as $to) {
             if (!empty($to)) {
                 @Mail_Queue::put($smtpuser, $to, $mailSubject, $message, Const_Mail::TYPE_SWIFT, Const_Mail::TYPE_ID_COMMUNITY_SUBSCRIBE);
             }
         }
     }
 }
Пример #13
0
 /**
  * Try to authenticate using the username and password
  * Returns false on failure
  * @param string The username
  * @param string The password
  * @param Swift The instance of Swift this authenticator is used in
  * @return boolean
  */
 function isAuthenticated($user, $pass, &$swift)
 {
     Swift_ClassLoader::load("Swift_Errors");
     Swift_Errors::expect($e, "Swift_ConnectionException");
     if (!$e) {
         $swift->command("AUTH LOGIN", 334);
     }
     if (!$e) {
         $swift->command(base64_encode($user), 334);
     }
     if (!$e) {
         $swift->command(base64_encode($pass), 235);
     }
     if ($e) {
         $swift->reset();
         return false;
     }
     Swift_Errors::clear("Swift_ConnectionException");
     return true;
 }
Пример #14
0
 /**
  * 发送邮件
  * @param $mailSubject 标题
  * @param $mailBody 内容
  * @param array $mailTo 接受人,数组
  * @return bool
  */
 public function sendMail($mailSubject, $mailBody, $mailTo = array())
 {
     if (empty($mailSubject) || empty($mailBody) || empty($mailTo)) {
         return false;
     }
     apf_require_file("Swift.php");
     Swift_ClassLoader::load("Swift_Connection_SMTP");
     $smtpuser = APF::get_instance()->get_config("SmtpUser");
     $smtpemailto = $mailTo;
     $message = new Swift_Message($mailSubject);
     $message->setFrom("安居客<" . $smtpuser . ">");
     $message->setTo($smtpemailto);
     $message->attach(new Swift_Message_Part(strip_tags($mailBody), "text/plain", "base64", "utf-8"));
     $message->attach(new Swift_Message_Part($mailBody, "text/html", "base64", "utf-8"));
     foreach ($smtpemailto as $to) {
         if (!empty($to)) {
             @Mail_Queue::put($smtpuser, $to, $mailSubject, $message, Const_Mail::TYPE_SWIFT, Const_Mail::TYPE_ID_COMMUNITY_SUBSCRIBE);
         }
     }
     return true;
 }
 public function go()
 {
     try {
         Swift_ClassLoader::load("Swift_Cache_Disk");
         Swift_Cache_Disk::setSavePath(TestConfiguration::WRITABLE_PATH);
         Swift_CacheFactory::setClassName("Swift_Cache_Disk");
         $swift = new Swift($this->getConnection(), null, Swift::ENABLE_LOGGING);
         $this->setSwiftInstance($swift);
         $message = new Swift_Message("Smoke Test 3 - Attachment");
         $message->attach(new Swift_Message_Part("This message contains an attachment"));
         $message->attach(new Swift_Message_Part("This message contains an <em>attachment</em>", "text/html"));
         $message->attach(new Swift_Message_Attachment(new Swift_File(dirname(__FILE__) . "/../files/cv.pdf"), "Authors_CV.pdf", "application/pdf"));
         $to = new Swift_Address(TestConfiguration::TO_ADDRESS, TestConfiguration::TO_NAME);
         $from = new Swift_Address(TestConfiguration::FROM_ADDRESS, TestConfiguration::FROM_NAME);
         $swift->send($message, $to, $from);
         $this->to = $to->build();
         $this->from = $from->build();
     } catch (Exception $e) {
         $this->failed = true;
         $this->setError($e->getMessage());
     }
     $this->render();
 }
 public function go()
 {
     try {
         Swift_ClassLoader::load("Swift_Cache_Disk");
         Swift_Cache_Disk::setSavePath(TestConfiguration::WRITABLE_PATH);
         Swift_CacheFactory::setClassName("Swift_Cache_Disk");
         $swift = new Swift($this->getConnection(), null, Swift::ENABLE_LOGGING);
         $this->setSwiftInstance($swift);
         $message = new Swift_Message("Smoke Test 5 - Embedded Image");
         $part = new Swift_Message_Part("\n        Here is an embedded image: <br />\n        <img src=\"" . $message->attach(new Swift_Message_Image(new Swift_File(dirname(__FILE__) . "/../files/manchester.jpeg"))) . "\" alt=\"image\" /><br />And here is the rest of the message.", "text/html");
         $message->attach($part);
         $message->attach(new Swift_Message_Part("You are viewing this message in plain text.  Switch to HTML mode to see the image.", "text/plain"));
         $to = new Swift_Address(TestConfiguration::TO_ADDRESS, TestConfiguration::TO_NAME);
         $from = new Swift_Address(TestConfiguration::FROM_ADDRESS, TestConfiguration::FROM_NAME);
         $swift->send($message, $to, $from);
         $this->to = $to->build();
         $this->from = $from->build();
     } catch (Exception $e) {
         $this->failed = true;
         $this->setError($e->getMessage());
     }
     $this->render();
 }
Пример #17
0
<?php

/**
 * Swift Mailer SMTP Connection component.
 * Please read the LICENSE file
 * @author Chris Corbyn <*****@*****.**>
 * @package Swift_Connection
 * @license GNU Lesser General Public License
 */
require_once dirname(__FILE__) . "/../ClassLoader.php";
Swift_ClassLoader::load("Swift_ConnectionBase");
Swift_ClassLoader::load("Swift_Authenticator");
/**
 * Swift SMTP Connection
 * @package Swift_Connection
 * @author Chris Corbyn <*****@*****.**>
 */
class Swift_Connection_SMTP extends Swift_ConnectionBase
{
    /**
     * Constant for TLS connections
     */
    const ENC_TLS = 2;
    /**
     * Constant for SSL connections
     */
    const ENC_SSL = 4;
    /**
     * Constant for unencrypted connections
     */
    const ENC_OFF = 8;
Пример #18
0
 /**
  * Return a 8bit string from a file
  * @param Swift_File The file stream to read from
  * @param int Max line length (including CRLF)
  * @param string The line ending
  * @return Swift_Cache_OutputStream
  * @throws Swift_FileException If the file cannot be read
  */
 public function encode8BitFile(Swift_File $file, $chunk = 76, $le = "\r\n")
 {
     Swift_ClassLoader::load("Swift_CacheFactory");
     $cache = Swift_CacheFactory::getCache();
     $ret = "";
     while (false !== ($bytes = $file->read(8192))) {
         $ret .= $bytes;
     }
     $cache->write("8b", $this->fixLE(wordwrap($ret, $chunk - 2, $le, 1), $le));
     return $cache->getOutputStream("8b");
 }
Пример #19
0
<?php

/**
 * Swift Mailer Message Decorating Plugin.
 * Please read the LICENSE file
 * @author Chris Corbyn <*****@*****.**>
 * @package Swift_Plugin
 * @subpackage Decorator
 * @license GNU Lesser General Public License
 */
require_once dirname(__FILE__) . "/../ClassLoader.php";
Swift_ClassLoader::load("Swift_Events_BeforeSendListener");
Swift_ClassLoader::load("Swift_Events_SendListener");
Swift_ClassLoader::load("Swift_Plugin_Decorator_Replacements");
/**
 * Swift Decorator Plugin.
 * Allows messages to be slightly different for each recipient.
 * @package Swift_Plugin
 * @subpackage Decorator
 * @author Chris Corbyn <*****@*****.**>
 */
class Swift_Plugin_Decorator implements Swift_Events_BeforeSendListener, Swift_Events_SendListener
{
    /**
     * The replacements object.
     * @var Swift_Plugin_Decorator_Replacements
     */
    protected $replacements;
    /**
     * Temporary storage so we can restore changes we make.
     * @var array
<?php

/**
 * EasySwift Response Tracker
 * Please read the LICENSE file
 * @copyright Chris Corbyn <*****@*****.**>
 * @author Chris Corbyn <*****@*****.**>
 * @package EasySwift
 * @license GNU Lesser General Public License
 */
require_once dirname(__FILE__) . "/../ClassLoader.php";
Swift_ClassLoader::load("Swift_Events_ResponseListener");
/**
 * EasySwift, Swift Response Tracker.
 * Updates properties in EasySwift when a response is received by Swift.
 * @package EasySwift
 * @author Chris Corbyn <*****@*****.**>
 */
class Swift_Plugin_EasySwiftResponseTracker implements Swift_Events_ResponseListener
{
    /**
     * The target object to update
     * @var EasySwift
     */
    protected $target = null;
    /**
     * Constructor
     * @param EasySwift The instance of EasySwift to run against
     */
    public function __construct($obj)
    {
Пример #21
0
<?php

/**
 * Swift Mailer Verbose-sending Plugin Default View File.
 * Please read the LICENSE file
 * @author Chris Corbyn <*****@*****.**>
 * @package Swift_Plugin
 * @subpackage VerboseSending
 * @license GNU Lesser General Public License
 */
require_once dirname(__FILE__) . "/../../ClassLoader.php";
Swift_ClassLoader::load("Swift_Plugin_VerboseSending_AbstractView");
/**
 * The Default View for the Verbose Sending Plugin
 * @package Swift_Plugin
 * @subpackage VerboseSending
 * @author Chris Corbyn <*****@*****.**>
 */
class Swift_Plugin_VerboseSending_DefaultView extends Swift_Plugin_VerboseSending_AbstractView
{
    /**
     * Number of recipients painted
     * @var int
     */
    protected $count = 0;
    /**
     * Paint the result of a send operation
     * @param string The email address that was tried
     * @param boolean True if the message was successfully sent
     */
    public function paintResult($address, $result)
<?php

/**
 * Swift Mailer Throttling Plugin.
 * Please read the LICENSE file
 * @author Chris Corbyn <*****@*****.**>
 * @package Swift_Plugin
 * @license GNU Lesser General Public License
 */
require_once dirname(__FILE__) . "/../ClassLoader.php";
Swift_ClassLoader::load("Swift_Plugin_BandwidthMonitor");
Swift_ClassLoader::load("Swift_Events_SendListener");
/**
 * Throttler plugin for Swift Mailer.
 * Restricts the speed at which Swift will operate.
 * @package Swift_Plugin
 * @author Chris Corbyn <*****@*****.**>
 */
class Swift_Plugin_Throttler extends Swift_Plugin_BandwidthMonitor implements Swift_Events_SendListener
{
    /**
     * The rate in byte-per-minute
     * @var int
     */
    protected $bpm = null;
    /**
     * The rate as emails-per-minute
     * @var int
     */
    protected $epm = null;
    /**
Пример #23
0
 /**
  * Build the list of attributes for appending to the given header
  * This is RFC 2231 & 2047 compliant.
  * A HUGE thanks to Joaquim Homrighausen for heaps of help, advice
  * and testing to get this working rock solid.
  * @param string The header built without attributes
  * @param string The lowercase name of the header
  * @return string
  * @throws Swift_Message_MimeException If no such header exists or there are no attributes
  */
 function buildAttributes($header_line, $header_name)
 {
     Swift_ClassLoader::load("Swift_Message_Encoder");
     $encoder =& Swift_Message_Encoder::instance();
     $lines = explode($this->LE, $header_line);
     $used_len = strlen($lines[count($lines) - 1]);
     $lines = null;
     $ret = "";
     foreach ($this->attributes[$header_name] as $attribute => $att_value) {
         if ($att_value === null) {
             continue;
         }
         // 70 to account for LWSP, CRLF, quotes and a semi-colon
         // + length of attribute
         // + 4 for a 2 digit number and 2 asterisks
         $avail_len = 70 - (strlen($attribute) + 4);
         $encoded = $encoder->rfc2047Encode($att_value, $this->charset, $this->language, $avail_len, $this->LE);
         $lines = explode($this->LE, $encoded);
         foreach ($lines as $i => $line) {
             //Add quotes if needed (RFC 2045)
             if (preg_match("~[\\s\";,<>\\(\\)@:\\\\/\\[\\]\\?=]~", $line)) {
                 $lines[$i] = '"' . $line . '"';
             }
         }
         $encoded = implode($this->LE, $lines);
         //If we can fit this entire attribute onto the same line as the header then do it!
         if (strlen($encoded) + $used_len + strlen($attribute) + 4 < 74) {
             if (strpos($encoded, "'") !== false) {
                 $attribute .= "*";
             }
             $append = "; " . $attribute . "=" . $encoded;
             $ret .= $append;
             $used_len += strlen($append);
         } else {
             $ret .= ";";
             if (count($lines) > 1) {
                 $loop = false;
                 $add_asterisk = false;
                 foreach ($lines as $i => $line) {
                     $att_copy = $attribute;
                     //Because it's multi-line it needs asterisks with decimal indices
                     $att_copy .= "*" . $i;
                     if ($add_asterisk || strpos($encoded, "'") !== false) {
                         $att_copy .= "*";
                         //And if it's got a ' then it needs another asterisk
                         $add_asterisk = true;
                     }
                     $append = "";
                     if ($loop) {
                         $append .= ";";
                     }
                     $append .= $this->LE . " " . $att_copy . "=" . $line;
                     $ret .= $append;
                     $used_len = strlen($append) + 1;
                     $loop = true;
                 }
             } else {
                 if (strpos($encoded, "'") !== false) {
                     $attribute .= "*";
                 }
                 $append = $this->LE . " " . $attribute . "=" . $encoded;
                 $used_len = strlen($append) + 1;
                 $ret .= $append;
             }
         }
         $lines = null;
     }
     return $ret;
 }
Пример #24
0
<?php

/**
 * Swift Connection Exception
 * Please read the LICENSE file
 * @copyright Chris Corbyn <*****@*****.**>
 * @author Chris Corbyn <*****@*****.**>
 * @package Swift_Connection
 * @license GNU Lesser General Public License
 */
require_once dirname(__FILE__) . "/ClassLoader.php";
Swift_ClassLoader::load("Swift_Exception");
/**
 * Swift Connection Exception
 * @package Swift_Connection
 * @author Chris Corbyn <*****@*****.**>
 */
class Swift_ConnectionException extends Swift_Exception
{
}
Пример #25
0
<?php

/**
 * Swift Mailer Default Logger
 * Please read the LICENSE file
 * @copyright Chris Corbyn <*****@*****.**>
 * @author Chris Corbyn <*****@*****.**>
 * @package Swift_Log
 * @license GNU Lesser General Public License
 */
require_once dirname(__FILE__) . "/../ClassLoader.php";
Swift_ClassLoader::load("Swift_Log");
/**
 * The Default Logger class
 * @package Swift_Log
 * @author Chris Corbyn <*****@*****.**>
 */
class Swift_Log_DefaultLog extends Swift_Log
{
    /**
     * Lines in the log
     * @var array
     */
    protected $entries = array();
    /**
     * Add a log entry
     * @param string The text for this entry
     * @param string The label for the type of entry
     */
    public function add($text, $type = self::NORMAL)
    {
Пример #26
0
 /**
  * A factory method to return an output stream object for the relevant location in the cache
  * @param string The cache key to fetch the stream for
  * @return Swift_Cache_OutputStream
  */
 public function getOutputStream($key)
 {
     Swift_ClassLoader::load("Swift_Cache_OutputStream");
     $os = new Swift_Cache_OutputStream($this, $key);
     return $os;
 }
Пример #27
0
<?php

/**
 * Swift Mailer mail() connection component
 * Please read the LICENSE file
 * @author Chris Corbyn <*****@*****.**>
 * @package Swift_Connection
 * @license GNU Lesser General Public License
 */
require_once dirname(__FILE__) . "/../ClassLoader.php";
Swift_ClassLoader::load("Swift_ConnectionBase");
Swift_ClassLoader::load("Swift_Plugin_MailSend");
/**
 * Swift mail() Connection
 * NOTE: This class is nothing more than a stub.  The MailSend plugin does the actual sending.
 * @package Swift_Connection
 * @author Chris Corbyn <*****@*****.**>
 */
class Swift_Connection_NativeMail extends Swift_ConnectionBase
{
    /**
     * The response the stub will be giving next
     * @var string Response
     */
    protected $response = "220 Stubbed";
    /**
     * The 5th parameter in mail() is a sprintf() formatted string.
     * @var string
     */
    protected $pluginParams;
    /**
Пример #28
0
Swift_ClassLoader::load("Swift_Events_SendListener");
Swift_ClassLoader::load("Swift_Events_BeforeCommandListener");
Swift_ClassLoader::load("Swift_Events_CommandListener");
Swift_ClassLoader::load("Swift_Events_ResponseListener");
Swift_ClassLoader::load("Swift_Events_ConnectListener");
Swift_ClassLoader::load("Swift_Events_DisconnectListener");
Swift_ClassLoader::load("Swift_Plugin_AntiFlood");
Swift_ClassLoader::load("Swift_Plugin_BandwidthMonitor");
Swift_ClassLoader::load("Swift_Plugin_Throttler");
Swift_ClassLoader::load("Swift_Plugin_VerboseSending");
Swift_ClassLoader::load("Swift_Plugin_ConnectionRotator");
Swift_ClassLoader::load("Swift_Plugin_Decorator");
Swift_ClassLoader::load("Swift_Message_Headers");
Swift_ClassLoader::load("Swift_CacheFactory");
Swift_ClassLoader::load("Swift_Log_DefaultLog");
Swift_ClassLoader::load("Swift_Message_Encoder");
Swift_ClassLoader::load("Swift_Cache_JointOutputStream");
require_once TestConfiguration::SWIFT_LIBRARY_PATH . "/Swift/Authenticator/@PopB4Smtp.php";
Swift_ClassLoader::load("Swift_Authenticator_PopB4Smtp_Pop3Connection");
require_once dirname(__FILE__) . "/AbstractTestWithSend.php";
require_once dirname(__FILE__) . "/AbstractTestOfCache.php";
require_once dirname(__FILE__) . "/AbstractTestOfAuthenticator.php";
require_once dirname(__FILE__) . "/stubs/MimeExtension.php";
require_once dirname(__FILE__) . "/stubs/DummyConnection.php";
Mock::Generate("DummyConnection", "FullMockConnection");
Mock::Generate("Swift_Connection_Rotator", "MockRotatorConnection");
Mock::Generate("Swift_Message", "MockMessage");
Mock::Generate("Swift_Events_SendListener", "MockSendListener");
Mock::Generate("Swift_Connection_SMTP", "MockSMTPConnection");
Mock::GeneratePartial("Swift_Connection_SMTP", "MockSMTPConnectionAuth", array("read", "write", "isAlive", "start", "stop"));
Mock::Generate("Swift_Message_Headers", "MockHeaders");
Пример #29
0
 /**
  * Send a message to any number of recipients
  * @param Swift_Message The message to send.  This does not need to (and shouldn't really) have any of the recipient headers set.
  * @param mixed The recipients to send to.  Can be a string, Swift_Address or Swift_RecipientList. Note that all addresses apart from Bcc recipients will appear in the message headers
  * @param mixed The address to send the message from.  Can either be a string or an instance of Swift_Address.
  * @return int The number of successful recipients
  * @throws Swift_ConnectionException If sending fails for any reason.
  */
 public function send(Swift_Message $message, $recipients, $from)
 {
     Swift_ClassLoader::load("Swift_Message_Encoder");
     if (is_string($recipients) && preg_match("/^" . Swift_Message_Encoder::CHEAP_ADDRESS_RE . "\$/", $recipients)) {
         $recipients = new Swift_Address($recipients);
     } elseif (!$recipients instanceof Swift_AddressContainer) {
         throw new Exception("The recipients parameter must either be a valid string email address, " . "an instance of Swift_RecipientList or an instance of Swift_Address.");
     }
     if (is_string($from) && preg_match("/^" . Swift_Message_Encoder::CHEAP_ADDRESS_RE . "\$/", $from)) {
         $from = new Swift_Address($from);
     } elseif (!$from instanceof Swift_Address) {
         throw new Exception("The sender parameter must either be a valid string email address or " . "an instance of Swift_Address.");
     }
     $log = Swift_LogContainer::getLog();
     if (!$message->getEncoding() && !$this->connection->hasExtension("8BITMIME")) {
         $message->setEncoding("QP", true, true);
     }
     $list = $recipients;
     if ($recipients instanceof Swift_Address) {
         $list = new Swift_RecipientList();
         $list->addTo($recipients);
     }
     Swift_ClassLoader::load("Swift_Events_SendEvent");
     $send_event = new Swift_Events_SendEvent($message, $list, $from, 0);
     $this->notifyListeners($send_event, "BeforeSendListener");
     $to = $cc = array();
     if (!($has_from = $message->getFrom())) {
         $message->setFrom($from);
     }
     if (!($has_return_path = $message->getReturnPath())) {
         $message->setReturnPath($from->build(true));
     }
     if (!($has_reply_to = $message->getReplyTo())) {
         $message->setReplyTo($from);
     }
     if (!$has_reply_to[0]) {
         $message->setReplyTo($from->getAddress());
     }
     if (!($has_message_id = $message->getId())) {
         $message->generateId();
     }
     $this->command("MAIL FROM: " . $message->getReturnPath(true), 250);
     $failed = 0;
     $sent = 0;
     $tmp_sent = 0;
     $it = $list->getIterator("to");
     while ($it->hasNext()) {
         $it->next();
         $address = $it->getValue();
         $to[] = $address->build();
         try {
             $this->command("RCPT TO: " . $address->build(true), 250);
             $tmp_sent++;
         } catch (Swift_BadResponseException $e) {
             $failed++;
             $send_event->addFailedRecipient($address->getAddress());
             if ($log->hasLevel(Swift_Log::LOG_FAILURES)) {
                 $log->addfailedRecipient($address->getAddress());
             }
         }
     }
     $it = $list->getIterator("cc");
     while ($it->hasNext()) {
         $it->next();
         $address = $it->getValue();
         $cc[] = $address->build();
         try {
             $this->command("RCPT TO: " . $address->build(true), 250);
             $tmp_sent++;
         } catch (Swift_BadResponseException $e) {
             $failed++;
             $send_event->addFailedRecipient($address->getAddress());
             if ($log->hasLevel(Swift_Log::LOG_FAILURES)) {
                 $log->addfailedRecipient($address->getAddress());
             }
         }
     }
     if ($failed == count($to) + count($cc)) {
         $this->reset();
         $this->notifyListeners($send_event, "SendListener");
         return 0;
     }
     if (!($has_to = $message->getTo()) && !empty($to)) {
         $message->setTo($to);
     }
     if (!($has_cc = $message->getCc()) && !empty($cc)) {
         $message->setCc($cc);
     }
     $this->command("DATA", 354);
     $data = $message->build();
     while (false !== ($bytes = $data->read())) {
         $this->command($bytes, -1);
     }
     if ($log->hasLevel(Swift_Log::LOG_NETWORK)) {
         $log->add("<MESSAGE DATA>", Swift_Log::COMMAND);
     }
     try {
         $this->command("\r\n.", 250);
         $sent += $tmp_sent;
     } catch (Swift_BadResponseException $e) {
         $failed += $tmp_sent;
     }
     $tmp_sent = 0;
     $has_bcc = $message->getBcc();
     $it = $list->getIterator("bcc");
     while ($it->hasNext()) {
         $it->next();
         $address = $it->getValue();
         if (!$has_bcc) {
             $message->setBcc($address->build());
         }
         try {
             $this->command("MAIL FROM: " . $message->getReturnPath(true), 250);
             $this->command("RCPT TO: " . $address->build(true), 250);
             $this->command("DATA", 354);
             $data = $message->build();
             while (false !== ($bytes = $data->read())) {
                 $this->command($bytes, -1);
             }
             if ($log->hasLevel(Swift_Log::LOG_NETWORK)) {
                 $log->add("<MESSAGE DATA>", Swift_Log::COMMAND);
             }
             $this->command("\r\n.", 250);
             $sent++;
         } catch (Swift_BadResponseException $e) {
             $failed++;
             $send_event->addFailedRecipient($address->getAddress());
             if ($log->hasLevel(Swift_Log::LOG_FAILURES)) {
                 $log->addfailedRecipient($address->getAddress());
             }
             $this->reset();
         }
     }
     $total = count($to) + count($cc) + count($list->getBcc());
     $send_event->setNumSent($sent);
     $this->notifyListeners($send_event, "SendListener");
     if (!$has_return_path) {
         $message->setReturnPath("");
     }
     if (!$has_from) {
         $message->setFrom("");
     }
     if (!$has_to) {
         $message->setTo("");
     }
     if (!$has_reply_to) {
         $message->setReplyTo(null);
     }
     if (!$has_cc) {
         $message->setCc(null);
     }
     if (!$has_bcc) {
         $message->setBcc(null);
     }
     if (!$has_message_id) {
         $message->setId(null);
     }
     if ($log->hasLevel(Swift_Log::LOG_NETWORK)) {
         $log->add("Message sent to " . $sent . "/" . $total . " recipients", Swift_Log::NORMAL);
     }
     return $sent;
 }
Пример #30
0
 /**
  * FUNCTION: _sendMail
  *
  * Proccesses all headers and attachments ready for sending.
  *
  * @access private
  */
 function _sendMail()
 {
     $message = new Swift_Message($this->subject);
     if (empty($this->sendto) and (empty($this->body) and empty($this->htmlbody))) {
         vlibMimeMailError::raiseError('VM_ERROR_CANNOT_SEND', FATAL);
     }
     // Attachments
     for ($index = 0; $index < sizeof($this->attachments); $index++) {
         $message->attach(new Swift_Message_Attachment(new Swift_File($this->attachments[$index]), $this->attachments[$index], $this->mimetypes[$index]));
     }
     // ReplyTo if exists
     if (!empty($this->replyToEmail)) {
         $message->setReplyTo(new Swift_Address($this->replyToEmail, $this->replyToName));
     }
     // attach body if exist
     if (!empty($this->body)) {
         if (empty($this->htmlbody) and sizeof($this->attachments) == 0) {
             $message->setData($this->body);
             Swift_ClassLoader::load('Swift_Message_Encoder');
             if (Swift_Message_Encoder::instance()->isUTF8($this->body)) {
                 $message->setCharset('utf-8');
             } else {
                 $message->setCharset('iso-8859-1');
             }
         } else {
             $message->attach(new Swift_Message_Part($this->body, 'text/plain'));
         }
     }
     // attach HTML body if exist
     if (!empty($this->htmlbody)) {
         $message->attach(new Swift_Message_Part($this->htmlbody, 'text/html'));
     }
     return $this->swift->send($message, $this->swift_recipients, new Swift_Address($this->fromEmail, $this->fromName));
 }