Work around IMAP servers that don't return UIDNEXT
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 27 Mar 2009 06:21:21 +0000 (00:21 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 27 Mar 2009 06:21:21 +0000 (00:21 -0600)
framework/Imap_Client/lib/Horde/Imap/Client/Base.php
framework/Imap_Client/lib/Horde/Imap/Client/Socket.php

index a483e52..bd3130d 100644 (file)
@@ -2414,11 +2414,19 @@ abstract class Horde_Imap_Client_Base
 
         $status = $this->status($mailbox, $query);
 
-        $data = $condstore
-            ? array($status['highestmodseq'], $status['uidvalidity'])
-            : array($status['uidvalidity'], $status['uidnext'], $status['messages']);
+        if ($condstore) {
+            return implode('|', array($status['highestmodseq'], $status['uidvalidity']));
+        }
+
+        if (empty($status['uidnext'])) {
+            /* UIDNEXT is not strictly required on mailbox open. If it is
+             * not available, use the last UID in the mailbox instead. */
+            $search_res = $this->fetch($this->_selected, array(Horde_Imap_Client::FETCH_UID => true), array('ids' => array('*'), 'sequence' => true));
+            $result = reset($search_res);
+            $status['uidnext'] = $result['uid'];
+        }
 
-        return implode('|', $data);
+        return implode('|', array($status['uidvalidity'], $status['uidnext'], $status['messages']));
     }
 
     /**
index bd0fdff..4355367 100644 (file)
@@ -1076,6 +1076,10 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
                 if ($mailbox == $this->_selected) {
                     if (isset($this->_temp['mailbox'][$val])) {
                         $data[$val] = $this->_temp['mailbox'][$val];
+                    } elseif ($key == Horde_Imap_Client::STATUS_UIDNEXT) {
+                        /* UIDNEXT is not strictly required on mailbox open.
+                         * See RFC 3501 [6.3.1]. */
+                        $data[$val] = 0;
                     } else {
                         if ($key == Horde_Imap_Client::STATUS_UIDNOTSTICKY) {
                             /* In the absence of uidnotsticky information, or