当前位置: 首页>>代码示例>>PHP>>正文


PHP Swift::attachPlugin方法代码示例

本文整理汇总了PHP中Swift::attachPlugin方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift::attachPlugin方法的具体用法?PHP Swift::attachPlugin怎么用?PHP Swift::attachPlugin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Swift的用法示例。


在下文中一共展示了Swift::attachPlugin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadPlugin

 /**
  * Add a new plugin to respond to events
  * @param Swift_Events_Listener The plugin to load
  * @param string The ID to identify the plugin by if needed
  * @return string The ID of the plugin
  */
 function loadPlugin(&$plugin, $name = null)
 {
     $this->pluginCount++;
     if (!$name) {
         $name = "p" . $this->pluginCount;
     }
     $this->swift->attachPlugin($plugin, $name);
     return $name;
 }
开发者ID:jeffthestampede,项目名称:excelsior,代码行数:15,代码来源:EasySwift.php

示例2: loadPlugin

 /**
  * Add a new plugin to respond to events
  * @param Swift_Events_Listener The plugin to load
  * @param string The ID to identify the plugin by if needed
  * @return string The ID of the plugin
  */
 public function loadPlugin(Swift_Events_Listener $plugin, $name = null)
 {
     $this->pluginCount++;
     if (!$name) {
         $name = "p" . $this->pluginCount;
     }
     $this->swift->attachPlugin($plugin, $name);
     return $name;
 }
开发者ID:darkcolonist,项目名称:kohana234-doctrine115,代码行数:15,代码来源:EasySwift.php

示例3: testWaitingTimeIsHonoured

 /**
  * Tests that the sleep() time is used if it's set.
  */
 public function testWaitingTimeIsHonoured()
 {
     $conn = $this->getWorkingMockConnection(20, null, 5);
     $swift = new Swift($conn);
     $plugin = new MockAntiFloodPlugin();
     $plugin->setWait(10);
     $plugin->setThreshold(5);
     $plugin->expect("wait", array(10));
     $swift->attachPlugin($plugin, "antiflood");
     for ($i = 0; $i < 20; $i++) {
         $swift->send(new Swift_Message("foo", "bar"), new Swift_Address("foo@bar.com"), new Swift_Address("foo@bar.com"));
     }
 }
开发者ID:Esleelkartea,项目名称:legedia-ESLE,代码行数:16,代码来源:TestOfAntiFloodPlugin.php

示例4: testThresholdIsHonouredBeforeRotating

 /**
  * Test that the number of emails (threshold) can be set.
  */
 public function testThresholdIsHonouredBeforeRotating()
 {
     $plugin = new Swift_Plugin_ConnectionRotator();
     $conn = $this->getWorkingMockConnection(20, new MockRotatorConnection(), 6, 2);
     $conn->expectCallCount("nextConnection", 3);
     $conn->setReturnValueAt(0, "getActive", 0);
     $conn->setReturnValueAt(1, "getActive", 1);
     $conn->setReturnValueAt(2, "getActive", 2);
     $swift = new Swift($conn);
     $swift->attachPlugin(new Swift_Plugin_ConnectionRotator(6), "foo");
     for ($i = 0; $i < 20; $i++) {
         $swift->send(new Swift_Message("subject", "body"), new Swift_Address("foo@bar.tld"), new Swift_Address("zip@button.com"));
     }
 }
开发者ID:Esleelkartea,项目名称:legedia-ESLE,代码行数:17,代码来源:TestOfConnectionRotatorPlugin.php

示例5: testBytesCanBeReset

 /**
  * The counters should be settable through setBytesIn() and setBytesOut().
  */
 public function testBytesCanBeReset()
 {
     $conn = new FullMockConnection();
     //7 chars + 2 for EOL
     $conn->setReturnValueAt(0, "read", "250 foo");
     //15 chars + 2 for EOL
     $conn->setReturnValueAt(1, "read", "221 bye for now");
     $swift = new Swift($conn, null, Swift::NO_START);
     $plugin = new Swift_Plugin_BandwidthMonitor();
     $swift->attachPlugin($plugin, "bwmon");
     //20 chars + 2 for EOL
     $swift->command("abcdefghijklm 123456");
     $this->assertEqual(22, $plugin->getBytesOut());
     $this->assertEqual(9, $plugin->getBytesIn());
     $plugin->setBytesOut(0);
     $this->assertEqual(0, $plugin->getBytesOut());
     //3 chars + 2 for EOL
     $swift->command("bar");
     $this->assertEqual(5, $plugin->getBytesOut());
     $this->assertEqual(26, $plugin->getBytesIn());
     $plugin->setBytesIn(0);
     $this->assertEqual(0, $plugin->getBytesIn());
 }
开发者ID:Esleelkartea,项目名称:legedia-ESLE,代码行数:26,代码来源:TestOfBandwidthMonitorPlugin.php

示例6: postConnect

 /**
  * Sets the MailSend plugin in Swift once Swift has connected
  * @param Swift The current instance of Swift
  */
 public function postConnect(Swift $instance)
 {
     $this->plugin = new Swift_Plugin_MailSend($this->getAdditionalMailParams());
     $instance->attachPlugin($this->plugin, "_MAIL_SEND");
 }
开发者ID:dev-lav,项目名称:htdocs,代码行数:9,代码来源:NativeMail.php

