Handle non-existent mailboxes better
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 20 Nov 2009 23:13:09 +0000 (16:13 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 20 Nov 2009 23:54:59 +0000 (16:54 -0700)
imp/ajax.php
imp/js/ViewPort.js
imp/lib/Views/ListMessages.php
imp/mailbox.php

index 3671a2f..c591708 100644 (file)
@@ -374,9 +374,18 @@ case 'ViewPort':
 
     $changed = _changed($mbox, $cacheid, false);
 
-    if ($changed ||
-        Horde_Util::getPost('rangeslice') ||
-        !Horde_Util::getPost('checkcache')) {
+    if (is_null($changed)) {
+        $list_msg = new IMP_Views_ListMessages();
+        $result = new stdClass;
+        $result->ViewPort = $list_msg->getBaseOb($mbox);
+
+        $req_id = Horde_Util::getPost('requestid');
+        if (!is_null($req_id)) {
+            $result->ViewPort->requestid = intval($req_id);
+        }
+    } elseif ($changed ||
+              Horde_Util::getPost('rangeslice') ||
+              !Horde_Util::getPost('checkcache')) {
         $result = new stdClass;
         $result->ViewPort = _getListMessages($mbox, $changed);
     }
index 517b49f..662d6e8 100644 (file)
@@ -724,7 +724,7 @@ var ViewPort = Class.create({
             }
         }
 
-        if (r.cacheid) {
+        if (!Object.isUndefined(r.cacheid)) {
             this._ajaxResponse(r);
         }
     },
index f85d621..5bb7a47 100644 (file)
@@ -72,8 +72,6 @@ class IMP_Views_ListMessages
             }
         }
 
-        $label = IMP::getLabel($mbox);
-
         /* Set the current time zone. */
         Horde_Nls::setTimeZone();
 
@@ -93,11 +91,9 @@ class IMP_Views_ListMessages
         $msgcount = count($sorted_list['s']);
 
         /* Create the base object. */
-        $result = new stdClass;
-        $result->view = $mbox;
-        $result->totalrows = $msgcount;
-        $result->label = $label;
+        $result = $this->getBaseOb($mbox);
         $result->cacheid = $imp_mailbox->getCacheID();
+        $result->totalrows = $msgcount;
 
         /* If this is the initial request for a mailbox, figure out the
          * starting location based on user's preferences. */
@@ -136,7 +132,6 @@ class IMP_Views_ListMessages
         $slice_end = min($msgcount, $slice_end);
 
         /* Mail-specific viewport information. */
-        $result->metadata = new stdClass;
         $md = &$result->metadata;
         if (!IMP::threadSortAvailable($mbox)) {
             $md->nothread = 1;
@@ -162,10 +157,9 @@ class IMP_Views_ListMessages
         if (empty($msgcount) && !isset($md->search)) {
             $imp_folder = IMP_Folder::singleton();
             if (!$imp_folder->exists($mbox)) {
-                $GLOBALS['notification']->push(sprintf(_("Mailbox %s does not exist."), $label), 'horde.error');
+                $GLOBALS['notification']->push(sprintf(_("Mailbox %s does not exist."), IMP::getLabel($mbox)), 'horde.error');
             }
 
-            $result->data = $result->rowlist = array();
             return $result;
         }
 
@@ -357,4 +351,25 @@ class IMP_Views_ListMessages
         return $msgs;
     }
 
+    /**
+     * Prepare the base object used by the ViewPort javascript object.
+     *
+     * @param string $mbox  The mailbox name.
+     *
+     * @return object  The base ViewPort object.
+     */
+    public function getBaseOb($mbox)
+    {
+        $ob = new stdClass;
+        $ob->cacheid = 0;
+        $ob->data = array();
+        $ob->label = IMP::getLabel($mbox);
+        $ob->metadata = new stdClass;
+        $ob->rowlist = array();
+        $ob->totalrows = 0;
+        $ob->view = $mbox;
+
+        return $ob;
+    }
+
 }
index 036d6e7..31a95da 100644 (file)
@@ -93,7 +93,11 @@ if ($actionID && ($actionID != 'message_missing')) {
  * select it on the IMAP server (saves some STATUS calls). Open R/W to clear
  * the RECENT flag. */
 if (!$search_mbox) {
-    $imp_imap->ob()->openMailbox($imp_mbox['mailbox'], Horde_Imap_Client::OPEN_READWRITE);
+    try {
+        $imp_imap->ob()->openMailbox($imp_mbox['mailbox'], Horde_Imap_Client::OPEN_READWRITE);
+    } catch (Horde_Imap_Client_Exception $e) {
+        $actionID = null;
+    }
 }
 
 /* Determine if mailbox is readonly. */