public function sendMessage($email, $headers, $message)
{
$email = $this->_prepSendMessage($email, $headers, $message);
-
- $mail_driver = $this->getMailDriver();
- try {
- $mailer = Horde_Mime_Mail::getMailOb($mail_driver['driver'], $mail_driver['params']);
- } catch (Horde_Mime_Exception $e) {
- throw new IMP_Compose_Exception($e);
- }
+ $mailer = $this->getMailOb();
try {
$message->send($email, $headers, $mailer);
}
/**
- * Return mail driver/params necessary to send a message.
- *
- * @return array 'driver' => mail driver; 'params' => list of params.
- */
- static public function getMailDriver()
- {
- /* We don't actually want to alter the contents of the $conf['mailer']
- * array, so we make a copy of the current settings. We will apply our
- * modifications (if any) to the copy, instead. */
- $params = $GLOBALS['conf']['mailer']['params'];
-
- /* Force the SMTP host and port value to the current SMTP server if
- * one has been selected for this connection. */
- if (!empty($_SESSION['imp']['smtp'])) {
- $params = array_merge($params, $_SESSION['imp']['smtp']);
- }
-
- /* If SMTP authentication has been requested, use either the username
- * and password provided in the configuration or populate the username
- * and password fields based on the current values for the user. Note
- * that we assume that the username and password values from the
- * current IMAP / POP3 connection are valid for SMTP authentication as
- * well. */
- if (!empty($params['auth']) && empty($params['username'])) {
- $params['username'] = $GLOBALS['imp_imap']->ob()->getParam('username');
- $params['password'] = $GLOBALS['imp_imap']->ob()->getParam('password');
- }
-
- return array(
- 'driver' => $GLOBALS['conf']['mailer']['type'],
- 'params' => $params
- );
- }
-
- /**
* Save the recipients done in a sendMessage().
*
* @param string $recipients The list of recipients.
$header_text = trim($resent_headers->toString(array('encode' => Horde_Nls::getCharset()))) . "\n" . trim($contents->getHeaderOb(false));
- $mail_driver = $this->getMailDriver();
- try {
- $mailer = Horde_Mime_Mail::getMailOb($mail_driver['driver'], $mail_driver['params'], array('raw' => array('from' => $headers->getValue('from'), 'headertext' => $header_text)));
- } catch (Horde_Mime_Exception $e) {
- throw new IMP_Compose_Exception($e);
- }
+ $mailer = $this->getMailOb(array(
+ 'raw' => array('from' => $headers->getValue('from'), 'headertext' => $header_text)
+ ));
$to = $this->_prepSendMessage($recipients);
}
/**
+ * If this object contains sufficient metadata, return an IMP_Contents
+ * object reflecting that metadata.
+ *
+ * @return mixed Either an IMP_Contents object or null.
+ */
+ public function getContentsOb()
+ {
+ return $this->getMetadata('reply_type')
+ ? IMP_Contents::singleton($this->getMetadata('uid') . IMP::IDX_SEP . $this->getMetadata('mailbox'))
+ : null;
+ }
+
+ /* Static utility functions. */
+
+ /**
+ * Return mail driver/params necessary to send a message.
+ *
+ * @return array 'driver' => mail driver; 'params' => list of params.
+ */
+ static public function getMailDriver()
+ {
+ /* We don't actually want to alter the contents of the $conf['mailer']
+ * array, so we make a copy of the current settings. We will apply our
+ * modifications (if any) to the copy, instead. */
+ $params = $GLOBALS['conf']['mailer']['params'];
+
+ /* Force the SMTP host and port value to the current SMTP server if
+ * one has been selected for this connection. */
+ if (!empty($_SESSION['imp']['smtp'])) {
+ $params = array_merge($params, $_SESSION['imp']['smtp']);
+ }
+
+ /* If SMTP authentication has been requested, use either the username
+ * and password provided in the configuration or populate the username
+ * and password fields based on the current values for the user. Note
+ * that we assume that the username and password values from the
+ * current IMAP / POP3 connection are valid for SMTP authentication as
+ * well. */
+ if (!empty($params['auth']) && empty($params['username'])) {
+ $params['username'] = $GLOBALS['imp_imap']->ob()->getParam('username');
+ $params['password'] = $GLOBALS['imp_imap']->ob()->getParam('password');
+ }
+
+ return array(
+ 'driver' => $GLOBALS['conf']['mailer']['type'],
+ 'params' => $params
+ );
+ }
+
+ /**
+ * Return a Mail object with the current driver parameters.
+ *
+ * @param array $options Additional options to pass to
+ * Horde_Mime_Mail::getMailOb().
+ *
+ * @return Mail A Mail object.
+ * @throws IMP_Compose_Exception
+ */
+ static public function getMailOb($options = array())
+ {
+ $mail_driver = self::getMailDriver();
+
+ try {
+ return Horde_Mime_Mail::getMailOb($mail_driver['driver'], $mail_driver['params'], $options);
+ } catch (Horde_Mime_Exception $e) {
+ throw new IMP_Compose_Exception($e);
+ }
+ }
+
+ /**
* Formats the address properly.
*
* @param string $addr The address to format.
return array('sources' => $src, 'fields' => $fields);
}
- /**
- * If this object contains sufficient metadata, return an IMP_Contents
- * object reflecting that metadata.
- *
- * @return mixed Either an IMP_Contents object or null.
- */
- public function getContentsOb()
- {
- return $this->getMetadata('reply_type')
- ? IMP_Contents::singleton($this->getMetadata('uid') . IMP::IDX_SEP . $this->getMetadata('mailbox'))
- : null;
- }
-
}
$msg_headers->addHeader('Subject', Horde_Mime::encode($subject, $charset));
// Send the reply.
- $mail_driver = IMP_Compose::getMailDriver();
try {
- $mime->send($organizerEmail, $msg_headers,
- $mail_driver['driver'],
- $mail_driver['params']);
+ $mailer = IMP_Compose::getMailOb();
+ $mime->send($organizerEmail, $msg_headers, $mailer);
$msgs[] = array('success', _("Reply Sent."));
- } catch (Horde_Mime_Exception $e) {
+ } catch (Exception $e) {
$msgs[] = array('error', sprintf(_("Error sending reply: %s."), $e->getMessage()));
}
} else {
$msg_headers->addHeader('Subject', Horde_Mime::encode(_("Free/Busy Request Response"), $charset));
// Send the reply.
- $mail_driver = IMP_Compose::getMailDriver();
try {
- $mime->send($organizerEmail, $msg_headers,
- $mail_driver['driver'],
- $mail_driver['params']);
+ $mailer = IMP_Compose::getMailOb();
+ $mime->send($organizerEmail, $msg_headers, $mailer);
$msgs[] = array('success', _("Reply Sent."));
- } catch (Horde_Mime_Exception $e) {
+ } catch (Exception $e) {
$msgs[] = array('error', sprintf(_("Error sending reply: %s."), $e->getMessage()));
}
} else {