示例7: Send

 public static function Send($id_lang, $template, $subject, $templateVars, $to, $toName = NULL, $from = NULL, $fromName = NULL, $fileAttachment = NULL, $modeSMTP = NULL, $templatePath = _PS_MAIL_DIR_)
 {
     $configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME', 'PS_MAIL_SMTP_ENCRYPTION', 'PS_MAIL_SMTP_PORT', 'PS_MAIL_METHOD', 'PS_MAIL_TYPE'));
     if (!isset($configuration['PS_MAIL_SMTP_ENCRYPTION'])) {
         $configuration['PS_MAIL_SMTP_ENCRYPTION'] = "off";
     }
     if (!isset($configuration['PS_MAIL_SMTP_PORT'])) {
         $configuration['PS_MAIL_SMTP_PORT'] = "default";
     }
     if (!isset($from)) {
         $from = $configuration['PS_SHOP_EMAIL'];
     }
     if (!isset($fromName)) {
         $fromName = $configuration['PS_SHOP_NAME'];
     }
     if (!empty($from) and !Validate::isEmail($from) or !empty($fromName) and !Validate::isMailName($fromName) or !is_array($to) and !Validate::isEmail($to) or !empty($toName) and !Validate::isMailName($toName) or !is_array($templateVars) or !Validate::isTplName($template) or !Validate::isMailSubject($subject)) {
         die(Tools::displayError('Error: mail parameters are corrupted'));
     }
     /* Construct multiple recipients list if needed */
     if (is_array($to)) {
         $to_list = new Swift_RecipientList();
         foreach ($to as $key => $addr) {
             $to_name = NULL;
             $addr = trim($addr);
             if (!Validate::isEmail($addr)) {
                 die(Tools::displayError('Error: mail parameters are corrupted'));
             }
             if ($toName and is_array($toName) and Validate::isGenericName($toName[$key])) {
                 $to_name = $toName[$key];
             }
             $to_list->addTo($addr, $to_name);
         }
         $to_plugin = $to[0];
         $to = $to_list;
     } else {
         /* Simple recipient, one address */
         $to_plugin = $to;
         $to = new Swift_Address($to, $toName);
     }
     try {
         /* Connect with the appropriate configuration */
         if (intval($configuration['PS_MAIL_METHOD']) == 2) {
             $connection = new Swift_Connection_SMTP($configuration['PS_MAIL_SERVER'], $configuration['PS_MAIL_SMTP_PORT'], $configuration['PS_MAIL_SMTP_ENCRYPTION'] == "ssl" ? Swift_Connection_SMTP::ENC_SSL : ($configuration['PS_MAIL_SMTP_ENCRYPTION'] == "tls" ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_OFF));
             $connection->setTimeout(4);
             if (!$connection) {
                 return false;
             }
             if (!empty($configuration['PS_MAIL_USER']) and !empty($configuration['PS_MAIL_PASSWD'])) {
                 $connection->setUsername($configuration['PS_MAIL_USER']);
                 $connection->setPassword($configuration['PS_MAIL_PASSWD']);
             }
         } else {
             $connection = new Swift_Connection_NativeMail();
         }
         if (!$connection) {
             return false;
         }
         $swift = new Swift($connection);
         /* Get templates content */
         $iso = Language::getIsoById(intval($id_lang));
         if (!$iso) {
             die(Tools::displayError('Error - No iso code for email !'));
         }
         $template = $iso . '/' . $template;
         if (!file_exists($templatePath . $template . '.txt') or !file_exists($templatePath . $template . '.html')) {
             die(Tools::displayError('Error - The following email template is missing:') . ' ' . $templatePath . $template . '.txt');
         }
         $templateHtml = file_get_contents($templatePath . $template . '.html');
         $templateTxt = strip_tags(html_entity_decode(file_get_contents($templatePath . $template . '.txt'), NULL, 'utf-8'));
         include_once dirname(__FILE__) . '/../mails/' . $iso . '/lang.php';
         global $_LANGMAIL;
         /* Create mail and attach differents parts */
         $message = new Swift_Message('[' . Configuration::get('PS_SHOP_NAME') . '] ' . ((is_array($_LANGMAIL) and key_exists($subject, $_LANGMAIL)) ? $_LANGMAIL[$subject] : $subject));
         $templateVars['{shop_logo}'] = file_exists(_PS_IMG_DIR_ . 'logo.jpg') ? $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_ . 'logo.jpg'))) : '';
         $templateVars['{shop_name}'] = htmlentities(Configuration::get('PS_SHOP_NAME'), NULL, 'utf-8');
         $templateVars['{shop_url}'] = 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__;
         $swift->attachPlugin(new Swift_Plugin_Decorator(array($to_plugin => $templateVars)), 'decorator');
         if ($configuration['PS_MAIL_TYPE'] == 3 or $configuration['PS_MAIL_TYPE'] == 2) {
             $message->attach(new Swift_Message_Part($templateTxt, 'text/plain', '8bit', 'utf-8'));
         }
         if ($configuration['PS_MAIL_TYPE'] == 3 or $configuration['PS_MAIL_TYPE'] == 1) {
             $message->attach(new Swift_Message_Part($templateHtml, 'text/html', '8bit', 'utf-8'));
         }
         if ($fileAttachment and isset($fileAttachment['content']) and isset($fileAttachment['name']) and isset($fileAttachment['mime'])) {
             $message->attach(new Swift_Message_Attachment($fileAttachment['content'], $fileAttachment['name'], $fileAttachment['mime']));
         }
         /* Send mail */
         $send = $swift->send($message, $to, new Swift_Address($from, $fromName));
         $swift->disconnect();
         return $send;
     } catch (Swift_ConnectionException $e) {
         return false;
     }
 }
