thomascube
2008-12-24 230f944bf62f141f47c021dbfe6cc3d07b74a76d
program/include/main.inc
@@ -151,19 +151,19 @@
 * Garbage collector for cache entries.
 * Remove all expired message cache records
 */
function rcmail_message_cache_gc()
function rcmail_cache_gc()
  {
  global $DB, $CONFIG;
  // no cache lifetime configured
  if (empty($CONFIG['message_cache_lifetime']))
    return;
  $rcmail = rcmail::get_instance();
  $db = $rcmail->get_dbh();
  
  // get target timestamp
  $ts = get_offset_time($CONFIG['message_cache_lifetime'], -1);
  $ts = get_offset_time($rcmail->config->get('message_cache_lifetime', '30d'), -1);
  
  $DB->query("DELETE FROM ".get_table_name('messages')."
             WHERE  created < ".$DB->fromunixtime($ts));
  $db->query("DELETE FROM ".get_table_name('messages')."
             WHERE  created < " . $db->fromunixtime($ts));
  $db->query("DELETE FROM ".get_table_name('cache')."
              WHERE  created < " . $db->fromunixtime($ts));
  }
@@ -178,7 +178,9 @@
 */
function rcube_charset_convert($str, $from, $to=NULL)
  {
  static $mbstring_loaded = null, $convert_warning = false;
  static $mbstring_loaded = null;
  static $mbstring_list = null;
  static $convert_warning = false;
  $from = strtoupper($from);
  $to = $to==NULL ? strtoupper(RCMAIL_CHARSET) : strtoupper($to);
@@ -219,9 +221,19 @@
    $aliases['UTF-7'] = 'UTF7-IMAP';
    $aliases['WINDOWS-1257'] = 'ISO-8859-13';
    
    // return if convert succeeded
    if (($out = mb_convert_encoding($str, ($aliases[$to] ? $aliases[$to] : $to), ($aliases[$from] ? $aliases[$from] : $from))) != '')
      return $out;
    if (is_null($mbstring_list)) {
      $mbstring_list = mb_list_encodings();
      $mbstring_list = array_map('strtoupper', $mbstring_list);
    }
    $mb_from = $aliases[$from] ? $aliases[$from] : $from;
    $mb_to = $aliases[$to] ? $aliases[$to] : $to;
    // return if encoding found, string matches encoding and convert succeeded
    if (in_array($mb_from, $mbstring_list) && in_array($mb_to, $mbstring_list))
      if (mb_check_encoding($str, $mb_from))
   if ($out = mb_convert_encoding($str, $mb_to, $mb_from))
          return $out;
    }
    
  
@@ -600,18 +612,26 @@
    array(
      '/(^\s*<!--)|(-->\s*$)/',
      '/(^\s*|,\s*|\}\s*)([a-z0-9\._#][a-z0-9\.\-_]*)/im',
      '/@import\s+(url\()?[\'"]?([^\)\'"]+)[\'"]?(\))?/ime',
      '/<<str_replacement\[([0-9]+)\]>>/e',
      "/$container_id\s+body/i"
      "/$container_id\s+body/i",
    ),
    array(
      '',
      "\\1#$container_id \\2",
      "sprintf(\"@import url('./bin/modcss.php?u=%s&c=%s')\", urlencode(make_absolute_url('\\2','$base_url')), urlencode($container_id))",
      "\$a_css_values[\\1]",
      "$container_id div.rcmBody"
      "$container_id div.rcmBody",
    ),
    $source);
  // replace all @import statements to modify the imported CSS sources too
  $styles = preg_replace_callback(
    '/@import\s+(url\()?[\'"]?([^\)\'"]+)[\'"]?(\))?/im',
    create_function('$matches', "return sprintf(\"@import url('./bin/modcss.php?u=%s&c=%s')\", urlencode(make_absolute_url(\$matches[2],'$base_url')), urlencode('$container_id'));"),
    $styles);
  // put block contents back in
  $styles = preg_replace_callback(
    '/<<str_replacement\[([0-9]+)\]>>/',
    create_function('$matches', "\$values = ".var_export($a_css_values, true)."; return \$values[\$matches[1]];"),
    $styles);
  return $styles;
  }
@@ -627,7 +647,7 @@
function rcmail_xss_entitiy_decode($content)
{
  $out = html_entity_decode(html_entity_decode($content));
  $out = preg_replace('/\\\([0-9a-f]{4})/ie', "chr(hexdec('\\1'))", $out);
  $out = preg_replace_callback('/\\\([0-9a-f]{4})/i', create_function('$matches', 'return chr(hexdec($matches[1]));'), $out);
  $out = preg_replace('#/\*.*\*/#Um', '', $out);
  return $out;
}
@@ -661,7 +681,7 @@
function parse_attrib_string($str)
  {
  $attrib = array();
  preg_match_all('/\s*([-_a-z]+)=(["\'])??(?(2)([^\2]+)\2|(\S+?))/Ui', stripslashes($str), $regs, PREG_SET_ORDER);
  preg_match_all('/\s*([-_a-z]+)=(["\'])??(?(2)([^\2]*)\2|(\S+?))/Ui', stripslashes($str), $regs, PREG_SET_ORDER);
  // convert attributes to an associative array (name => value)
  if ($regs)
@@ -1143,17 +1163,15 @@
{
  global $CONFIG;
  $cname = null;
  $folder_lc = strtolower($folder_id);
  // for these mailboxes we have localized labels and css classes
  foreach (array('inbox', 'sent', 'drafts', 'trash', 'junk') as $smbx)
  foreach (array('sent', 'drafts', 'trash', 'junk') as $smbx)
  {
    if ($folder_lc == $smbx || $folder_id == $CONFIG[$smbx.'_mbox'])
      $cname = $smbx;
    if ($folder_id == $CONFIG[$smbx.'_mbox'])
      return $smbx;
  }
  return $cname;
  if ($folder_id == 'INBOX')
    return 'inbox';
}