powered by nequal
Home » jpSimpleMailPlugin » Timeline » 2312

Diffs

jpSimpleMailPlugin/trunk/test/unit/jpPHPMailerTest.php

@@ -1,5 +1,10 @@
<?php
include(dirname(__FILE__) . '/../bootstrap/unit.php');
+
+// for include library
+// change the path to your library.
+require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/lib/vendor/phpMailer_v2.3/class.phpmailer.php');
+
$t = new lime_test(23, new lime_output_color());
// send mail
$t->diag('check method');
@@ -19,7 +24,7 @@
$old = $mailer->getEncoding();
$mailer->setEncoding('7bit');
$t->is($mailer->getEncoding(), '7bit', 'test Encoding');
-$mailer->setPriority($old);
+$mailer->setEncoding($old);
// return path
$old = $mailer->getReturnPath();
$mailer->setReturnPath($params['from']);

jpSimpleMailPlugin/trunk/test/unit/jpSwiftMailerTest.php

@@ -1,5 +1,13 @@
<?php
include(dirname(__FILE__) . '/../bootstrap/unit.php');
+
+// for include library
+// change the path to your library.
+$dir = dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/data/swift';
+$sfSimpleAutoload = sfSimpleAutoload::getInstance();
+$sfSimpleAutoload->addDirectory($dir);
+$sfSimpleAutoload->register();
+
$t = new lime_test(23, new lime_output_color());
// send mail
$t->diag('check method');
@@ -19,7 +27,7 @@
$old = $mailer->getEncoding();
$mailer->setEncoding('7bit');
$t->is($mailer->getEncoding(), '7bit', 'test Encoding');
-$mailer->setPriority($old);
+$mailer->setEncoding($old);
// return path
$old = $mailer->getReturnPath();
$mailer->setReturnPath($params['from']);

jpSimpleMailPlugin/trunk/test/unit/jpQdmailTest.php

@@ -1,5 +1,10 @@
<?php
include(dirname(__FILE__) . '/../bootstrap/unit.php');
+
+// for include library
+// change the path to your library.
+require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/lib/vendor/qdmail.1.2.6b/qdmail.php');
+
$t = new lime_test(23, new lime_output_color());
// send mail
$t->diag('check method');
@@ -19,7 +24,7 @@
$old = $mailer->getEncoding();
$mailer->setEncoding('7bit');
$t->is($mailer->getEncoding(), '7bit', 'test Encoding');
-$mailer->setPriority($old);
+$mailer->setEncoding($old);
// return path
$old = $mailer->getReturnPath();
$mailer->setReturnPath($params['from']);
@@ -32,7 +37,7 @@
$old = $mailer->getFrom();
$mailer->setFrom($params['from'], $params['from_name']);
$t->is($mailer->getFrom(), $params['from'], 'test From');
-$mailer->setFrom($old);
+//$mailer->setFrom($old);
//addCc
$t->is($mailer->addCc($_SERVER['SF_TEST_TO_ADDRESS']), null, 'test to call addCc method');
$t->is($mailer->addCc($_SERVER['SF_TEST_TO_ADDRESS'], $params['to_name']), null, 'test to call addCc method with name');
@@ -40,10 +45,11 @@
$t->is($mailer->addBcc($_SERVER['SF_TEST_TO_ADDRESS']), null, 'test to call addBcc method');
$t->is($mailer->addBcc($_SERVER['SF_TEST_TO_ADDRESS'], $params['to_name']), null, 'test to call addBcc method with name');
// Subject
-$old = $mailer->getSubject();
+// if subject is null, qdmail occurs an error, so the previous value is not checked.
+//$old = $mailer->getSubject();
$mailer->setSubject($params['subject']);
$t->is($mailer->getSubject(), $params['subject'], 'test encoded Subject');
-$mailer->setSubject($old);
+//$mailer->setSubject($old);
// body
$old = $mailer->getBody();
$mailer->setBody($params['body']);