开发者ID:sealence,项目名称:local,代码行数:94,代码来源:Mail.php

示例8: Send


//.........这里部分代码省略.........
         if ($configuration['PS_MAIL_METHOD'] == 2) {
             if (empty($configuration['PS_MAIL_SERVER']) || empty($configuration['PS_MAIL_SMTP_PORT'])) {
                 Tools::dieOrLog(Tools::displayError('Error: invalid SMTP server or SMTP port'), $die);
                 return false;
             }
             $connection = new Swift_Connection_SMTP($configuration['PS_MAIL_SERVER'], $configuration['PS_MAIL_SMTP_PORT'], $configuration['PS_MAIL_SMTP_ENCRYPTION'] == 'ssl' ? Swift_Connection_SMTP::ENC_SSL : ($configuration['PS_MAIL_SMTP_ENCRYPTION'] == 'tls' ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_OFF));
             $connection->setTimeout(4);
             if (!$connection) {
                 return false;
             }
             if (!empty($configuration['PS_MAIL_USER'])) {
                 $connection->setUsername($configuration['PS_MAIL_USER']);
             }
             if (!empty($configuration['PS_MAIL_PASSWD'])) {
                 $connection->setPassword($configuration['PS_MAIL_PASSWD']);
             }
         } else {
             $connection = new Swift_Connection_NativeMail();
         }
         if (!$connection) {
             return false;
         }
         $swift = new Swift($connection, Configuration::get('PS_MAIL_DOMAIN'));
         /* Get templates content */
         $iso = Language::getIsoById((int) $id_lang);
         if (!$iso) {
             Tools::dieOrLog(Tools::displayError('Error - No ISO code for email'), $die);
             return false;
         }
         $template = $iso . '/' . $template;
         $module_name = false;
         $override_mail = false;
         // get templatePath
         if (preg_match('#' . __PS_BASE_URI__ . 'modules/#', $template_path) && preg_match('#modules/([a-z0-9_-]+)/#ui', $template_path, $res)) {
             $module_name = $res[1];
         }
         if ($module_name !== false && (file_exists($theme_path . 'modules/' . $module_name . '/mails/' . $template . '.txt') || file_exists($theme_path . 'modules/' . $module_name . '/mails/' . $template . '.html'))) {
             $template_path = $theme_path . 'modules/' . $module_name . '/mails/';
         } else {
             if (file_exists($theme_path . 'mails/' . $template . '.txt') || file_exists($theme_path . 'mails/' . $template . '.html')) {
                 $template_path = $theme_path . 'mails/';
                 $override_mail = true;
             } else {
                 if (!file_exists($template_path . $template . '.txt') || !file_exists($template_path . $template . '.html')) {
                     Tools::dieOrLog(Tools::displayError('Error - The following e-mail template is missing:') . ' ' . $template_path . $template . '.txt', $die);
                     return false;
                 }
             }
         }
         $template_html = file_get_contents($template_path . $template . '.html');
         $template_txt = strip_tags(html_entity_decode(file_get_contents($template_path . $template . '.txt'), null, 'utf-8'));
         if ($override_mail && file_exists($template_path . $iso . '/lang.php')) {
             include_once $template_path . $iso . '/lang.php';
         } else {
             if ($module_name && file_exists($template_path . $iso . '/lang.php')) {
                 include_once $theme_path . 'mails/' . $iso . '/lang.php';
             } else {
                 include_once dirname(__FILE__) . '/../mails/' . $iso . '/lang.php';
             }
         }
         /* Create mail and attach differents parts */
         $message = new Swift_Message('[' . Configuration::get('PS_SHOP_NAME') . '] ' . $subject);
         $message->headers->setEncoding('Q');
         if (Configuration::get('PS_LOGO_MAIL') !== false && file_exists(_PS_IMG_DIR_ . Configuration::get('PS_LOGO_MAIL'))) {
             $template_vars['{shop_logo}'] = $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_ . Configuration::get('PS_LOGO_MAIL'))));
         } else {
             if (file_exists(_PS_IMG_DIR_ . 'logo.jpg')) {
                 $template_vars['{shop_logo}'] = $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_ . Configuration::get('PS_LOGO'))));
             } else {
                 $template_vars['{shop_logo}'] = '';
             }
         }
         $template_vars['{shop_name}'] = Tools::safeOutput(Configuration::get('PS_SHOP_NAME'));
         $template_vars['{shop_url}'] = Tools::getShopDomain(true, true) . __PS_BASE_URI__ . 'index.php';
         $swift->attachPlugin(new Swift_Plugin_Decorator(array($to_plugin => $template_vars)), 'decorator');
         if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_TEXT) {
             $message->attach(new Swift_Message_Part($template_txt, 'text/plain', '8bit', 'utf-8'));
         }
         if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_HTML) {
             $message->attach(new Swift_Message_Part($template_html, 'text/html', '8bit', 'utf-8'));
         }
         if ($file_attachment && !empty($file_attachment)) {
             // Multiple attachments?
             if (!is_array(current($file_attachment))) {
                 $file_attachment = array($file_attachment);
             }
             foreach ($file_attachment as $attachment) {
                 if (isset($attachment['content']) && isset($attachment['name']) && isset($attachment['mime'])) {
                     $message->attach(new Swift_Message_Attachment($attachment['content'], $attachment['name'], $attachment['mime']));
                 }
             }
         }
         /* Send mail */
         $send = $swift->send($message, $to, new Swift_Address($from, $from_name));
         $swift->disconnect();
         return $send;
     } catch (Swift_Exception $e) {
         return false;
     }
 }
