Add DebugFolderEmailTransport
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 12 Feb 2019 18:41:49 +0000 (19:41 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Sun, 10 Nov 2019 12:09:36 +0000 (13:09 +0100)
(cherry picked from commit e5c4fc8eb9dd3b0761db7fe1ba4d098c686ba0fa)

Closes #3103

com.woltlab.wcf/option.xml
wcfsetup/install/files/lib/system/email/transport/DebugFolderEmailTransport.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index dcf8a6941e52fa91fc26dde376d20f9869343c96..499d8278df855d41e043c278a292b970c14ab73c 100644 (file)
@@ -910,10 +910,12 @@ physical:wcf.acp.option.google_maps_type.physical</selectoptions>
                                <defaultvalue>php</defaultvalue>
                                <selectoptions>php:wcf.acp.option.mail_send_method.php
 smtp:wcf.acp.option.mail_send_method.smtp
-debug:wcf.acp.option.mail_send_method.debug</selectoptions>
+debug:wcf.acp.option.mail_send_method.debug
+debugFolder:wcf.acp.option.mail_send_method.debugFolder</selectoptions>
                                <enableoptions>php:mail_use_f_param,!mail_smtp_host,!mail_smtp_port,!mail_smtp_starttls,!mail_smtp_user,!mail_smtp_password
 smtp:!mail_use_f_param,mail_smtp_host,mail_smtp_port,mail_smtp_starttls,mail_smtp_user,mail_smtp_password
-debug:!mail_use_f_param,!mail_smtp_host,!mail_smtp_port,!mail_smtp_starttls,!mail_smtp_user,!mail_smtp_password</enableoptions>
+debug:!mail_use_f_param,!mail_smtp_host,!mail_smtp_port,!mail_smtp_starttls,!mail_smtp_user,!mail_smtp_password
+debugFolder:!mail_use_f_param,!mail_smtp_host,!mail_smtp_port,!mail_smtp_starttls,!mail_smtp_user,!mail_smtp_password</enableoptions>
                        </option>
                        <option name="mail_smtp_host">
                                <categoryname>general.mail.send</categoryname>
diff --git a/wcfsetup/install/files/lib/system/email/transport/DebugFolderEmailTransport.class.php b/wcfsetup/install/files/lib/system/email/transport/DebugFolderEmailTransport.class.php
new file mode 100644 (file)
index 0000000..ead83a9
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+namespace wcf\system\email\transport;
+use wcf\system\email\Email;
+use wcf\system\email\Mailbox;
+use wcf\util\FileUtil;
+
+/**
+ * DebugFolderEmailTransport is a debug implementation of an email transport which writes emails into
+ * a folder.
+ * On unix-like operating systems the folder will be a valid Maildir.
+ * 
+ * @author     Tim Duesterhus
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Email\Transport
+ * @since      5.2
+ */
+class DebugFolderEmailTransport implements IEmailTransport {
+       /**
+        * folder
+        * @var string
+        */
+       protected $folder = null;
+       
+       /**
+        * Creates a new DebugFolderTransport using the given folder as target.
+        * 
+        * @param       string  $folder folder or null for default folder
+        */
+       public function __construct($folder = null) {
+               if ($folder === null) $folder = WCF_DIR.'log/Maildir';
+               
+               $this->folder = FileUtil::addTrailingSlash($folder);
+               FileUtil::makePath($this->folder);
+               if (PHP_EOL != "\r\n") {
+                       FileUtil::makePath($this->folder.'new');
+                       FileUtil::makePath($this->folder.'cur');
+                       FileUtil::makePath($this->folder.'tmp');
+               }
+       }
+       
+       /**
+        * Writes the given $email into the folder.
+        * 
+        * @param       Email           $email
+        * @param       Mailbox         $envelopeFrom
+        * @param       Mailbox         $envelopeTo
+        */
+       public function deliver(Email $email, Mailbox $envelopeFrom, Mailbox $envelopeTo) {
+               $eml = "Return-Path: <".$envelopeFrom->getAddress().">\r\n";
+               $eml .= "Delivered-To: <".$envelopeTo->getAddress().">\r\n";
+               $eml .= $email->getEmail();
+               $eml .= "\r\n";
+               $timestamp = explode(' ', microtime());
+               $filename = $timestamp[1].'.M'.substr($timestamp[0], 2).'.eml';
+               file_put_contents($this->folder.$filename, $eml);
+               
+               if (PHP_EOL != "\r\n") {
+                       symlink('../'.$filename, $this->folder.'new/'.$filename);
+               }
+       }
+}
index 7a3ee4c44e577be8d3a412f9ef8cf5c3fbcadc85..76c77495ab2e26095c5b6ba0316aaab769d103b4 100644 (file)
@@ -243,7 +243,7 @@ class PackageInstallationDispatcher {
                                                        'exception_privacy'
                                                ]);
                                                $statement->execute([
-                                                       'debug',
+                                                       'debugFolder',
                                                        'mail_send_method'
                                                ]);
                                                $statement->execute([
index 0b740a3e7e0ddbdf4718586b6a7525e26c0aa331..89395488410843952a64cb503c861f394541234c 100644 (file)
                <item name="wcf.acp.option.mail_from_name"><![CDATA[Absender-Name]]></item>
                <item name="wcf.acp.option.mail_from_name.description"><![CDATA[Absender-Name für automatisch generierte E-Mails]]></item>
                <item name="wcf.acp.option.mail_send_method"><![CDATA[Versandmethode]]></item>
-               <item name="wcf.acp.option.mail_send_method.debug"><![CDATA[Debug]]></item>
+               <item name="wcf.acp.option.mail_send_method.debug"><![CDATA[Debug (mbox)]]></item>
+               <item name="wcf.acp.option.mail_send_method.debugFolder"><![CDATA[Debug (Ordner mit .eml-Dateien)]]></item>
                <item name="wcf.acp.option.mail_send_method.php"><![CDATA[PHP]]></item>
                <item name="wcf.acp.option.mail_send_method.smtp"><![CDATA[SMTP]]></item>
                <item name="wcf.acp.option.mail_signature"><![CDATA[Signatur]]></item>
index 60391556af3d8765d1979412b99601bcf4c0ba9d..1138c339dbd1d561fddfad64df3118bfd611c8e7 100644 (file)
                <item name="wcf.acp.option.mail_from_name"><![CDATA[Sender’s Name]]></item>
                <item name="wcf.acp.option.mail_from_name.description"><![CDATA[The sender’s name for all generated emails.]]></item>
                <item name="wcf.acp.option.mail_send_method"><![CDATA[Send Method]]></item>
-               <item name="wcf.acp.option.mail_send_method.debug"><![CDATA[Use Debug]]></item>
+               <item name="wcf.acp.option.mail_send_method.debug"><![CDATA[Use Debug (mbox)]]></item>
+               <item name="wcf.acp.option.mail_send_method.debugFolder"><![CDATA[Use Debug (Folder with .eml files)]]></item>
                <item name="wcf.acp.option.mail_send_method.php"><![CDATA[Use PHP]]></item>
                <item name="wcf.acp.option.mail_send_method.smtp"><![CDATA[Use SMTP]]></item>
                <item name="wcf.acp.option.mail_signature"><![CDATA[Sender’s Signature]]></item>