jpSimpleMailPlugin/trunk/test/unit/jpSwiftMailer4Test.php

@@ -0,0 +1,79 @@
+<?php
+include(dirname(__FILE__) . '/../bootstrap/unit.php');
+
+// for include library
+// change the path to your library.
+// SwiftMailer4 depends on sfMailer with sfContext, so you have to create sample application 'frontend' for test
+// and require ProjectConfiguration.class.php like below.
+require_once dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/config/ProjectConfiguration.class.php';
+$app_configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false);
+sfContext::createInstance($app_configuration);
+
+$t = new lime_test(23, new lime_output_color());
+// send mail
+$t->diag('check method');
+$mailer = jpSimpleMail::create('SwiftMailer4');
+$t->isa_ok($mailer, 'jpSwiftMailer4', 'created instance is correct');
+// charset
+$old = $mailer->getCharset();
+$mailer->setCharset('utf-8');
+$t->is($mailer->getCharset(), 'utf-8', 'test Charset');
+$mailer->setCharset($old);
+// priority
+$old = $mailer->getPriority();
+$mailer->setPriority('1');
+$t->is($mailer->getPriority(), '1', 'test Priority');
+$mailer->setPriority($old);
+// encoding
+$old = $mailer->getEncoding();
+$mailer->setEncoding('7bit');
+$t->is($mailer->getEncoding(), '7bit', 'test Encoding');
+$mailer->setEncoding($old);
+// return path
+$old = $mailer->getReturnPath();
+$mailer->setReturnPath($params['from']);
+$t->is($mailer->getReturnPath(), $params['from'], 'test Return Path');
+$mailer->setReturnPath($old);
+// addTo
+$t->is($mailer->addTo($_SERVER['SF_TEST_TO_ADDRESS']), null, 'test to call addTo method');
+$t->is($mailer->addTo($_SERVER['SF_TEST_TO_ADDRESS'], $params['to_name']), null, 'test to call addTo method with name');
+// from
+$old = $mailer->getFrom();
+$mailer->setFrom($params['from'], $params['from_name']);
+$t->is($mailer->getFrom(), $params['from'], 'test From');
+$mailer->setFrom($old);
+//addCc
+$t->is($mailer->addCc($_SERVER['SF_TEST_TO_ADDRESS']), null, 'test to call addCc method');
+$t->is($mailer->addCc($_SERVER['SF_TEST_TO_ADDRESS'], $params['to_name']), null, 'test to call addCc method with name');
+//addBcc
+$t->is($mailer->addBcc($_SERVER['SF_TEST_TO_ADDRESS']), null, 'test to call addBcc method');
+$t->is($mailer->addBcc($_SERVER['SF_TEST_TO_ADDRESS'], $params['to_name']), null, 'test to call addBcc method with name');
+// Subject
+$old = $mailer->getSubject();
+$mailer->setSubject($params['subject']);
+$t->is($mailer->getSubject(), $params['subject'], 'test Subject');
+$mailer->setSubject($old);
+// body
+$old = $mailer->getBody();
+$mailer->setBody($params['body']);
+$t->is($mailer->getbody(), $params['body'], 'test body');
+$mailer->setBody($old);
+//addReplyTo
+$t->is($mailer->addReplyTo($params['from']), null, 'test to call addReplyTo method');
+$t->is($mailer->addReplyTo($params['from'], $params['from_name']), null, 'test to call addReplyTo method with name');
+// clearTo
+$t->is($mailer->clearTo(), null, 'test to call clearTo method');
+// clearCc
+$t->is($mailer->clearCc(), null, 'test to call clearCc method');
+// clearBcc
+$t->is($mailer->clearBcc(), null, 'test to call clearBcc method');
+// clearReplyTo
+$t->is($mailer->clearReplyTo(), null, 'test to call clearReplyTo method');
+// sender ( only this class)
+$old = $mailer->getSender();
+$mailer->setSender($params['from'], $params['from_name']);
+$t->is($mailer->getSender(), $params['from'], 'test Sender');
+$mailer->setSender($old);
+// addAddress (only this class)
+$t->is($mailer->addAddress($_SERVER['SF_TEST_TO_ADDRESS']), null, 'test to call addAddress method');
+$t->is($mailer->addAddress($_SERVER['SF_TEST_TO_ADDRESS'], $params['to_name']), null, 'test to call addAddress method with name');