开发者ID:jicheng17,项目名称:vipinsg,代码行数:101,代码来源:Mail.php

示例9: Send


//.........这里部分代码省略.........
         /* Get templates content */
         $iso = Language::getIsoById((int) $id_lang);
         if (!$iso) {
             Tools::dieOrLog(Tools::displayError('Error - No ISO code for email'), $die);
             return false;
         }
         $template = $iso . '/' . $template;
         $module_name = false;
         $override_mail = false;
         // get templatePath
         if (preg_match('#' . __PS_BASE_URI__ . 'modules/#', str_replace(DIRECTORY_SEPARATOR, '/', $template_path)) && preg_match('#modules/([a-z0-9_-]+)/#ui', str_replace(DIRECTORY_SEPARATOR, '/', $template_path), $res)) {
             $module_name = $res[1];
         }
         if ($module_name !== false && (file_exists($theme_path . 'modules/' . $module_name . '/mails/' . $template . '.txt') || file_exists($theme_path . 'modules/' . $module_name . '/mails/' . $template . '.html'))) {
             $template_path = $theme_path . 'modules/' . $module_name . '/mails/';
         } elseif (file_exists($theme_path . 'mails/' . $template . '.txt') || file_exists($theme_path . 'mails/' . $template . '.html')) {
             $template_path = $theme_path . 'mails/';
             $override_mail = true;
         }
         if (!file_exists($template_path . $template . '.txt') && ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_TEXT)) {
             Tools::dieOrLog(Tools::displayError('Error - The following e-mail template is missing:') . ' ' . $template_path . $template . '.txt', $die);
             return false;
         } else {
             if (!file_exists($template_path . $template . '.html') && ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_HTML)) {
                 Tools::dieOrLog(Tools::displayError('Error - The following e-mail template is missing:') . ' ' . $template_path . $template . '.html', $die);
                 return false;
             }
         }
         $template_html = file_get_contents($template_path . $template . '.html');
         $template_txt = strip_tags(html_entity_decode(file_get_contents($template_path . $template . '.txt'), null, 'utf-8'));
         if ($override_mail && file_exists($template_path . $iso . '/lang.php')) {
             include_once $template_path . $iso . '/lang.php';
         } else {
             if ($module_name && file_exists($theme_path . 'mails/' . $iso . '/lang.php')) {
                 include_once $theme_path . 'mails/' . $iso . '/lang.php';
             } else {
                 if (file_exists(_PS_MAIL_DIR_ . $iso . '/lang.php')) {
                     include_once _PS_MAIL_DIR_ . $iso . '/lang.php';
                 } else {
                     Tools::dieOrLog(Tools::displayError('Error - The lang file is missing for :') . ' ' . $iso, $die);
                     return false;
                 }
             }
         }
         /* Create mail and attach differents parts */
         $message = new Swift_Message('[' . Configuration::get('PS_SHOP_NAME', null, null, $id_shop) . '] ' . $subject);
         $message->setCharset('utf-8');
         /* Set Message-ID - getmypid() is blocked on some hosting */
         $message->setId(Mail::generateId());
         $message->headers->setEncoding('Q');
         if (Configuration::get('PS_LOGO_MAIL') !== false && file_exists(_PS_IMG_DIR_ . Configuration::get('PS_LOGO_MAIL', null, null, $id_shop))) {
             $logo = _PS_IMG_DIR_ . Configuration::get('PS_LOGO_MAIL', null, null, $id_shop);
         } else {
             if (file_exists(_PS_IMG_DIR_ . Configuration::get('PS_LOGO', null, null, $id_shop))) {
                 $logo = _PS_IMG_DIR_ . Configuration::get('PS_LOGO', null, null, $id_shop);
             } else {
                 $template_vars['{shop_logo}'] = '';
             }
         }
         ShopUrl::cacheMainDomainForShop((int) $id_shop);
         /* don't attach the logo as */
         if (isset($logo)) {
             $template_vars['{shop_logo}'] = $message->attach(new Swift_Message_EmbeddedFile(new Swift_File($logo), null, ImageManager::getMimeTypeByExtension($logo)));
         }
         if (Context::getContext()->link instanceof Link === false) {
             Context::getContext()->link = new Link();
         }
         $template_vars['{shop_name}'] = Tools::safeOutput(Configuration::get('PS_SHOP_NAME', null, null, $id_shop));
         $template_vars['{shop_url}'] = Context::getContext()->link->getPageLink('index', true, Context::getContext()->language->id);
         $template_vars['{my_account_url}'] = Context::getContext()->link->getPageLink('my-account', true, Context::getContext()->language->id);
         $template_vars['{guest_tracking_url}'] = Context::getContext()->link->getPageLink('guest-tracking', true, Context::getContext()->language->id);
         $template_vars['{history_url}'] = Context::getContext()->link->getPageLink('history', true, Context::getContext()->language->id);
         $template_vars['{color}'] = Tools::safeOutput(Configuration::get('PS_MAIL_COLOR', null, null, $id_shop));
         $swift->attachPlugin(new Swift_Plugin_Decorator(array($to_plugin => $template_vars)), 'decorator');
         if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_TEXT) {
             $message->attach(new Swift_Message_Part($template_txt, 'text/plain', '8bit', 'utf-8'));
         }
         if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_HTML) {
             $message->attach(new Swift_Message_Part($template_html, 'text/html', '8bit', 'utf-8'));
         }
         if ($file_attachment && !empty($file_attachment)) {
             // Multiple attachments?
             if (!is_array(current($file_attachment))) {
                 $file_attachment = array($file_attachment);
             }
             foreach ($file_attachment as $attachment) {
                 if (isset($attachment['content']) && isset($attachment['name']) && isset($attachment['mime'])) {
                     $message->attach(new Swift_Message_Attachment($attachment['content'], $attachment['name'], $attachment['mime']));
                 }
             }
         }
         /* Send mail */
         $send = $swift->send($message, $to, new Swift_Address($from, $from_name));
         $swift->disconnect();
         ShopUrl::resetMainDomainCache();
         return $send;
     } catch (Swift_Exception $e) {
         return false;
     }
 }
