From 996d75d5fa4a5052094a64cf82d78c4375a5e797 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 23 May 2012 03:19:51 -0400
Subject: [PATCH] Improved PERMANENTFLAGS checking code, added code for flags caching (currently commented out)

---
 program/include/rcube_imap.php |   58 +++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 49 insertions(+), 9 deletions(-)

diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index b966aa3..bfa84b4 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -19,9 +19,6 @@
  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
  | Author: Aleksander Machniak <alec@alec.pl>                            |
  +-----------------------------------------------------------------------+
-
- $Id$
-
 */
 
 
@@ -404,15 +401,56 @@
      */
     public function check_permflag($flag)
     {
-        $flag = strtoupper($flag);
-        $imap_flag = $this->conn->flags[$flag];
+        $flag       = strtoupper($flag);
+        $imap_flag  = $this->conn->flags[$flag];
+        $perm_flags = $this->get_permflags($this->folder);
 
-        if ($this->folder !== null) {
-            $this->check_connection();
+        return in_array_nocase($imap_flag, $perm_flags);
+    }
+
+
+    /**
+     * Returns PERMANENTFLAGS of the specified folder
+     *
+     * @param  string $folder Folder name
+     *
+     * @return array Flags
+     */
+    public function get_permflags($folder)
+    {
+        if (!strlen($folder)) {
+            return array();
         }
-        // @TODO: cache permanent flags (?)
+/*
+        Checking PERMANENTFLAGS is rather rare, so we disable caching of it
+        Re-think when we'll use it for more than only MDNSENT flag
 
-        return (in_array_nocase($imap_flag, $this->conn->data['PERMANENTFLAGS']));
+        $cache_key = 'mailboxes.permanentflags.' . $folder;
+        $permflags = $this->get_cache($cache_key);
+
+        if ($permflags !== null) {
+            return explode(' ', $permflags);
+        }
+*/
+        if (!$this->check_connection()) {
+            return array();
+        }
+
+        if ($this->conn->select($folder)) {
+            $permflags = $this->conn->data['PERMANENTFLAGS'];
+        }
+        else {
+            return array();
+        }
+
+        if (!is_array($permflags)) {
+            $permflags = array();
+        }
+/*
+        // Store permflags as string to limit cached object size
+        $this->update_cache($cache_key, implode(' ', $permflags));
+*/
+        return $permflags;
     }
 
 
@@ -2670,6 +2708,8 @@
             return array();
         }
 
+        $config = rcube::get_instance()->config;
+
         // #1486796: some server configurations doesn't return folders in all namespaces
         if ($root == '' && $name == '*' && $config->get('imap_force_ns')) {
             $this->list_folders_update($result);

--
Gitblit v1.9.1