jpSimpleMailPlugin/trunk/test/functional/jpPHPMailerTest.php

@@ -1,5 +1,10 @@
<?php
include(dirname(__FILE__) . '/../bootstrap/functional.php');
+
+// for include library
+// change the path to your library.
+require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/lib/vendor/phpMailer_v2.3/class.phpmailer.php');
+
$t = new lime_test(2, new lime_output_color());
$t->diag('send mail by PHPMailer');
// success to send a mail

jpSimpleMailPlugin/trunk/test/functional/jpSwiftMailerTest.php

@@ -1,5 +1,13 @@
<?php
include(dirname(__FILE__) . '/../bootstrap/functional.php');
+
+// for include library
+// change the path to your library.
+$dir = dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/data/swift';
+$sfSimpleAutoload = sfSimpleAutoload::getInstance();
+$sfSimpleAutoload->addDirectory($dir);
+$sfSimpleAutoload->register();
+
$t = new lime_test(2, new lime_output_color());
$t->diag('send mail by Swift Mailer');
// success to send a mail

jpSimpleMailPlugin/trunk/test/functional/jpQdmailTest.php

@@ -1,5 +1,10 @@
<?php
include(dirname(__FILE__) . '/../bootstrap/functional.php');
+
+// for include library
+// change the path to your library.
+require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/lib/vendor/qdmail.1.2.6b/qdmail.php');
+
$t = new lime_test(2, new lime_output_color());
$t->diag('send mail by Qdmail');
// success to send a mail

jpSimpleMailPlugin/trunk/test/functional/jpSwiftMailer4Test.php

@@ -0,0 +1,41 @@
+<?php
+include(dirname(__FILE__) . '/../bootstrap/functional.php');
+
+// for include library
+// change the path to your library.
+// SwiftMailer4 depends on sfMailer with sfContext, so you have to create sample application 'frontend' for test
+// and require ProjectConfiguration.class.php like below.
+require_once dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/config/ProjectConfiguration.class.php';
+$app_configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false);
+sfContext::createInstance($app_configuration);
+
+$t = new lime_test(2, new lime_output_color());
+$t->diag('send mail by Swift Mailer ver.4');
+// success to send a mail
+$process = true;
+try {
+    $mailer = jpSimpleMail::create('SwiftMailer4');
+    $mailer->setSubject($params['subject']);
+    $mailer->setSender($_SERVER['SF_TEST_TO_ADDRESS']);
+    $mailer->addTo(sprintf('%s <%s>', $params['to_name'], $_SERVER['SF_TEST_TO_ADDRESS']));
+    $mailer->setFrom(sprintf('%s <%s>', $params['to_name'], $params['from']));
+    $mailer->setBody($params['body']);
+    $mailer->send();
+} catch (jpSendMailException $e) {
+  $process = false;
+}
+$t->is($process, true, 'succeess to send mail');
+// fail to send a mail
+$proccess = true;
+try{
+    $mailer = jpSimpleMail::create('SwiftMailer4');
+    $mailer->setSubject($params['subject']);
+    $mailer->setSender($_SERVER['SF_TEST_TO_ADDRESS']);
+//    $mailer->addTo(sprintf('%s <%s>', $params['to_name'], $_SERVER['SF_TEST_TO_ADDRESS']));
+    $mailer->setFrom(sprintf('%s <%s>', $params['from_name'], $params['from']));
+    $mailer->setBody($params['body']);
+    $mailer->send();
+} catch (jpSendMailException $e) {
+  $proccess = false;
+}
+$t->is($proccess, false, 'catch the jpSendMailException');
\ No newline at end of file