开发者ID:dev-lav,项目名称:htdocs,代码行数:101,代码来源:Mail.php

示例10: array


//.........这里部分代码省略.........
         Swift_ClassLoader::load('Swift_Connection_Multi');
         Swift_ClassLoader::load('Swift_Connection_SMTP');
         $pool = new Swift_Connection_Multi();
         // first choose method
         if ($fs->prefs['smtp_server']) {
             $split = explode(':', $fs->prefs['smtp_server']);
             $port = null;
             if (count($split) == 2) {
                 $fs->prefs['smtp_server'] = $split[0];
                 $port = $split[1];
             }
             // connection... SSL, TLS or none
             if ($fs->prefs['email_ssl']) {
                 $smtp = new Swift_Connection_SMTP($fs->prefs['smtp_server'], $port ? $port : SWIFT_SMTP_PORT_SECURE, SWIFT_SMTP_ENC_SSL);
             } else {
                 if ($fs->prefs['email_tls']) {
                     $smtp = new Swift_Connection_SMTP($fs->prefs['smtp_server'], $port ? $port : SWIFT_SMTP_PORT_SECURE, SWIFT_SMTP_ENC_TLS);
                 } else {
                     $smtp = new Swift_Connection_SMTP($fs->prefs['smtp_server'], $port);
                 }
             }
             if ($fs->prefs['smtp_user']) {
                 $smtp->setUsername($fs->prefs['smtp_user']);
                 $smtp->setPassword($fs->prefs['smtp_pass']);
             }
             if (defined('FS_SMTP_TIMEOUT')) {
                 $smtp->setTimeout(FS_SMTP_TIMEOUT);
             }
             $pool->addConnection($smtp);
         } else {
             Swift_ClassLoader::load('Swift_Connection_NativeMail');
             // a connection to localhost smtp server as fallback, discarded if there is no such thing available.
             $pool->addConnection(new Swift_Connection_SMTP());
             $pool->addConnection(new Swift_Connection_NativeMail());
         }
         $swift = new Swift($pool);
         if (isset($data['task_id'])) {
             $swift->attachPlugin(new NotificationsThread($data['task_id'], $emails, $db), 'MessageThread');
         }
         if (defined('FS_MAIL_DEBUG')) {
             $swift->log->enable();
             Swift_ClassLoader::load('Swift_Plugin_VerboseSending');
             $view = new Swift_Plugin_VerboseSending_DefaultView();
             $swift->attachPlugin(new Swift_Plugin_VerboseSending($view), "verbose");
         }
         $message = new Swift_Message($subject, $body);
         // check for reply-to
         if (isset($data['project']) && $data['project']->prefs['notify_reply']) {
             $message->setReplyTo($data['project']->prefs['notify_reply']);
         }
         if (isset($data['project']) && isset($data['project']->prefs['bounce_address'])) {
             $message->setReturnPath($data['project']->prefs['bounce_address']);
         }
         $message->headers->setCharset('utf-8');
         $message->headers->set('Precedence', 'list');
         $message->headers->set('X-Mailer', 'Flyspray');
         // Add custom headers, possibly
         if (isset($data['headers'])) {
             $headers = array_map('trim', explode("\n", $data['headers']));
             if ($headers = array_filter($headers)) {
                 foreach ($headers as $header) {
                     list($name, $value) = explode(':', $header);
                     $message->headers->set(sprintf('X-Flyspray-%s', $name), $value);
                 }
             }
         }
         $recipients = new Swift_RecipientList();
         $recipients->addTo($emails);
         // && $result purpose: if this has been set to false before, it should never become true again
         // to indicate an error
         $result = $swift->batchSend($message, $recipients, $fs->prefs['admin_email']) === count($emails) && $result;
         if (isset($data['task_id'])) {
             $plugin =& $swift->getPlugin('MessageThread');
             if (count($plugin->thread_info)) {
                 $stmt = $db->x->autoPrepare('{notification_threads}', array('task_id', 'recipient_id', 'message_id'));
                 $db->x->executeMultiple($stmt, $plugin->thread_info);
                 $stmt->free();
             }
         }
         $swift->disconnect();
     }
     if (count($jids)) {
         $jids = array_unique($jids);
         if (!$fs->prefs['jabber_username'] || !$fs->prefs['jabber_password']) {
             return $result;
         }
         // nothing that can't be guessed correctly ^^
         if (!$fs->prefs['jabber_port']) {
             $fs->prefs['jabber_port'] = 5222;
         }
         require_once 'class.jabber2.php';
         $jabber = new Jabber($fs->prefs['jabber_username'], $fs->prefs['jabber_password'], $fs->prefs['jabber_security'], $fs->prefs['jabber_port'], $fs->prefs['jabber_server']);
         $jabber->SetResource('flyspray');
         $jabber->login();
         foreach ($jids as $jid) {
             $result = $jabber->send_message($jid, $body, $subject, 'normal') && $result;
         }
     }
     return $result;
 }
