Add Horde_Mail_Mime::getMailOb()
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 25 Mar 2010 04:46:51 +0000 (22:46 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 25 Mar 2010 04:48:05 +0000 (22:48 -0600)
framework/Core/lib/Horde/Core/Binder/Mail.php
framework/Mime/lib/Horde/Mime/Mail.php
framework/Mime/lib/Horde/Mime/Mail/mail.php [new file with mode: 0644]
framework/Mime/lib/Horde/Mime/Mail/sendmail.php [new file with mode: 0644]
framework/Mime/lib/Horde/Mime/Mail/smtp.php [new file with mode: 0644]
framework/Mime/lib/Horde/Mime/Mail/smtpmx.php [new file with mode: 0644]
framework/Mime/package.xml

index cb0f92f..7be449f 100644 (file)
@@ -13,12 +13,11 @@ class Horde_Core_Binder_Mail implements Horde_Injector_Binder
             $params['password'] = Horde_Auth::getCredential('password');
         }
 
-        $result = Mail::factory($driver, $params);
-        if ($result instanceof PEAR_Error) {
-            throw new Horde_Exception($result);
+        try {
+            return Horde_Mime_Mail::getMailOb($driver, $params);
+        } catch (Horde_Mime_Exception $e) {
+            throw new Horde_Exception($e);
         }
-
-        return $result;
     }
 
     public function equals(Horde_Injector_Binder $binder)
index cb6d280..d58d4f1 100644 (file)
@@ -475,6 +475,50 @@ class Horde_Mime_Mail
     }
 
     /**
+     * Utility function to create a Mail object.
+     *
+     * @param string $driver  The mail driver.
+     * @param array $params   The mail parameters.
+     * @param array $options  Additional options:
+     * <pre>
+     * 'raw' - (array) If set, will use the value contained in 'headertext'
+     *         as the exact data to use for the message header. Additionally,
+     *         the 'from' key should contain the From address to use.
+     * </pre>
+     *
+     * @return Mail  A Mail object.
+     * @throws Horde_Mime_Exception
+     */
+    static public function getMailOb($driver, $params, $options = array())
+    {
+        if (!empty($options['raw'])) {
+            switch ($driver) {
+            case 'mail':
+            case 'sendmail':
+            case 'smtp':
+            case 'smtpmx':
+                /* Can't autoload - Mail doesn't support it. */
+                require_once dirname(__FILE__) . '/Mail/' . $driver . '.php';
+                $driver = 'horde_mime_' . $driver;
+                $params['from'] = empty($options['raw']['from'])
+                    ? ''
+                    : $options['raw']['from'];
+                $params['headertext'] = empty($options['raw']['headertext'])
+                    ? ''
+                    : $options['raw']['headertext'];
+                break;
+            }
+        }
+
+        $mailer = Mail::factory($driver, $params);
+        if ($mailer instanceof PEAR_Error) {
+            throw new Horde_Mime_Exception($mailer);
+        }
+
+        return $mailer;
+    }
+
+    /**
      * Utility function to send a message using a PEAR Mail driver. Handles
      * errors from this class.
      *
diff --git a/framework/Mime/lib/Horde/Mime/Mail/mail.php b/framework/Mime/lib/Horde/Mime/Mail/mail.php
new file mode 100644 (file)
index 0000000..df4003c
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+/**
+ * Extends mail Mail driver by allowing unaltered headers to be sent.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package Horde_Mime
+ */
+class Mail_horde_mime_mail extends Mail_mail
+{
+    /**
+     * The From address to use.
+     *
+     * @var string
+     */
+    protected $_from;
+
+    /**
+     * The raw headertext to use.
+     *
+     * @var string
+     */
+    protected $_headertext;
+
+    /**
+     * Constructor.
+     *
+     * @param array $params  Configuration parameters:
+     * <pre>
+     * 'from' - (string) The From address to use.
+     * 'headertext' - (string) The raw headertext to use.
+     * </pre>
+     */
+    public function __construct($params)
+    {
+        $this->_from = $params['from'];
+        $this->_headertext = $params['headertext'];
+        unset($params['from'], $params['headertext']);
+
+        parent::__construct($params);
+    }
+
+    /**
+     * Prepare headers for sending.
+     *
+     * @param array $headers  The headers array (not used).
+     *
+     * @return array  2 elements: the from address and the header text.
+     */
+    public function prepareHeaders($headers)
+    {
+        return array($this->_from, $this->_headertext);
+    }
+
+}
diff --git a/framework/Mime/lib/Horde/Mime/Mail/sendmail.php b/framework/Mime/lib/Horde/Mime/Mail/sendmail.php
new file mode 100644 (file)
index 0000000..9e0b9ac
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+/**
+ * Extends Sendmail Mail driver by allowing unaltered headers to be sent.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package Horde_Mime
+ */
+class Mail_horde_mime_sendmail extends Mail_sendmail
+{
+    /**
+     * The From address to use.
+     *
+     * @var string
+     */
+    protected $_from;
+
+    /**
+     * The raw headertext to use.
+     *
+     * @var string
+     */
+    protected $_headertext;
+
+    /**
+     * Constructor.
+     *
+     * @param array $params  Configuration parameters:
+     * <pre>
+     * 'from' - (string) The From address to use.
+     * 'headertext' - (string) The raw headertext to use.
+     * </pre>
+     */
+    public function __construct($params)
+    {
+        $this->_from = $params['from'];
+        $this->_headertext = $params['headertext'];
+        unset($params['from'], $params['headertext']);
+
+        parent::__construct($params);
+    }
+
+    /**
+     * Prepare headers for sending.
+     *
+     * @param array $headers  The headers array (not used).
+     *
+     * @return array  2 elements: the from address and the header text.
+     */
+    public function prepareHeaders($headers)
+    {
+        return array($this->_from, $this->_headertext);
+    }
+
+}
diff --git a/framework/Mime/lib/Horde/Mime/Mail/smtp.php b/framework/Mime/lib/Horde/Mime/Mail/smtp.php
new file mode 100644 (file)
index 0000000..f6025dc
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+/**
+ * Extends Smtp Mail driver by allowing unaltered headers to be sent.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package Horde_Mime
+ */
+class Mail_horde_mime_smtp extends Mail_smtp
+{
+    /**
+     * The From address to use.
+     *
+     * @var string
+     */
+    protected $_from;
+
+    /**
+     * The raw headertext to use.
+     *
+     * @var string
+     */
+    protected $_headertext;
+
+    /**
+     * Constructor.
+     *
+     * @param array $params  Configuration parameters:
+     * <pre>
+     * 'from' - (string) The From address to use.
+     * 'headertext' - (string) The raw headertext to use.
+     * </pre>
+     */
+    public function __construct($params)
+    {
+        $this->_from = $params['from'];
+        $this->_headertext = $params['headertext'];
+        unset($params['from'], $params['headertext']);
+
+        parent::__construct($params);
+    }
+
+    /**
+     * Prepare headers for sending.
+     *
+     * @param array $headers  The headers array (not used).
+     *
+     * @return array  2 elements: the from address and the header text.
+     */
+    public function prepareHeaders($headers)
+    {
+        return array($this->_from, $this->_headertext);
+    }
+
+}
diff --git a/framework/Mime/lib/Horde/Mime/Mail/smtpmx.php b/framework/Mime/lib/Horde/Mime/Mail/smtpmx.php
new file mode 100644 (file)
index 0000000..99bdef7
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+/**
+ * Extends Smtpmx Mail driver by allowing unaltered headers to be sent.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package Horde_Mime
+ */
+class Mail_horde_mime_smtpmx extends Mail_smtpmx
+{
+    /**
+     * The From address to use.
+     *
+     * @var string
+     */
+    protected $_from;
+
+    /**
+     * The raw headertext to use.
+     *
+     * @var string
+     */
+    protected $_headertext;
+
+    /**
+     * Constructor.
+     *
+     * @param array $params  Configuration parameters:
+     * <pre>
+     * 'from' - (string) The From address to use.
+     * 'headertext' - (string) The raw headertext to use.
+     * </pre>
+     */
+    public function __construct($params)
+    {
+        $this->_from = $params['from'];
+        $this->_headertext = $params['headertext'];
+        unset($params['from'], $params['headertext']);
+
+        parent::__construct($params);
+    }
+
+    /**
+     * Prepare headers for sending.
+     *
+     * @param array $headers  The headers array (not used).
+     *
+     * @return array  2 elements: the from address and the header text.
+     */
+    public function prepareHeaders($headers)
+    {
+        return array($this->_from, $this->_headertext);
+    }
+
+}
index a2c7c69..2f12530 100644 (file)
@@ -31,7 +31,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
   <api>alpha</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>