jpSimpleMailPlugin/trunk/config/jpSimpleMailPluginConfiguration.class.php

@@ -5,7 +5,7 @@
*
* @package     jpSimpleMailPlugin
* @subpackage  config
- * @author      Your name here
+ * @author      brt.river <brt.river@gmail.com>
* @version     SVN: $Id$
*/
class jpSimpleMailPluginConfiguration extends sfPluginConfiguration

jpSimpleMailPlugin/trunk/lib/kzl_Jp_Swift_Mime_Headers_UnstructredHeader.php

@@ -1,34 +0,0 @@
-<?php
-//@require 'Swift/Mime/Headers/AbstractHeader.php';
-//@require 'Swift/Mime/HeaderEncoder.php';
-
-/**
- * 日本語(ISO-2022-JP)用メールヘッダクラス
- * @package kzlJpSwiftMailerPlugin
- * @subpackage Mime
- * @author kawaguchi
- * @url http://www.kuzilla.co.jp/
- */
-class kzl_Jp_Swift_Mime_Headers_UnstructuredHeader
-  extends Swift_Mime_Headers_UnstructuredHeader
-{
-  // override
-  public function getFieldBody()
-  {
-    if (!$this->getCachedValue())
-    {
-      // ISO-2022-JP対応
-      if (strcasecmp($this->getCharset(), 'iso-2022-jp') === 0)
-      {
-        // TODO:: エンコードを内包するパターンでSubjectがMIMEエンコードされているのを確認
-        // subjectをセットする際にエンコードするのでここでは何もしない
-        //$this->setCachedValue($this->getValue());
-        // エンコード内包する場合。(本来はこちらが正しいかも)
-        $this->setCachedValue(jpSimpleMail::mb_encode_mimeheader(( $this->getValue())));
-      } else {
-        parent::getFieldBody();
-      }
-    }
-    return $this->getCachedValue();
-  }
-}
\ No newline at end of file

jpSimpleMailPlugin/trunk/lib/jpSimpleMail.class.php

@@ -13,7 +13,7 @@
* Factory method
*
* @param string $mailer: the name of the instance
-   *                        'PHPMailer', 'SwiftMailer', 'Qdmail' for default
+   *                        'SwiftMailer4','PHPMailer', 'SwiftMailer', 'Qdmail' for default
*
* @return object $class: the created instance
*/

jpSimpleMailPlugin/trunk/lib/mailer/jpQdmail.class.php

