From cc95700b58f31f04470db8271a09d6e52ba9a63d Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Sun, 05 Feb 2006 10:38:51 -0500
Subject: [PATCH] Added message cache garbage collector

---
 program/include/main.inc |   71 +++++++++++++++++++++++++----------
 1 files changed, 50 insertions(+), 21 deletions(-)

diff --git a/program/include/main.inc b/program/include/main.inc
index 307a880..ac612cd 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -21,6 +21,7 @@
 
 require_once('lib/des.inc');
 require_once('lib/utf7.inc');
+require_once('lib/utf8.class.php');
 
 
 // register session and connect to server
@@ -70,7 +71,7 @@
 
   // we can use the database for storing session data
   // session queries do not work with MDB2
-  if ($CONFIG['db_backend']!='mdb2' && is_object($DB) /* && $DB->db_provider!='sqlite' */)
+  if ($CONFIG['db_backend']!='mdb2' && is_object($DB))
     include_once('include/session.inc');
 
 
@@ -696,38 +697,63 @@
   }
 
 
+// remove all expired message cache records
+function rcmail_message_cache_gc()
+  {
+  global $DB, $CONFIG;
+  
+  // no cache lifetime configured
+  if (empty($CONFIG['message_cache_lifetime']))
+    return;
+  
+  // get target timestamp
+  $ts = get_offset_time($CONFIG['message_cache_lifetime'], -1);
+  
+  $DB->query("DELETE FROM ".get_table_name('messages')."
+             WHERE  created < ".$DB->fromunixtime($ts));
+  }
+
 
 // convert a string from one charset to another
 // this function is not complete and not tested well
 function rcube_charset_convert($str, $from, $to=NULL)
   {
-  $from = strtolower($from);
-  $to = $to==NULL ? strtolower($GLOBALS['CHARSET']) : strtolower($to);
+  $from = strtoupper($from);
+  $to = $to==NULL ? strtoupper($GLOBALS['CHARSET']) : strtoupper($to);
   
   if ($from==$to)
     return $str;
-  
-  // decode characters
-  if ($from=='utf-7')
-    $str = UTF7DecodeString($str);
-  else if ($from=='utf-8' && function_exists('utf8_decode'))
-    $str = utf8_decode($str);
-  else if ($from=="koi8-r")
-    $str = convert_cyr_string($str, 'k', 'i');
-  else if ($from=="windows-1251" || $from=="win-1251")
-    $str = convert_cyr_string($str, 'w', 'i');
-  else if ($from=="x-cp866")
-    $str = convert_cyr_string($str, 'a', 'i');
-  else if ($from=="x-mac-cyrillic")
-    $str = convert_cyr_string($str, 'm', 'i');
+    
+  // convert charset using iconv module  
+  if (function_exists('iconv') && $from!='UTF-7' && $to!='UTF-7') {
+    return iconv($from, $to, $str);
+    }
+
+  $conv = new utf8();
+
+  // convert string to UTF-8
+  if ($from=='UTF-7')
+    $str = rcube_charset_convert(UTF7DecodeString($str), 'ISO-8859-1');
+  else if ($from=='ISO-8859-1' && function_exists('utf8_encode'))
+    $str = utf8_encode($str);
+  else if ($from!='UTF-8')
+    {
+    $conv->loadCharset($from);
+    $str = $conv->strToUtf8($str);
+    }
 
   // encode string for output
-  if ($to=='utf-8' && function_exists('utf8_encode'))
-    return utf8_encode($str);
-  else if ($to=='utf-7')
+  if ($to=='UTF-7')
     return UTF7EncodeString($str);
+  else if ($to=='ISO-8859-1' && function_exists('utf8_decode'))
+    return utf8_decode($str);
+  else if ($to!='UTF-8')
+    {
+    $conv->loadCharset($to);
+    return $conv->utf8ToStr($str);
+    }
 
-  // return raw string
+  // return UTF-8 string
   return $str;
   }
 
@@ -952,6 +978,7 @@
         'message' => 'rcmail_message_container',
         'messages' => 'rcmail_message_list',
         'messagecountdisplay' => 'rcmail_messagecount_display',
+        'quotadisplay' => 'rcmail_quota_display',
         'messageheaders' => 'rcmail_message_headers',
         'messagebody' => 'rcmail_message_body',
         'messageattachments' => 'rcmail_message_attachments',
@@ -1495,6 +1522,8 @@
   }
 
 
+/****** debugging function ********/
+
 function rcube_timer()
   {
   list($usec, $sec) = explode(" ", microtime());

--
Gitblit v1.9.1