+ <notes>* Add Mail driver extensions (raw header output).
  * No need to generate Content-Transfer-Encoding header if part data is 7bit.
  * Default disposition should be empty by default, not inline (RFC 2183 [2]).
  * Request #8556: Allow specifying a header charset for a part.
@@ -49,6 +49,12 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <dir name="lib">
     <dir name="Horde">
      <dir name="Mime">
+      <dir name="Mail">
+       <file name="mail.php" role="php" />
+       <file name="sendmail.php" role="php" />
+       <file name="smtp.php" role="php" />
+       <file name="smtpmx.php" role="php" />
+      </dir> <!-- /lib/Horde/Mime/Mail -->
       <dir name="Viewer">
        <dir name="Ooo">
         <file name="common.xsl" role="php" />
@@ -216,6 +222,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
  </dependencies>
  <phprelease>
   <filelist>
+   <install name="lib/Horde/Mime/Mail/mail.php" as="Horde/Mime/Mail/mail.php" />
+   <install name="lib/Horde/Mime/Mail/sendmail.php" as="Horde/Mime/Mail/sendmail.php" />
+   <install name="lib/Horde/Mime/Mail/smtp.php" as="Horde/Mime/Mail/smtp.php" />
+   <install name="lib/Horde/Mime/Mail/smtpmx.php" as="Horde/Mime/Mail/smtpmx.php" />
    <install name="lib/Horde/Mime/Viewer/Ooo/common.xsl" as="Horde/Mime/Viewer/Ooo/common.xsl" />
    <install name="lib/Horde/Mime/Viewer/Ooo/global_document.xsl" as="Horde/Mime/Viewer/Ooo/global_document.xsl" />
    <install name="lib/Horde/Mime/Viewer/Ooo/main_html.xsl" as="Horde/Mime/Viewer/Ooo/main_html.xsl" />