From 29566e95072fa5ac743580dee3acea90f2b5b384 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 20 Nov 2009 16:13:09 -0700 Subject: [PATCH] Handle non-existent mailboxes better --- imp/ajax.php | 15 ++++++++++++--- imp/js/ViewPort.js | 2 +- imp/lib/Views/ListMessages.php | 33 ++++++++++++++++++++++++--------- imp/mailbox.php | 6 +++++- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/imp/ajax.php b/imp/ajax.php index 3671a2fe8..c5917081c 100644 --- a/imp/ajax.php +++ b/imp/ajax.php @@ -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); } diff --git a/imp/js/ViewPort.js b/imp/js/ViewPort.js index 517b49f83..662d6e86f 100644 --- a/imp/js/ViewPort.js +++ b/imp/js/ViewPort.js @@ -724,7 +724,7 @@ var ViewPort = Class.create({ } } - if (r.cacheid) { + if (!Object.isUndefined(r.cacheid)) { this._ajaxResponse(r); } }, diff --git a/imp/lib/Views/ListMessages.php b/imp/lib/Views/ListMessages.php index f85d62192..5bb7a4777 100644 --- a/imp/lib/Views/ListMessages.php +++ b/imp/lib/Views/ListMessages.php @@ -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; + } + } diff --git a/imp/mailbox.php b/imp/mailbox.php index 036d6e743..31a95daca 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -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. */ -- 2.11.0