From: Michael M Slusarz Date: Thu, 25 Mar 2010 04:46:51 +0000 (-0600) Subject: Add Horde_Mail_Mime::getMailOb() X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=804f78bcddd4b6253bedfe861a3794a13a726406;p=horde.git Add Horde_Mail_Mime::getMailOb() --- diff --git a/framework/Core/lib/Horde/Core/Binder/Mail.php b/framework/Core/lib/Horde/Core/Binder/Mail.php index cb0f92f11..7be449f5b 100644 --- a/framework/Core/lib/Horde/Core/Binder/Mail.php +++ b/framework/Core/lib/Horde/Core/Binder/Mail.php @@ -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) diff --git a/framework/Mime/lib/Horde/Mime/Mail.php b/framework/Mime/lib/Horde/Mime/Mail.php index cb6d2801d..d58d4f195 100644 --- a/framework/Mime/lib/Horde/Mime/Mail.php +++ b/framework/Mime/lib/Horde/Mime/Mail.php @@ -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: + *
+     * '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.
+     * 
+ * + * @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 index 000000000..df4003c71 --- /dev/null +++ b/framework/Mime/lib/Horde/Mime/Mail/mail.php @@ -0,0 +1,59 @@ + + * @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: + *
+     * 'from' - (string) The From address to use.
+     * 'headertext' - (string) The raw headertext to use.
+     * 
+ */ + 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 index 000000000..9e0b9ac32 --- /dev/null +++ b/framework/Mime/lib/Horde/Mime/Mail/sendmail.php @@ -0,0 +1,59 @@ + + * @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: + *
+     * 'from' - (string) The From address to use.
+     * 'headertext' - (string) The raw headertext to use.
+     * 
+ */ + 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 index 000000000..f6025dc94 --- /dev/null +++ b/framework/Mime/lib/Horde/Mime/Mail/smtp.php @@ -0,0 +1,59 @@ + + * @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: + *
+     * 'from' - (string) The From address to use.
+     * 'headertext' - (string) The raw headertext to use.
+     * 
+ */ + 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 index 000000000..99bdef7f3 --- /dev/null +++ b/framework/Mime/lib/Horde/Mime/Mail/smtpmx.php @@ -0,0 +1,59 @@ + + * @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: + *
+     * 'from' - (string) The From address to use.
+     * 'headertext' - (string) The raw headertext to use.
+     * 
+ */ + 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/package.xml b/framework/Mime/package.xml index a2c7c69f9..2f12530bb 100644 --- a/framework/Mime/package.xml +++ b/framework/Mime/package.xml @@ -31,7 +31,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> alpha LGPL - + * 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"> + + + + + + @@ -216,6 +222,10 @@ http://pear.php.net/dtd/package-2.0.xsd"> + + + +