Thomas Bruederli
2014-06-05 99cdca46b7bcc46fe6affd9e9f9f60a546b2e5b8
program/lib/Roundcube/rcube_imap_generic.php
@@ -50,17 +50,17 @@
    public static $mupdate;
    private $fp;
    private $host;
    private $logged = false;
    private $capability = array();
    private $capability_readed = false;
    private $prefs;
    private $cmd_tag;
    private $cmd_num = 0;
    private $resourceid;
    private $_debug = false;
    private $_debug_handler = false;
    protected $fp;
    protected $host;
    protected $logged = false;
    protected $capability = array();
    protected $capability_readed = false;
    protected $prefs;
    protected $cmd_tag;
    protected $cmd_num = 0;
    protected $resourceid;
    protected $_debug = false;
    protected $_debug_handler = false;
    const ERROR_OK = 0;
    const ERROR_NO = -1;
@@ -352,7 +352,7 @@
     *
     * @return bool True if connection is closed
     */
    private function eof()
    protected function eof()
    {
        if (!is_resource($this->fp)) {
            return true;
@@ -375,7 +375,7 @@
    /**
     * Closes connection stream.
     */
    private function closeSocket()
    protected function closeSocket()
    {
        @fclose($this->fp);
        $this->fp = null;
@@ -421,7 +421,7 @@
        return false;
    }
    private function hasCapability($name)
    protected function hasCapability($name)
    {
        if (empty($this->capability) || $name == '') {
            return false;
@@ -1191,13 +1191,20 @@
     * Folder creation (CREATE)
     *
     * @param string $mailbox Mailbox name
     * @param array  $types    Optional folder types (RFC 6154)
     *
     * @return bool True on success, False on error
     */
    function createFolder($mailbox)
    function createFolder($mailbox, $types = null)
    {
        $result = $this->execute('CREATE', array($this->escape($mailbox)),
            self::COMMAND_NORESPONSE);
        $args = array($this->escape($mailbox));
        // RFC 6154: CREATE-SPECIAL-USE
        if (!empty($types) && $this->getCapability('CREATE-SPECIAL-USE')) {
            $args[] = '(USE (' . implode(' ', $types) . '))';
        }
        $result = $this->execute('CREATE', $args, self::COMMAND_NORESPONSE);
        return ($result == self::ERROR_OK);
    }
@@ -1293,15 +1300,17 @@
     * @param string $ref         Reference name
     * @param string $mailbox     Mailbox name
     * @param bool   $subscribed  Enables returning subscribed mailboxes only
     * @param array  $status_opts List of STATUS options (RFC5819: LIST-STATUS)
     *                            Possible: MESSAGES, RECENT, UIDNEXT, UIDVALIDITY, UNSEEN
     * @param array  $status_opts List of STATUS options
     *                            (RFC5819: LIST-STATUS:  MESSAGES, RECENT, UIDNEXT, UIDVALIDITY, UNSEEN)
     *                            or RETURN options (RFC5258: LIST_EXTENDED: SUBSCRIBED, CHILDREN)
     * @param array  $select_opts List of selection options (RFC5258: LIST-EXTENDED)
     *                            Possible: SUBSCRIBED, RECURSIVEMATCH, REMOTE
     *                            Possible: SUBSCRIBED, RECURSIVEMATCH, REMOTE,
     *                                      SPECIAL-USE (RFC6154)
     *
     * @return array List of mailboxes or hash of options if $status_ops argument
     *               is non-empty.
     */
    private function _listMailboxes($ref, $mailbox, $subscribed=false,
    protected function _listMailboxes($ref, $mailbox, $subscribed=false,
        $status_opts=array(), $select_opts=array())
    {
        if (!strlen($mailbox)) {
@@ -1309,6 +1318,7 @@
        }
        $args = array();
        $rets = array();
        if (!empty($select_opts) && $this->getCapability('LIST-EXTENDED')) {
            $select_opts = (array) $select_opts;
@@ -1319,11 +1329,21 @@
        $args[] = $this->escape($ref);
        $args[] = $this->escape($mailbox);
        if (!empty($status_opts) && $this->getCapability('LIST-STATUS')) {
            $status_opts = (array) $status_opts;
            $lstatus = true;
        if (!empty($status_opts) && $this->getCapability('LIST-EXTENDED')) {
            $rets = array_intersect($status_opts, array('SUBSCRIBED', 'CHILDREN'));
        }
            $args[] = 'RETURN (STATUS (' . implode(' ', $status_opts) . '))';
        if (!empty($status_opts) && $this->getCapability('LIST-STATUS')) {
            $status_opts = array_intersect($status_opts, array('MESSAGES', 'RECENT', 'UIDNEXT', 'UIDVALIDITY', 'UNSEEN'));
            if (!empty($status_opts)) {
                $lstatus = true;
                $rets[] = 'STATUS (' . implode(' ', $status_opts) . ')';
            }
        }
        if (!empty($rets)) {
            $args[] = 'RETURN (' . implode(' ', $rets) . ')';
        }
        list($code, $response) = $this->execute($subscribed ? 'LSUB' : 'LIST', $args);
@@ -1965,7 +1985,7 @@
     *
     * @return bool True on success, False on failure
     */
    private function modFlag($mailbox, $messages, $flag, $mod = '+')
    protected function modFlag($mailbox, $messages, $flag, $mod = '+')
    {
        if ($mod != '+' && $mod != '-') {
            $mod = '+';
@@ -3123,7 +3143,8 @@
                    if (isset($mbox) && is_array($data[$i])) {
                        $size_sub = count($data[$i]);
                        for ($x=0; $x<$size_sub; $x++) {
                            $result[$mbox][$data[$i][$x]] = $data[$i][++$x];
                            if ($data[$i][$x+1] !== null)
                                $result[$mbox][$data[$i][$x]] = $data[$i][++$x];
                        }
                        unset($data[$i]);
                    }
@@ -3141,7 +3162,8 @@
                        }
                    }
                    else if (isset($mbox)) {
                        $result[$mbox][$data[$i]] = $data[++$i];
                        if ($data[$i+1] !== null)
                            $result[$mbox][$data[$i]] = $data[++$i];
                        unset($data[$i]);
                        unset($data[$i-1]);
                    }
@@ -3286,10 +3308,10 @@
                        for ($x=0, $len=count($attribs); $x<$len;) {
                            $attr  = $attribs[$x++];
                            $value = $attribs[$x++];
                            if ($attr == 'value.priv') {
                            if ($attr == 'value.priv' && $value !== null) {
                                $result[$mbox]['/private' . $entry] = $value;
                            }
                            else if ($attr == 'value.shared') {
                            else if ($attr == 'value.shared' && $value !== null) {
                                $result[$mbox]['/shared' . $entry] = $value;
                            }
                        }
@@ -3659,7 +3681,7 @@
        return $result;
    }
    private function _xor($string, $string2)
    protected function _xor($string, $string2)
    {
        $result = '';
        $size   = strlen($string);
@@ -3678,7 +3700,7 @@
     *
     * @return string Space-separated list of flags
     */
    private function flagsToStr($flags)
    protected function flagsToStr($flags)
    {
        foreach ((array)$flags as $idx => $flag) {
            if ($flag = $this->flags[strtoupper($flag)]) {
@@ -3730,7 +3752,7 @@
    /**
     * CAPABILITY response parser
     */
    private function parseCapability($str, $trusted=false)
    protected function parseCapability($str, $trusted=false)
    {
        $str = preg_replace('/^\* CAPABILITY /i', '', $str);
@@ -3807,7 +3829,7 @@
     *
     * @since 0.5-stable
     */
    private function debug($message)
    protected function debug($message)
    {
        if (($len = strlen($message)) > self::DEBUG_LINE_LENGTH) {
            $diff    = $len - self::DEBUG_LINE_LENGTH;