开发者ID:negram,项目名称:flyspray,代码行数:101,代码来源:class.notify.php

示例11: Send


//.........这里部分代码省略.........
         foreach ($to as $key => $addr) {
             $to_name = NULL;
             $addr = trim($addr);
             if (!Validate::isEmail($addr)) {
                 Tools::dieOrLog(Tools::displayError('Error: invalid email address'), $die);
                 return false;
             }
             if (is_array($toName)) {
                 if ($toName and is_array($toName) and Validate::isGenericName($toName[$key])) {
                     $to_name = $toName[$key];
                 }
             }
             $to_list->addTo($addr, $to_name);
         }
         $to_plugin = $to[0];
         $to = $to_list;
     } else {
         /* Simple recipient, one address */
         $to_plugin = $to;
         $to = new Swift_Address($to, $toName);
     }
     try {
         /* Connect with the appropriate configuration */
         if ($configuration['PS_MAIL_METHOD'] == 2) {
             if (empty($configuration['PS_MAIL_SERVER']) or empty($configuration['PS_MAIL_SMTP_PORT'])) {
                 Tools::dieOrLog(Tools::displayError('Error: invalid SMTP server or SMTP port'), $die);
                 return false;
             }
             $connection = new Swift_Connection_SMTP($configuration['PS_MAIL_SERVER'], $configuration['PS_MAIL_SMTP_PORT'], $configuration['PS_MAIL_SMTP_ENCRYPTION'] == "ssl" ? Swift_Connection_SMTP::ENC_SSL : ($configuration['PS_MAIL_SMTP_ENCRYPTION'] == "tls" ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_OFF));
             $connection->setTimeout(4);
             if (!$connection) {
                 return false;
             }
             if (!empty($configuration['PS_MAIL_USER'])) {
                 $connection->setUsername($configuration['PS_MAIL_USER']);
             }
             if (!empty($configuration['PS_MAIL_PASSWD'])) {
                 $connection->setPassword($configuration['PS_MAIL_PASSWD']);
             }
         } else {
             $connection = new Swift_Connection_NativeMail();
         }
         if (!$connection) {
             return false;
         }
         $swift = new Swift($connection, Configuration::get('PS_MAIL_DOMAIN'));
         /* Get templates content */
         $iso = Language::getIsoById((int) $id_lang);
         if (!$iso) {
             Tools::dieOrLog(Tools::displayError('Error - No ISO code for email'), $die);
             return false;
         }
         $template = $iso . '/' . $template;
         $moduleName = false;
         $overrideMail = false;
         // get templatePath
         if (preg_match('#' . __PS_BASE_URI__ . 'modules/#', $templatePath) and preg_match('#modules/([a-z0-9_-]+)/#ui', $templatePath, $res)) {
             $moduleName = $res[1];
         }
         if ($moduleName !== false and (file_exists(_PS_THEME_DIR_ . 'modules/' . $moduleName . '/mails/' . $template . '.txt') or file_exists(_PS_THEME_DIR_ . 'modules/' . $moduleName . '/mails/' . $template . '.html'))) {
             $templatePath = _PS_THEME_DIR_ . 'modules/' . $moduleName . '/mails/';
         } elseif (file_exists(_PS_THEME_DIR_ . 'mails/' . $template . '.txt') or file_exists(_PS_THEME_DIR_ . 'mails/' . $template . '.html')) {
             $templatePath = _PS_THEME_DIR_ . 'mails/';
             $overrideMail = true;
         } elseif (!file_exists($templatePath . $template . '.txt') or !file_exists($templatePath . $template . '.html')) {
             Tools::dieOrLog(Tools::displayError('Error - The following email template is missing:') . ' ' . $templatePath . $template . '.txt', $die);
             return false;
         }
         $templateHtml = file_get_contents($templatePath . $template . '.html');
         $templateTxt = strip_tags(html_entity_decode(file_get_contents($templatePath . $template . '.txt'), NULL, 'utf-8'));
         if ($overrideMail and file_exists($templatePath . $iso . '/lang.php')) {
             include_once $templatePath . $iso . '/lang.php';
         } elseif ($moduleName and file_exists($templatePath . $iso . '/lang.php')) {
             include_once _PS_THEME_DIR_ . 'mails/' . $iso . '/lang.php';
         } else {
             include_once dirname(__FILE__) . '/../mails/' . $iso . '/lang.php';
         }
         /* Create mail and attach differents parts */
         $message = new Swift_Message('[' . Configuration::get('PS_SHOP_NAME') . '] ' . $subject);
         $templateVars['{shop_logo}'] = file_exists(_PS_IMG_DIR_ . 'logo_mail.jpg') ? $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_ . 'logo_mail.jpg'))) : (file_exists(_PS_IMG_DIR_ . 'logo.jpg') ? $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_ . 'logo.jpg'))) : '');
         $templateVars['{shop_name}'] = Tools::safeOutput(Configuration::get('PS_SHOP_NAME'));
         $templateVars['{shop_url}'] = Tools::getShopDomain(true, true) . __PS_BASE_URI__;
         $swift->attachPlugin(new Swift_Plugin_Decorator(array($to_plugin => $templateVars)), 'decorator');
         if ($configuration['PS_MAIL_TYPE'] == 3 or $configuration['PS_MAIL_TYPE'] == 2) {
             $message->attach(new Swift_Message_Part($templateTxt, 'text/plain', '8bit', 'utf-8'));
         }
         if ($configuration['PS_MAIL_TYPE'] == 3 or $configuration['PS_MAIL_TYPE'] == 1) {
             $message->attach(new Swift_Message_Part($templateHtml, 'text/html', '8bit', 'utf-8'));
         }
         if ($fileAttachment and isset($fileAttachment['content']) and isset($fileAttachment['name']) and isset($fileAttachment['mime'])) {
             $message->attach(new Swift_Message_Attachment($fileAttachment['content'], $fileAttachment['name'], $fileAttachment['mime']));
         }
         /* Send mail */
         $send = $swift->send($message, $to, new Swift_Address($from, $fromName));
         $swift->disconnect();
         return $send;
     } catch (Swift_ConnectionException $e) {
         return false;
     }
 }
