[Svn] r4120 - in trunk/roundcubemail: . program/include

trac at roundcube.net trac at roundcube.net
Fri Oct 22 13:13:39 CEST 2010


Author: alec
Date: 2010-10-22 06:13:39 -0500 (Fri, 22 Oct 2010)
New Revision: 4120

Modified:
   trunk/roundcubemail/CHANGELOG
   trunk/roundcubemail/program/include/rcube_imap_generic.php
Log:
- Add LIST-STATUS support in rcube_imap_generic class (RFC5819)


Modified: trunk/roundcubemail/CHANGELOG
===================================================================
--- trunk/roundcubemail/CHANGELOG	2010-10-21 10:49:09 UTC (rev 4119)
+++ trunk/roundcubemail/CHANGELOG	2010-10-22 11:13:39 UTC (rev 4120)
@@ -39,6 +39,7 @@
 - Fix handling of attachments when Content-Disposition is not inline nor attachment (#1487051)
 - Improve performance of unseen messages counting (#1487058)
 - Improve performance of messages counting using ESEARCH extension (RFC4731)
+- Add LIST-STATUS support in rcube_imap_generic class (RFC5819)
 
 RELEASE 0.4.2
 -------------

Modified: trunk/roundcubemail/program/include/rcube_imap_generic.php
===================================================================
--- trunk/roundcubemail/program/include/rcube_imap_generic.php	2010-10-21 10:49:09 UTC (rev 4119)
+++ trunk/roundcubemail/program/include/rcube_imap_generic.php	2010-10-22 11:13:39 UTC (rev 4120)
@@ -1664,17 +1664,52 @@
         return $r;
     }
 
-    function listMailboxes($ref, $mailbox)
+    /**
+     * Returns list of mailboxes
+     *
+     * @param string $ref         Reference name
+     * @param string $mailbox     Mailbox name
+     * @param array  $status_opts (see self::_listMailboxes)
+     *
+     * @return array List of mailboxes or hash of options if $status_opts argument
+     *               is non-empty.
+     * @access public
+     */
+    function listMailboxes($ref, $mailbox, $status_opts=array())
     {
-        return $this->_listMailboxes($ref, $mailbox, false);
+        return $this->_listMailboxes($ref, $mailbox, false, $status_opts);
     }
 
-    function listSubscribed($ref, $mailbox)
+    /**
+     * Returns list of subscribed mailboxes
+     *
+     * @param string $ref         Reference name
+     * @param string $mailbox     Mailbox name
+     * @param array  $status_opts (see self::_listMailboxes)
+     *
+     * @return array List of mailboxes or hash of options if $status_ops argument
+     *               is non-empty.
+     * @access public
+     */
+    function listSubscribed($ref, $mailbox, $status_opts=array())
     {
-        return $this->_listMailboxes($ref, $mailbox, true);
+        return $this->_listMailboxes($ref, $mailbox, true, $status_opts);
     }
 
-    private function _listMailboxes($ref, $mailbox, $subscribed=false)
+    /**
+     * IMAP LIST/LSUB command
+     *
+     * @param string $ref         Reference name
+     * @param string $mailbox     Mailbox name
+     * @param bool   $subscribed  Enables returning subscribed mailboxes only
+     * @param array  $status_opts List of STATUS options (RFC5819: LIST-STATUS)
+     *                            Possible: MESSAGES, RECENT, UIDNEXT, UIDVALIDITY, UNSEEN
+     *
+     * @return array List of mailboxes or hash of options if $status_ops argument
+     *               is non-empty.
+     * @access private
+     */
+    private function _listMailboxes($ref, $mailbox, $subscribed=false, $status_opts=array())
     {
 		if (empty($mailbox)) {
 	        $mailbox = '*';
@@ -1684,16 +1719,42 @@
 	        $ref = $this->rootdir;
 	    }
 
-        list($code, $response) = $this->execute($subscribed ? 'LSUB' : 'LIST',
-            array($this->escape($ref), $this->escape($mailbox)));
+        $args = array($this->escape($ref), $this->escape($mailbox));
 
+        if (!empty($status_opts) && $this->getCapability('LIST-STATUS')) {
+            $status_opts = array($status_opts);
+            $lstatus = true;
+
+            $args[] = 'RETURN (STATUS (' . implode(' ', $status_opts) . '))';
+        }
+
+        list($code, $response) = $this->execute($subscribed ? 'LSUB' : 'LIST', $args);
+
         if ($code == self::ERROR_OK) {
             $folders = array();
             while ($this->tokenizeResponse($response, 1) == '*') {
-                list (,$opts, $delim, $folder) = $this->tokenizeResponse($response, 4);
-        		// folder name
-   			    $folders[] = $folder;
+                $cmd = strtoupper($this->tokenizeResponse($response, 1));
+                // * LIST (<options>) <delimiter> <mailbox>
+                if (!$lstatus || $cmd == 'LIST' || $cmd == 'LSUB') {
+                    list($opts, $delim, $folder) = $this->tokenizeResponse($response, 3);
+                    if (!$lstatus) {
+           			    $folders[] = $folder;
+                    }
+                    else {
+                        $folders[$folder] = array();
+                    }
+                }
+                // * STATUS <mailbox> (<result>)
+                else if ($cmd == 'STATUS') {
+                    list($folder, $status) = $this->tokenizeResponse($response, 2);
+
+                    for ($i=0, $len=count($status); $i<$len; $i += 2) {
+                        list($name, $value) = $this->tokenizeResponse($status, 2);
+                        $folders[$folder][$name] = $value;
+                    }
+                }
 		    }
+
             return $folders;
         }
 

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list