svncommit
2005-10-21 7dd801e71011f62ff7b2dd59636a6908fd037993
program/include/main.inc
@@ -30,7 +30,7 @@
  // check client
  $BROWSER = rcube_browser();
  // load config file
  include_once('config/main.inc.php');
  $CONFIG = is_array($rcmail_config) ? $rcmail_config : array();
@@ -51,9 +51,15 @@
    ini_set('display_errors', 1);
  else
    ini_set('display_errors', 0);
  // set session garbage collecting time according to session_lifetime
  if (!empty($CONFIG['session_lifetime']))
    ini_set('session.gc_maxlifetime', ($CONFIG['session_lifetime']+2)*60);
  // prepare DB connection
  require_once('include/rcube_'.(empty($CONFIG['db_backend']) ? 'db' : $CONFIG['db_backend']).'.inc');
  $DB = new rcube_db($CONFIG['db_dsnw'], $CONFIG['db_dsnr']);
  $DB->sqlite_initials = $INSTALL_PATH.'SQL/sqlite.initial.sql';
@@ -136,34 +142,43 @@
  $IMAP = new rcube_imap();
  // connect with stored session data
  if ($connect)
    {
    if (!($conn = $IMAP->connect($_SESSION['imap_host'], $_SESSION['username'], decrypt_passwd($_SESSION['password']), $_SESSION['imap_port'], $_SESSION['imap_ssl'])))
      show_message('imaperror', 'error');
    rcmail_set_imap_prop();
    }
  // enable caching of imap data
  if ($CONFIG['enable_caching']===TRUE)
    $IMAP->set_caching(TRUE);
  // set root dir from config
  if (strlen($CONFIG['imap_root']))
    $IMAP->set_rootdir($CONFIG['imap_root']);
  if (is_array($CONFIG['default_imap_folders']))
    $IMAP->set_default_mailboxes($CONFIG['default_imap_folders']);
  if (strlen($_SESSION['mbox']))
    $IMAP->set_mailbox($_SESSION['mbox']);
  if (isset($_SESSION['page']))
    $IMAP->set_page($_SESSION['page']);
  // set pagesize from config
  if (isset($CONFIG['pagesize']))
    $IMAP->set_pagesize($CONFIG['pagesize']);
  }
  // connect with stored session data
  if ($connect)
    {
    if (!($conn = $IMAP->connect($_SESSION['imap_host'], $_SESSION['username'], decrypt_passwd($_SESSION['password']))))
      show_message('imaperror', 'error');
    }
// set root dir and last stored mailbox
// this must be done AFTER connecting to the server
function rcmail_set_imap_prop()
  {
  global $CONFIG, $IMAP;
  // set root dir from config
  if (strlen($CONFIG['imap_root']))
    $IMAP->set_rootdir($CONFIG['imap_root']);
  if (strlen($_SESSION['mbox']))
    $IMAP->set_mailbox($_SESSION['mbox']);
  if (isset($_SESSION['page']))
    $IMAP->set_page($_SESSION['page']);
  }
@@ -260,7 +275,7 @@
    {
    $host = $a_host['host'];
    $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? TRUE : FALSE;
    $imap_port = isset($a_host['post']) ? $a_host['post'] : ($imap_ssl ? 993 : $CONFIG['default_port']);
    $imap_port = isset($a_host['port']) ? $a_host['port'] : ($imap_ssl ? 993 : $CONFIG['default_port']);
    }
  // exit if IMAP login failed
@@ -299,6 +314,8 @@
    {
    $_SESSION['user_id']   = $user_id;
    $_SESSION['imap_host'] = $host;
    $_SESSION['imap_port'] = $imap_port;
    $_SESSION['imap_ssl']  = $imap_ssl;
    $_SESSION['username']  = $user;
    $_SESSION['password']  = encrypt_passwd($pass);
@@ -386,8 +403,13 @@
function console($msg, $type=1)
  {
  print $msg;
  print "\n<hr>\n";
  if ($GLOBALS['REMOTE_REQUEST'])
    print "// $msg\n";
  else
    {
    print $msg;
    print "\n<hr>\n";
    }
  }
@@ -417,6 +439,33 @@
  exit;
  }
// read directory program/localization/ and return a list of available languages
function rcube_list_languages()
  {
  global $CONFIG, $INSTALL_PATH;
  static $sa_languages = array();
  if (!sizeof($sa_languages))
    {
    @include_once($INSTLL_PATH.'program/localization/index.inc');
    if ($dh = @opendir($INSTLL_PATH.'program/localization'))
      {
      while (($name = readdir($dh)) !== false)
        {
        if ($name{0}=='.' || !is_dir($INSTLL_PATH.'program/localization/'.$name))
          continue;
        if ($label = $rcube_languages[$name])
          $sa_languages[$name] = $label ? $label : $name;
        }
      closedir($dh);
      }
    }
  return $sa_languages;
  }
@@ -516,7 +565,7 @@
    // show a label
    case 'label':
      if ($attrib['name'] || $attrib['command'])
        return rcube_label($attrib);
        return rep_specialchars_output(rcube_label($attrib));
      break;
    // create a menu item
@@ -648,7 +697,7 @@
        else if (isset($GLOBALS['PAGE_TITLE']))
          return rep_specialchars_output("RoundCube|Mail :: ".$GLOBALS['PAGE_TITLE']);
        else if ($task=='mail' && ($mbox_name = $IMAP->get_mailbox_name()))
          return "RoundCube|Mail :: $mbox_name";
          return "RoundCube|Mail :: ".rep_specialchars_output(UTF7DecodeString($mbox_name), 'html', 'all');
        else
          return "RoundCube|Mail :: $task";
        }
@@ -666,7 +715,7 @@
// create and register a button
function rcube_button($attrib)
  {
  global $CONFIG, $OUTPUT, $JS_OBJECT_NAME;
  global $CONFIG, $OUTPUT, $JS_OBJECT_NAME, $BROWSER;
  static $sa_buttons = array();
  static $s_button_count = 100;
  
@@ -723,7 +772,14 @@
  if ($attrib['alt'])
    $attrib['alt'] = rep_specialchars_output(rcube_label($attrib['alt']));
  // set title to alt attribute for IE browsers
  if ($BROWSER['ie'] && $attrib['title'] && !$attrib['alt'])
    {
    $attrib['alt'] = $attrib['title'];
    unset($attrib['title']);
    }
  // add empty alt attribute for XHTML compatibility
  if (!isset($attrib['alt']))
    $attrib['alt'] = '';
@@ -815,7 +871,7 @@
  $table .= "<thead><tr>\n";
  foreach ($a_show_cols as $col)
    $table .= '<td class="'.$col.'">' . rcube_label($col) . "</td>\n";
    $table .= '<td class="'.$col.'">' . rep_specialchars_output(rcube_label($col)) . "</td>\n";
  $table .= "</tr></thead>\n<tbody>\n";