alecpl
2011-03-26 c09e3287c1704473bc9a68c6eaae45ae2ad3c418
program/include/rcube_imap_generic.php
@@ -56,13 +56,10 @@
    public $priority;
    public $mdn_to;
    public $mdn_sent = false;
    public $is_draft = false;
    public $seen = false;
    public $deleted = false;
    public $recent = false;
    public $answered = false;
    public $forwarded = false;
    public $junk = false;
    public $flagged = false;
    public $has_children = false;
    public $depth = 0;
@@ -91,7 +88,6 @@
    public $flags = array(
        'SEEN'     => '\\Seen',
        'DELETED'  => '\\Deleted',
        'RECENT'   => '\\Recent',
        'ANSWERED' => '\\Answered',
        'DRAFT'    => '\\Draft',
        'FLAGGED'  => '\\Flagged',
@@ -213,31 +209,26 @@
    {
        $line = '';
        if (!$this->fp) {
            return NULL;
        }
        if (!$size) {
            $size = 1024;
        }
        do {
            if (feof($this->fp)) {
            if ($this->eof()) {
                return $line ? $line : NULL;
            }
            $buffer = fgets($this->fp, $size);
            if ($buffer === false) {
                @fclose($this->fp);
                $this->fp = null;
                $this->closeSocket();
                break;
            }
            if ($this->_debug) {
                $this->debug('S: '. rtrim($buffer));
            }
            $line .= $buffer;
        } while ($buffer[strlen($buffer)-1] != "\n");
        } while (substr($buffer, -1) != "\n");
        return $line;
    }
@@ -267,7 +258,7 @@
    {
        $data = '';
        $len  = 0;
        while ($len < $bytes && !feof($this->fp))
        while ($len < $bytes && !$this->eof())
        {
            $d = fread($this->fp, $bytes-$len);
            if ($this->_debug) {
@@ -312,8 +303,7 @@
            } else if ($res == 'BAD') {
                $this->errornum = self::ERROR_BAD;
            } else if ($res == 'BYE') {
                @fclose($this->fp);
                $this->fp = null;
                $this->closeSocket();
                $this->errornum = self::ERROR_BYE;
            }
@@ -339,6 +329,32 @@
        return self::ERROR_UNKNOWN;
    }
    private function eof()
    {
        if (!is_resource($this->fp)) {
            return true;
        }
        // If a connection opened by fsockopen() wasn't closed
        // by the server, feof() will hang.
        $start = microtime(true);
        if (feof($this->fp) ||
            ($this->prefs['timeout'] && (microtime(true) - $start > $this->prefs['timeout']))
        ) {
            $this->closeSocket();
            return true;
        }
        return false;
    }
    private function closeSocket()
    {
        @fclose($this->fp);
        $this->fp = null;
    }
    function setError($code, $msg='')
    {
        $this->errornum = $code;
@@ -360,8 +376,7 @@
        }
        if ($error && preg_match('/^\* (BYE|BAD) /i', $string, $m)) {
            if (strtoupper($m[1]) == 'BYE') {
                @fclose($this->fp);
                $this->fp = null;
                $this->closeSocket();
            }
            return true;
        }
@@ -701,11 +716,12 @@
            $host = $this->prefs['ssl_mode'] . '://' . $host;
        }
        if ($this->prefs['timeout'] <= 0) {
            $this->prefs['timeout'] = ini_get('default_socket_timeout');
        }
        // Connect
        if ($this->prefs['timeout'] > 0)
            $this->fp = @fsockopen($host, $this->prefs['port'], $errno, $errstr, $this->prefs['timeout']);
        else
            $this->fp = @fsockopen($host, $this->prefs['port'], $errno, $errstr);
        $this->fp = @fsockopen($host, $this->prefs['port'], $errno, $errstr, $this->prefs['timeout']);
        if (!$this->fp) {
            $this->setError(self::ERROR_BAD, sprintf("Could not connect to %s:%d: %s", $host, $this->prefs['port'], $errstr));
@@ -848,8 +864,7 @@
            $this->readReply();
        }
        @fclose($this->fp);
        $this->fp = false;
        $this->closeSocket();
    }
    /**
@@ -1344,7 +1359,7 @@
                        $result[$id] = '';
                    }
                } else if ($mode == 2) {
                    if (preg_match('/\((UID|RFC822\.SIZE) ([0-9]+)/', $line, $matches)) {
                    if (preg_match('/(UID|RFC822\.SIZE) ([0-9]+)/', $line, $matches)) {
                        $result[$id] = trim($matches[2]);
                    } else {
                        $result[$id] = 0;
@@ -1722,14 +1737,10 @@
                                $result[$id]->seen = true;
                            } else if ($flag == 'DELETED') {
                                $result[$id]->deleted = true;
                            } else if ($flag == 'RECENT') {
                                $result[$id]->recent = true;
                            } else if ($flag == 'ANSWERED') {
                                $result[$id]->answered = true;
                            } else if ($flag == '$FORWARDED') {
                                $result[$id]->forwarded = true;
                            } else if ($flag == 'DRAFT') {
                                $result[$id]->is_draft = true;
                            } else if ($flag == '$MDNSENT') {
                                $result[$id]->mdn_sent = true;
                            } else if ($flag == 'FLAGGED') {
@@ -3321,7 +3332,7 @@
        else if ($force_quotes ||
            preg_match('/([\x00-\x20\x28-\x29\x7B\x25\x2A\x22\x5B\x5C\x5D\x7F]+)/', $string)
        ) {
            return '"' . strtr($string, array('"'=>'\\"', '\\' => '\\\\')) . '"';
            return '"' . addcslashes($string, '\\"') . '"';
        }
        // atom
@@ -3330,7 +3341,7 @@
    static function unEscape($string)
    {
        return strtr($string, array('\\"'=>'"', '\\\\' => '\\'));
        return stripslashes($string);
    }
    /**