Aleksander Machniak
2013-07-02 ed3e51f1b41d818ae757220fd41cdf0b093b20f6
program/lib/Roundcube/rcube.php
@@ -99,7 +99,6 @@
    protected $texts;
    protected $caches = array();
    protected $shutdown_functions = array();
    protected $expunge_cache = false;
    /**
@@ -378,6 +377,7 @@
            'auth_pw'     => $this->config->get("{$driver}_auth_pw"),
            'debug'       => (bool) $this->config->get("{$driver}_debug"),
            'force_caps'  => (bool) $this->config->get("{$driver}_force_caps"),
            'disabled_caps' => $this->config->get("{$driver}_disabled_caps"),
            'timeout'     => (int) $this->config->get("{$driver}_timeout"),
            'skip_deleted' => (bool) $this->config->get('skip_deleted'),
            'driver'      => $driver,
@@ -462,9 +462,7 @@
        // use database for storing session data
        $this->session = new rcube_session($this->get_dbh(), $this->config);
        $this->session->register_gc_handler(array($this, 'temp_gc'));
        $this->session->register_gc_handler(array($this, 'cache_gc'));
        $this->session->register_gc_handler(array($this, 'gc'));
        $this->session->set_secret($this->config->get('des_key') . dirname($_SERVER['SCRIPT_NAME']));
        $this->session->set_ip_check($this->config->get('ip_check'));
@@ -476,10 +474,23 @@
    /**
     * Garbage collector - cache/temp cleaner
     */
    public function gc()
    {
        rcube_cache::gc();
        rcube_cache_shared::gc();
        $this->get_storage()->cache_gc();
        $this->gc_temp();
    }
    /**
     * Garbage collector function for temp files.
     * Remove temp files older than two days
     */
    public function temp_gc()
    public function gc_temp()
    {
        $tmp = unslashify($this->config->get('temp_dir'));
        $expire = time() - 172800;  // expire in 48 hours
@@ -501,14 +512,21 @@
    /**
     * Garbage collector for cache entries.
     * Set flag to expunge caches on shutdown
     * Runs garbage collector with probability based on
     * session settings. This is intended for environments
     * without a session.
     */
    public function cache_gc()
    public function gc_run()
    {
        // because this gc function is called before storage is initialized,
        // we just set a flag to expunge storage cache on shutdown.
        $this->expunge_cache = true;
        $probability = (int) ini_get('session.gc_probability');
        $divisor     = (int) ini_get('session.gc_divisor');
        if ($divisor > 0 && $probability > 0) {
            $random = mt_rand(1, $divisor);
            if ($random <= $probability) {
                $this->gc();
            }
        }
    }
@@ -892,23 +910,25 @@
            call_user_func($function);
        }
        // write session data as soon as possible and before
        // closing database connection, don't do this before
        // registered shutdown functions, they may need the session
        // Note: this will run registered gc handlers (ie. cache gc)
        if ($_SERVER['REMOTE_ADDR'] && is_object($this->session)) {
            $this->session->write_close();
        }
        if (is_object($this->smtp)) {
            $this->smtp->disconnect();
        }
        foreach ($this->caches as $cache) {
            if (is_object($cache)) {
                if ($this->expunge_cache) {
                    $cache->expunge();
                }
                $cache->close();
            }
        }
        if (is_object($this->storage)) {
            if ($this->expunge_cache) {
                $this->storage->expunge_cache();
            }
            $this->storage->close();
        }
    }
@@ -1468,7 +1488,7 @@
                    $subject    = str_replace("\r\n", $delim, $subject);
                }
                if (ini_get('safe_mode'))
                if (filter_var(ini_get('safe_mode'), FILTER_VALIDATE_BOOLEAN))
                    $sent = mail($to, $subject, $msg_body, $header_str);
                else
                    $sent = mail($to, $subject, $msg_body, $header_str, "-f$from");