开发者ID:ricardo-rdfs,项目名称:Portal-BIP,代码行数:101,代码来源:Mail.php

示例12: testDisconnectListenerRunsUponDisconnect

 public function testDisconnectListenerRunsUponDisconnect()
 {
     $conn = new FullMockConnection();
     $conn->setReturnValueAt(0, "read", "220 Hello xx");
     $conn->setReturnValueAt(1, "read", "250 Hello xxx");
     $conn->setReturnValueAt(2, "read", "221 Bye");
     $disconnect_listener = new MockDisconnectListener();
     $disconnect_listener->expectCallCount("disconnectPerformed", 1);
     $swift = new Swift($conn);
     $swift->attachPlugin($disconnect_listener, "myplugin");
     $swift->disconnect();
     $conn = new FullMockConnection();
     $conn->setReturnValueAt(0, "read", "220 Hello xx");
     $conn->setReturnValueAt(1, "read", "250 Hello xxx");
     $conn->setReturnValueAt(2, "read", "221 Bye");
     $conn->setReturnValueAt(3, "read", "220 Hello xx");
     $conn->setReturnValueAt(4, "read", "250 Hello xxx");
     $conn->setReturnValueAt(5, "read", "221 Bye");
     $conn->setReturnValueAt(6, "read", "220 Hello xx");
     $conn->setReturnValueAt(7, "read", "250 Hello xxx");
     $conn->setReturnValueAt(8, "read", "221 Bye");
     $disconnect_listener = new MockDisconnectListener();
     $disconnect_listener->expectCallCount("disconnectPerformed", 3);
     $swift = new Swift($conn);
     $swift->attachPlugin($disconnect_listener, "myplugin");
     $swift->disconnect();
     $swift->connect();
     $swift->disconnect();
     $swift->connect();
     $swift->disconnect();
 }
开发者ID:Esleelkartea,项目名称:legedia-ESLE,代码行数:31,代码来源:TestOfPluginAPI.php

示例13: postConnect

 /**
  * Call the current connection's postConnect() method
  */
 public function postConnect(Swift $instance)
 {
     Swift_ClassLoader::load("Swift_Plugin_ConnectionRotator");
     if (!$instance->getPlugin("_ROTATOR")) {
         $instance->attachPlugin(new Swift_Plugin_ConnectionRotator(), "_ROTATOR");
     }
     $this->connections[$this->active]->postConnect($instance);
 }
开发者ID:AlexanderS,项目名称:Part-DB,代码行数:11,代码来源:Rotator.php

示例14: Send