@@ -16,11 +16,12 @@
}
public function setCharset($charset)
{
-    $this->mailer->setCharset($charset);
+    $this->mailer->charset($charset);
}
public function getCharset()
{
-    return $this->mailer->getCharset();
+    $ret = $this->mailer->charset();
+    return $ret['HEADER'];
}
public function setPriority($priority)
{
@@ -60,18 +61,30 @@
}
public function addTo($address, $name = null)
{
+    if ($name == null) {
+      list($address, $name) = jpSimpleMail::splitAddress($address);
+    }
$this->mailer->addAddress($address, $name);
}
public function setFrom($address, $name = null)
{
+    if ($name == null) {
+      list($address, $name) = jpSimpleMail::splitAddress($address);
+    }
$this->mailer->setFrom($address, $name);
}
public function addCc($address, $name = null)
{
+    if ($name == null) {
+      list($address, $name) = jpSimpleMail::splitAddress($address);
+    }
$this->mailer->AddCc($address, $name);
}
public function addBcc($address, $name = null)
{
+    if ($name == null) {
+      list($address, $name) = jpSimpleMail::splitAddress($address);
+    }
$this->mailer->AddBcc($address, $name);
}
public function setSubject($subject)
@@ -88,6 +101,9 @@
}
public function addReplyTo($address, $name = null)
{
+    if ($name == null) {
+      list($address, $name) = jpSimpleMail::splitAddress($address);
+    }
$this->mailer->AddReplyTo($address, $name);
}
public function getTo()
@@ -97,7 +113,8 @@
public function getFrom()
{
// if not set, email validation erro is occured.
-    return $this->mailer->from[0]['mail'];
+    $from = $this->mailer->from();
+    return (isset($from[0]['mail']))? $from[0]['mail']: "";
}
public function getSubject()
{

jpSimpleMailPlugin/trunk/lib/mailer/jpSwiftMailer4.class.php

@@ -3,7 +3,7 @@
* jpSwiftMailer4 class
*
*  this class is for SwiftMailer ver4
- *  require kzl_Jp_Swift_Mime_Headers_UnstructuredHeader
+ *  require Jp_Swift_Mime_Headers_UnstructuredHeader
*    ref: http://www.kuzilla.co.jp/article.php/20100301symfony
*
* @package    jpSimpleMailPlugin
@@ -11,7 +11,6 @@
* @author     brt.river <brt.river@gmail.com>
* @version    $Id: jpSwiftMailer4.class.php 1725 2010-03-22 13:32:49Z brtriver $
*/
-require_once dirname(dirname(__FILE__)) . "/kzl_Jp_Swift_Mime_Headers_UnstructredHeader.php";
class jpSwiftMailer4 extends jpMailer
{
public
@@ -24,7 +23,7 @@
mb_language('Ja');
$this->message = Swift_Message::newInstance();
$this->message->getHeaders()->remove('Subject');
-    $subjectHeader = new kzl_Jp_Swift_Mime_Headers_UnstructuredHeader('Subject',
+    $subjectHeader = new jp_Swift_Mime_Headers_UnstructuredHeader('Subject',
new Swift_Mime_HeaderEncoder_Base64HeaderEncoder());
$this->message->getHeaders()->set($subjectHeader);
$this->message->setContentType('text/plain');
@@ -49,11 +48,11 @@
}
public function setEncoding($encoding)
{
-    $this->message->setEncoding($encoding);
+    $this->message->getHeaders()->get('Content-Transfer-Encoding')->setValue($encoding);
}
public function getEncoding()
{
-    return $this->message->getEncoding();
+    return $this->message->getHeaders()->get('Content-Transfer-Encoding')->getValue();
}
public function setSender($address, $name = null)
{
@@ -144,7 +143,8 @@
}
public function getFrom()
{
-    return $this->from->getAddress();
+    $from = $this->message->getFrom();
+    return key($from);
}
public function getSubject()
{
@@ -173,10 +173,41 @@
public function send()
{
try {
-      $this->mailer->send($this->message);
+      $result = $this->mailer->send($this->message);
+      if (!$result) throw new Exception('Failures: Cannot send E-mail');
return true;
} catch ( Exception $e) {
throw new jpSendMailException($e);
}
}
}
+
+//@require 'Swift/Mime/Headers/AbstractHeader.php';
+//@require 'Swift/Mime/HeaderEncoder.php';
+
+/**
+ * 日本語(ISO-2022-JP)用メールヘッダクラス
+ * @package jpSimpleMailPlugin
+ * @subpackage Mime
+ * @author kawaguchi
+ * @url http://www.kuzilla.co.jp/
+ */
+class Jp_Swift_Mime_Headers_UnstructuredHeader
+  extends Swift_Mime_Headers_UnstructuredHeader
+{
+  // override
+  public function getFieldBody()
+  {
+    if (!$this->getCachedValue())
+    {
+      // ISO-2022-JP対応
+      if (strcasecmp($this->getCharset(), 'iso-2022-jp') === 0)
+      {
+        $this->setCachedValue(jpSimpleMail::mb_encode_mimeheader(( $this->getValue())));
+      } else {
+        parent::getFieldBody();
+      }
+    }
+    return $this->getCachedValue();
+  }
+}
\ No newline at end of file