thomascube
2010-09-21 cb2bc809ef29f349d38c89e202d821e67bb4c947
program/include/rcmail.php
@@ -45,6 +45,7 @@
  public $comm_path = './';
  private $texts;
  private $books = array();
  /**
@@ -235,7 +236,6 @@
      $this->db = new rcube_mdb2($config_all['db_dsnw'], $config_all['db_dsnr'], $config_all['db_persistent']);
      $this->db->sqlite_initials = INSTALL_PATH . 'SQL/sqlite.initial.sql';
      $this->db->set_debug((bool)$config_all['sql_debug']);
      $this->db->db_connect('w');
    }
    return $this->db;
@@ -255,7 +255,7 @@
    $ldap_config = (array)$this->config->get('ldap_public');
    $abook_type = strtolower($this->config->get('address_book_type'));
    $plugin = $this->plugins->exec_hook('get_address_book', array('id' => $id, 'writeable' => $writeable));
    $plugin = $this->plugins->exec_hook('addressbook_get', array('id' => $id, 'writeable' => $writeable));
    // plugin returned instance of a rcube_addressbook
    if ($plugin['instance'] instanceof rcube_addressbook) {
@@ -279,6 +279,10 @@
    else { // $id == 'sql'
      $contacts = new rcube_contacts($this->db, $this->user->ID);
    }
    // add to the 'books' array for shutdown function
    if (!in_array($contacts, $this->books))
      $this->books[] = $contacts;
    return $contacts;
  }
@@ -321,7 +325,7 @@
        );
    }
    $plugin = $this->plugins->exec_hook('address_sources', array('sources' => $list));
    $plugin = $this->plugins->exec_hook('addressbooks_list', array('sources' => $list));
    $list = $plugin['sources'];
    if ($writeable && !empty($list)) {
@@ -575,7 +579,7 @@
      if (!$allowed)
        return false;
      }
    else if (!empty($config['default_host']) && $host != $config['default_host'])
    else if (!empty($config['default_host']) && $host != rcube_parse_host($config['default_host']))
      return false;
    // parse $host URL
@@ -585,7 +589,7 @@
      $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? $a_host['scheme'] : null;
      if(!empty($a_host['port']))
        $imap_port = $a_host['port'];
      else if ($imap_ssl && $imap_ssl != 'tls')
      else if ($imap_ssl && $imap_ssl != 'tls' && (!$config['default_port'] || $config['default_port'] == 143))
        $imap_port = 993;
    }
@@ -595,11 +599,11 @@
       Inspired by Marco <P0L0_notspam_binware.org>
    */
    // Check if we need to add domain
    if (!empty($config['username_domain']) && !strpos($username, '@')) {
    if (!empty($config['username_domain']) && strpos($username, '@') === false) {
      if (is_array($config['username_domain']) && isset($config['username_domain'][$host]))
        $username .= '@'.$config['username_domain'][$host];
        $username .= '@'.rcube_parse_host($config['username_domain'][$host]);
      else if (is_string($config['username_domain']))
        $username .= '@'.$config['username_domain'];
        $username .= '@'.rcube_parse_host($config['username_domain']);
    }
    // try to resolve email address from virtuser table
@@ -743,7 +747,7 @@
      $host = get_input_value('_host', RCUBE_INPUT_POST);
    }
    else
      $host = $default_host;
      $host = rcube_parse_host($default_host);
    return $host;
  }
@@ -810,9 +814,9 @@
    if (($attrib['uppercase'] && strtolower($attrib['uppercase']=='first')) || $attrib['ucfirst'])
      return ucfirst($text);
    else if ($attrib['uppercase'])
      return strtoupper($text);
      return mb_strtoupper($text);
    else if ($attrib['lowercase'])
      return strtolower($text);
      return mb_strtolower($text);
    return $text;
  }
@@ -874,7 +878,7 @@
      if ($dh = @opendir(INSTALL_PATH . 'program/localization')) {
        while (($name = readdir($dh)) !== false) {
          if ($name{0}=='.' || !is_dir(INSTALL_PATH . 'program/localization/' . $name))
          if ($name[0] == '.' || !is_dir(INSTALL_PATH . 'program/localization/' . $name))
            continue;
          if ($label = $rcube_languages[$name])
@@ -928,7 +932,7 @@
   */
  public function kill_session()
  {
    $this->plugins->exec_hook('kill_session');
    $this->plugins->exec_hook('session_destroy');
    $this->session->remove();
    $_SESSION = array('language' => $this->user->language, 'auth_time' => time(), 'temp' => true);
@@ -974,8 +978,9 @@
    if (is_object($this->smtp))
      $this->smtp->disconnect();
    if (is_object($this->contacts))
      $this->contacts->close();
    foreach ($this->books as $book)
      if (is_object($book))
        $book->close();
    // before closing the database connection, write session data
    if ($_SERVER['REMOTE_ADDR'])
@@ -1071,7 +1076,7 @@
    if (function_exists('mcrypt_module_open') &&
        ($td = mcrypt_module_open(MCRYPT_TripleDES, "", MCRYPT_MODE_CBC, "")))
    {
      $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
      $iv = $this->create_iv(mcrypt_enc_get_iv_size($td));
      mcrypt_generic_init($td, $this->config->get_crypto_key($key), $iv);
      $cipher = $iv . mcrypt_generic($td, $clear);
      mcrypt_generic_deinit($td);
@@ -1082,9 +1087,7 @@
      if (function_exists('des')) {
        $des_iv_size = 8;
        $iv = '';
        for ($i = 0; $i < $des_iv_size; $i++)
          $iv .= sprintf("%c", mt_rand(0, 255));
        $iv = $this->create_iv($des_iv_size);
        $cipher = $iv . des($this->config->get_crypto_key($key), $clear, 1, 1, $iv);
      }
      else {
@@ -1153,6 +1156,22 @@
  }
  /**
   * Generates encryption initialization vector (IV)
   *
   * @param int Vector size
   * @return string Vector string
   */
  private function create_iv($size)
  {
    // mcrypt_create_iv() can be slow when system lacks entrophy
    // we'll generate IV vector manually
    $iv = '';
    for ($i = 0; $i < $size; $i++)
        $iv .= chr(mt_rand(0, 255));
    return $iv;
  }
  /**
   * Build a valid URL to this instance of RoundCube
   *
   * @param mixed Either a string with the action or url parameters as key-value pairs