powered by nequal
Home » jpSimpleMailPlugin » Timeline » 2317

Changeset 2317 -- 2011-01-09 00:56:26

Author
ganchiku
Comment
fixed debug panel for swiftmail4. added an option to activate debug panel for jpSimpleMail with swiftmail4. fixed return value of send method in jpSwiftMailer4 class.

Diffs

jpSimpleMailPlugin/trunk/config/app.yml

@@ -1,3 +1,4 @@
all:
jpSimpleMail:
-    encoding: utf-8
\ No newline at end of file
+    encoding: utf-8
+    swift_debug: true

jpSimpleMailPlugin/trunk/config/jpSimpleMailPluginConfiguration.class.php

@@ -15,5 +15,10 @@
*/
public function initialize()
{
+    if (sfConfig::get('app_jpSimpleMail_swift_debug', false)) {
+      $this->dispatcher->connect('debug.web.load_panels', array(
+        'JpSwiftWebDebugPanelMailer', 'listenToLoadDebugWebPanelEvent'
+      ));
+    }
}
}

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

@@ -182,9 +182,7 @@
public function send()
{
try {
-      $result = $this->mailer->send($this->message);
-      if (!$result) throw new Exception('Failures: Cannot send E-mail');
-      return true;
+      return $this->mailer->send($this->message);
} catch ( Exception $e) {
throw new jpSendMailException($e);
}
@@ -220,3 +218,36 @@
return $this->getCachedValue();
}
}
+class JpSwiftWebDebugPanelMailer extends sfWebDebugPanelMailer{
+  protected function renderMessageInformation(Swift_Message $message)
+  {
+    $internalEncoding = sfConfig::get('app_jpSimpleMail_encoding', 'utf-8');
+    static $i = 0;
+
+    $i++;
+
+    $to = null === $message->getTo() ? '' : implode(', ', array_keys($message->getTo()));
+
+    $html = array();
+    if ($message->getCharset() == 'iso-2022-jp') {
+      $html[] = sprintf('<h3>%s (to: %s) %s</h3>', $message->getSubject(), $to, $this->getToggler('sfWebDebugMailTemplate'.$i));
+      $html[] = '<div id="sfWebDebugMailTemplate'.$i.'" style="display:'.(1 == $i ? 'block' : 'none').'">';
+      $html[] = '<pre>'. htmlspecialchars(mb_convert_encoding($message->toString(), $internalEncoding, $message->getCharset()) , ENT_QUOTES, $internalEncoding).'</pre>';
+    } else {
+      // same as default
+      $html[] = sprintf('<h3>%s (to: %s) %s</h3>', $message->getSubject(), $to, $this->getToggler('sfWebDebugMailTemplate'.$i));
+      $html[] = '<div id="sfWebDebugMailTemplate'.$i.'" style="display:'.(1 == $i ? 'block' : 'none').'">';
+      $html[] = '<pre>'.htmlentities($message->toString(), ENT_QUOTES, $message->getCharset()).'</pre>';
+    }
+    $html[] = '</div>';
+
+    return implode("\n", $html);
+  }
+
+  public static function listenToLoadDebugWebPanelEvent(sfEvent $event)
+  {
+    // override mailer panel
+    $event->getSubject()->setPanel('mailer', new self($event->getSubject()));
+  }
+
+}