Move getIMPContents() to IMP_Ui_Compose::
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 10 Dec 2009 21:17:08 +0000 (14:17 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 10 Dec 2009 21:17:15 +0000 (14:17 -0700)
imp/compose-mimp.php
imp/compose.php
imp/lib/Ui/Compose.php

index 60943d1..a6f46f1 100644 (file)
  * @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]);
     }
index 7914783..9b0f9f5 100644 (file)
@@ -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;
     }
 
index e3e0af8..83cd5a4 100644 (file)
@@ -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;
+    }
+
 }