From ee3c580bfe56e3d053e469b229463d4c45fa63af Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Fri, 02 Oct 2009 06:58:12 -0400
Subject: [PATCH] - added @TODO comment

---
 program/include/rcube_imap.php |   51 ++++++++++++++++++++++++++++++---------------------
 1 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 96a4a65..6e98b20 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -485,7 +485,6 @@
    */
   private function _messagecount($mailbox='', $mode='ALL', $force=FALSE)
     {
-    $a_mailbox_cache = FALSE;
     $mode = strtoupper($mode);
 
     if (empty($mailbox))
@@ -1225,6 +1224,18 @@
         $this->struct_charset = $headers->charset;
       else
         $this->struct_charset = $this->_structure_charset($structure);
+
+      /*
+        @TODO: here we can recognize malformed BODYSTRUCTURE and parse
+	the message in other way to create our own message structure.
+	Example of structure for malformed MIME message:
+	("text" "plain" ("charset" "us-ascii") NIL NIL "7bit" 2154 70 NIL NIL NIL)
+
+	if ($headers->ctype != 'text/plain'
+	  && !is_array($structure[0]) && $structure[0] == 'text' 
+	  && !is_array($structure[1]) && $structure[1] == 'plain') 
+	  { }
+      */
 
       $struct = &$this->_structure_part($structure);
       $struct->headers = get_object_vars($headers);
@@ -2140,8 +2151,8 @@
    */
   function get_cache($key)
     {
-    // read cache
-    if (!isset($this->cache[$key]) && $this->caching_enabled)
+    // read cache (if it was not read before)
+    if (!count($this->cache) && $this->caching_enabled)
       {
       return $this->_read_cache_record($key);
       }
@@ -2218,7 +2229,8 @@
         {
 	$sql_key = preg_replace('/^IMAP\./', '', $sql_arr['cache_key']);
         $this->cache_keys[$sql_key] = $sql_arr['cache_id'];
-	$this->cache[$sql_key] = $sql_arr['data'] ? unserialize($sql_arr['data']) : FALSE;
+	if (!isset($this->cache[$sql_key]))
+	  $this->cache[$sql_key] = $sql_arr['data'] ? unserialize($sql_arr['data']) : FALSE;
         }
       }
 
@@ -2232,23 +2244,6 @@
     {
     if (!$this->db)
       return FALSE;
-
-    // check if we already have a cache entry for this key
-    if (!isset($this->cache_keys[$key]))
-      {
-      $sql_result = $this->db->query(
-        "SELECT cache_id
-         FROM ".get_table_name('cache')."
-         WHERE  user_id=?
-         AND    cache_key=?",
-        $_SESSION['user_id'],
-        'IMAP.'.$key);
-                                     
-      if ($sql_arr = $this->db->fetch_assoc($sql_result))
-        $this->cache_keys[$key] = $sql_arr['cache_id'];
-      else
-        $this->cache_keys[$key] = FALSE;
-      }
 
     // update existing cache record
     if ($this->cache_keys[$key])
@@ -2272,6 +2267,18 @@
         $_SESSION['user_id'],
         'IMAP.'.$key,
         $data);
+
+      // get cache entry ID for this key
+      $sql_result = $this->db->query(
+        "SELECT cache_id
+         FROM ".get_table_name('cache')."
+         WHERE  user_id=?
+         AND    cache_key=?",
+        $_SESSION['user_id'],
+        'IMAP.'.$key);
+                                     
+        if ($sql_arr = $this->db->fetch_assoc($sql_result))
+          $this->cache_keys[$key] = $sql_arr['cache_id'];
       }
     }
 
@@ -2286,6 +2293,8 @@
        AND    cache_key=?",
       $_SESSION['user_id'],
       'IMAP.'.$key);
+      
+    unset($this->cache_keys[$key]);
     }
 
 

--
Gitblit v1.9.1