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;
@@ -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;
  }
@@ -595,7 +599,7 @@
       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 .= '@'.rcube_parse_host($config['username_domain'][$host]);
      else if (is_string($config['username_domain']))
@@ -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])
@@ -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