From a98cc73fc9bff715c366950daa745b27ea3e0f6f Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 10 Dec 2009 14:17:08 -0700 Subject: [PATCH] Move getIMPContents() to IMP_Ui_Compose:: --- imp/compose-mimp.php | 30 ++++++------------------------ imp/compose.php | 23 ++++------------------- imp/lib/Ui/Compose.php | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 43 deletions(-) diff --git a/imp/compose-mimp.php b/imp/compose-mimp.php index 60943d1ff..a6f46f1ab 100644 --- a/imp/compose-mimp.php +++ b/imp/compose-mimp.php @@ -12,20 +12,6 @@ * @package IMP */ -function _getIMPContents($uid, $mailbox) -{ - if (empty($uid)) { - return false; - } - try { - $imp_contents = IMP_Contents::singleton($uid . IMP::IDX_SEP . $mailbox); - return $imp_contents; - } catch (Horde_Exception $e) { - $GLOBALS['notification']->push(_("Could not retrieve the message from the mail server."), 'horde.error'); - return false; - } -} - require_once dirname(__FILE__) . '/lib/Application.php'; new IMP_Application(array('init' => true, 'tz' => true)); @@ -67,9 +53,10 @@ if ($imp_imap->isReadOnly($sent_mail_folder)) { /* Determine if compose mode is disabled. */ $compose_disable = !IMP::canCompose(); -/* Initialize the IMP_Compose:: object. */ +/* Initialize objects. */ $composeCache = Horde_Util::getFormData('composeCache'); $imp_compose = IMP_Compose::singleton($composeCache); +$imp_ui = new IMP_Ui_Compose(); foreach (array_keys($display_hdrs) as $val) { $header[$val] = Horde_Util::getFormData($val); @@ -113,7 +100,6 @@ case 'd': case _("Expand Names"): $action = Horde_Util::getFormData('action'); - $imp_ui = new IMP_Ui_Compose(); foreach (array_keys($display_hdrs) as $val) { if (($val == 'to') || ($action != 'rc')) { @@ -138,7 +124,7 @@ case _("Expand Names"): case 'r': case 'ra': case 'rl': - if (!($imp_contents = _getIMPContents($uid, $thismailbox))) { + if (!($imp_contents = $imp_ui->getIMPContents($uid, $thismailbox))) { break; } $actions = array('r' => 'reply', 'ra' => 'reply_all', 'rl' => 'reply_list'); @@ -150,7 +136,7 @@ case 'rl': // 'f' = forward case 'f': - if (!($imp_contents = _getIMPContents($uid, $thismailbox))) { + if (!($imp_contents = $imp_ui->getIMPContents($uid, $thismailbox))) { break; } $fwd_msg = $imp_compose->forwardMessage($imp_contents); @@ -160,12 +146,10 @@ case 'f': break; case _("Redirect"): - if (!($imp_contents = _getIMPContents($uid, $thismailbox))) { + if (!($imp_contents = $imp_ui->getIMPContents($uid, $thismailbox))) { break; } - $imp_ui = new IMP_Ui_Compose(); - $f_to = $imp_ui->getAddressList($header['to']); try { @@ -207,7 +191,7 @@ case _("Send"): $uid = $imp_compose->getMetadata('uid'); if ($ctype = $imp_compose->getMetadata('reply_type')) { - if (!($imp_contents = _getIMPContents($uid, $thismailbox))) { + if (!($imp_contents = $imp_ui->getIMPContents($uid, $thismailbox))) { break; } @@ -235,8 +219,6 @@ case _("Send"): $header['replyto'] = $identity->getValue('replyto_addr'); $header['subject'] = Horde_Util::getFormData('subject'); - $imp_ui = new IMP_Ui_Compose(); - foreach ($display_hdrs as $val) { $header[$val] = $imp_ui->getAddressList($old_header[$val]); } diff --git a/imp/compose.php b/imp/compose.php index 7914783d9..9b0f9f510 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -40,21 +40,6 @@ function _popupSuccess() require $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc'; } -function _getIMPContents($uid, $mailbox) -{ - if (empty($uid)) { - return false; - } - - try { - $imp_contents = IMP_Contents::singleton($uid . IMP::IDX_SEP . $mailbox); - return $imp_contents; - } catch (Horde_Exception $e) { - $GLOBALS['notification']->push(_("Could not retrieve the message from the mail server."), 'horde.error'); - return false; - } -} - require_once dirname(__FILE__) . '/lib/Application.php'; new IMP_Application(array('init' => array('session_control' => 'netscape'), 'tz' => true)); @@ -242,7 +227,7 @@ if ($_SESSION['imp']['file_upload']) { $title = _("New Message"); switch ($actionID) { case 'mailto': - if (!($imp_contents = _getIMPContents($uid, $thismailbox))) { + if (!($imp_contents = $imp_ui->getIMPContents($uid, $thismailbox))) { break; } $imp_headers = $imp_contents->getHeaderOb(); @@ -293,7 +278,7 @@ case 'reply': case 'reply_all': case 'reply_auto': case 'reply_list': - if (!($imp_contents = _getIMPContents($uid, $thismailbox))) { + if (!($imp_contents = $imp_ui->getIMPContents($uid, $thismailbox))) { break; } @@ -320,7 +305,7 @@ case 'reply_list': break; case 'forward': - if (!($imp_contents = _getIMPContents($uid, $thismailbox))) { + if (!($imp_contents = $imp_ui->getIMPContents($uid, $thismailbox))) { break; } @@ -338,7 +323,7 @@ case 'redirect_compose': break; case 'redirect_send': - if (!($imp_contents = _getIMPContents($uid, $thismailbox))) { + if (!($imp_contents = $imp_ui->getIMPContents($uid, $thismailbox))) { break; } diff --git a/imp/lib/Ui/Compose.php b/imp/lib/Ui/Compose.php index e3e0af87e..83cd5a497 100644 --- a/imp/lib/Ui/Compose.php +++ b/imp/lib/Ui/Compose.php @@ -226,4 +226,25 @@ class IMP_Ui_Compose )); } + /** + * Get the IMP_Contents:: object for a Mailbox -> UID combo. + * + * @param integer $uid Message UID. + * @param string $mailbox Message mailbox. + * + * @return boolean|IMP_Contents The contents object, or false on error. + */ + public function getIMPContents($uid, $mailbox) + { + if (!empty($uid)) { + try { + return IMP_Contents::singleton($uid . IMP::IDX_SEP . $mailbox); + } catch (Horde_Exception $e) { + $GLOBALS['notification']->push(_("Could not retrieve the message from the mail server."), 'horde.error'); + } + } + + return false; + } + } -- 2.11.0