//.........这里部分代码省略.........
     if (!empty($from) && !Validate::isEmail($from)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "from" is corrupted'), $die);
         return false;
     }
     if (!empty($fromName) && !Validate::isMailName($fromName)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "fromName" is corrupted'), $die);
         return false;
     }
     if (!is_array($to) && !Validate::isEmail($to)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "to" is corrupted'), $die);
         return false;
     }
     if (!is_array($templateVars)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "templateVars" is not an array'), $die);
         return false;
     }
     // Do not crash for this error, that may be a complicated customer name
     if (is_string($toName)) {
         if (!empty($toName) && !Validate::isMailName($toName)) {
             $toName = null;
         }
     }
     if (!Validate::isTplName($template)) {
         Tools::dieOrLog(Tools::displayError('Error: invalid email template'), $die);
         return false;
     }
     if (!Validate::isMailSubject($subject)) {
         Tools::dieOrLog(Tools::displayError('Error: invalid email subject'), $die);
         return false;
     }
     /* Construct multiple recipients list if needed */
     if (isset($to) && is_array($to)) {
         $to_list = new Swift_RecipientList();
         foreach ($to as $key => $addr) {
             $to_name = null;
             $addr = trim($addr);
             if (!Validate::isEmail($addr)) {
                 Tools::dieOrLog(Tools::displayError('Error: invalid email address'), $die);
                 return false;
             }
             if (is_array($toName)) {
                 if ($toName && is_array($toName) && Validate::isGenericName($toName[$key])) {
                     $to_name = $toName[$key];
                 }
             }
             $to_list->addTo($addr, base64_encode($to_name));
         }
         $to_plugin = $to[0];
         $to = $to_list;
     } else {
         /* Simple recipient, one address */
         $to_plugin = $to;
         $to = new Swift_Address($to, base64_encode($toName));
     }
     try {
         /* Connect with the appropriate configuration */
         if ($configuration['TM_MAIL_METHOD'] == 2) {
             if (empty($configuration['TM_MAIL_SERVER']) || empty($configuration['TM_MAIL_SMTP_PORT'])) {
                 Tools::dieOrLog(Tools::displayError('Error: invalid SMTP server or SMTP port'), $die);
                 return false;
             }
             $connection = new Swift_Connection_SMTP($configuration['TM_MAIL_SERVER'], $configuration['TM_MAIL_SMTP_PORT'], $configuration['TM_MAIL_SMTP_ENCRYPTION'] == 'ssl' ? Swift_Connection_SMTP::ENC_SSL : ($configuration['TM_MAIL_SMTP_ENCRYPTION'] == 'tls' ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_OFF));
             $connection->setTimeout(20);
             if (!$connection) {
                 return false;
             }
             if (!empty($configuration['TM_MAIL_USER'])) {
                 $connection->setUsername($configuration['TM_MAIL_USER']);
             }
             if (!empty($configuration['TM_MAIL_PASSWD'])) {
                 $connection->setPassword($configuration['TM_MAIL_PASSWD']);
             }
         } else {
             $connection = new Swift_Connection_NativeMail();
         }
         if (!$connection) {
             return false;
         }
         $swift = new Swift($connection, Configuration::get('TM_MAIL_DOMAIN'));
         // get templatePath
         $templatePath = _TM_THEMES_DIR . 'mails/';
         $templateHtml = file_get_contents($templatePath . $template . '.html');
         /* Create mail && attach differents parts */
         $message = new Swift_Message('[' . Configuration::get('TM_SHOP_NAME') . '] ' . $subject);
         $templateVars['{shop_logo}'] = file_exists(_TM_IMG_DIR . 'logo_mail.jpg') ? $message->attach(new Swift_Message_Image(new Swift_File(_TM_IMG_DIR . 'logo_mail.jpg'))) : (file_exists(_TM_IMG_DIR . 'logo.jpg') ? $message->attach(new Swift_Message_Image(new Swift_File(_TM_IMG_DIR . 'logo.jpg'))) : '');
         $templateVars['{shop_name}'] = Tools::safeOutput(Configuration::get('TM_SHOP_NAME'));
         $templateVars['{shop_url}'] = Tools::getShopDomain(true, true) . __TM_BASE_URI__;
         $swift->attachPlugin(new Swift_Plugin_Decorator(array($to_plugin => $templateVars)), 'decorator');
         $message->attach(new Swift_Message_Part($templateHtml, 'text/html', '8bit', 'utf-8'));
         if ($fileAttachment && isset($fileAttachment['content']) && isset($fileAttachment['name']) && isset($fileAttachment['mime'])) {
             $message->attach(new Swift_Message_Attachment($fileAttachment['content'], $fileAttachment['name'], $fileAttachment['mime']));
         }
         /* Send mail */
         $send = $swift->send($message, $to, new Swift_Address($from, $fromName));
         $swift->disconnect();
         return $send;
     } catch (Swift_ConnectionException $e) {
         return false;
     }
 }
开发者ID:yiuked,项目名称:tmcart,代码行数:101,代码来源:Mail.php

示例15: testSubjectIsProvidedUnencodedIfAsciiIsUsed

 /**
  * The subject should not be encoded if 7-bit ascii is used.
  */
 public function testSubjectIsProvidedUnencodedIfAsciiIsUsed()
 {
     $swift = new Swift(new Swift_Connection_NativeMail());
     $mailsend = new MailSendWithGetDoMailArgs();
     $swift->attachPlugin($mailsend, "_MAIL_SEND");
     //Override the MailSend plugin with a custom mock
     $recipients = new Swift_Address("test@bar.tld", "Test");
     $sender = "foobar@bar.com";
     $subject = "foobar";
     $body = "Foo test\r\nBar";
     $message = new Swift_Message($subject, $body);
     $this->assertPattern("~\r\n~", $body);
     $swift->send($message, $recipients, $sender);
     $passed = $mailsend->getDoMailArgs();
     $this->assertEqual("foobar", $passed[1]);
 }
开发者ID:Esleelkartea,项目名称:legedia-ESLE,代码行数:19,代码来源:TestOfMailSendPlugin.php


注:本文中的Swift::attachPlugin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。