Thomas Bruederli
2014-01-21 d93ce5cde23b7170b96fd9816e8d5e8cfdf6e0f6
Fix concurrent connections to IMAP while searching
1 files modified
11 ■■■■ changed files
program/lib/Roundcube/rcube_imap_search.php 11 ●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_imap_search.php
@@ -189,6 +189,8 @@
        $imap = $this->worker->get_imap();
        if (!$imap->connected()) {
            trigger_error("No IMAP connection for $this->folder", E_USER_WARNING);
            if ($this->threading) {
                return new rcube_result_thread();
            }
@@ -280,14 +282,13 @@
    public $options;
    private $conn;
    private $counts = 0;
    /**
     * Default constructor
     */
    public function __construct($id, $options)
    {
        $options['ident']['command'] = 'search-'.$id;
        $this->id = $id;
        $this->options = $options;
    }
@@ -298,21 +299,19 @@
    public function get_imap()
    {
        // TODO: make this connection persistent for several jobs
        #if ($this->conn)
        #    return $this->conn;
        // This doesn't seem to work. Socket connections don't survive serialization which is used in pthreads
        $conn = new rcube_imap_generic();
        # $conn->setDebug(true, function($conn, $message){ trigger_error($message, E_USER_NOTICE); });
        if ($this->options['user'] && $this->options['password']) {
            // TODO: do this synchronized to avoid warnings like "Only one Id allowed in non-authenticated state"
            $this->options['ident']['command'] = 'search-' . $this->id . 't' . ++$this->counts;
            $conn->connect($this->options['host'], $this->options['user'], $this->options['password'], $this->options);
        }
        if ($conn->error)
            trigger_error($conn->error, E_USER_WARNING);
        #$this->conn = $conn;
        return $conn;
    }