Changeset 5054 in subversion


Ignore:
Timestamp:
Aug 12, 2011 5:21:21 AM (23 months ago)
Author:
alec
Message:
  • Added QRESYNC support (RFC5162)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-mcache/roundcubemail/program/include/rcube_imap_generic.php

    r5053 r5054  
    870870     * Executes SELECT command (if mailbox is already not in selected state) 
    871871     * 
    872      * @param string $mailbox Mailbox name 
     872     * @param string $mailbox      Mailbox name 
     873     * @param array  $qresync_data QRESYNC data (RFC5162) 
    873874     * 
    874875     * @return boolean True on success, false on error 
    875876     * @access public 
    876877     */ 
    877     function select($mailbox) 
     878    function select($mailbox, $qresync_data = null) 
    878879    { 
    879880        if (!strlen($mailbox)) { 
     
    894895        } 
    895896*/ 
    896         list($code, $response) = $this->execute('SELECT', array($this->escape($mailbox))); 
     897        $params = array($this->escape($mailbox)); 
     898 
     899        // QRESYNC data items 
     900        //    0. the last known UIDVALIDITY, 
     901        //    1. the last known modification sequence, 
     902        //    2. the optional set of known UIDs, and 
     903        //    3. an optional parenthesized list of known sequence ranges and their 
     904        //       corresponding UIDs. 
     905        if (!empty($qresync_data)) { 
     906            if (!empty($qresync_data[2])) 
     907                $qresync_data[2] = self::compressMessageSet($qresync_data[2]); 
     908            $params[] = array('QRESYNC', $qresync_data); 
     909        } 
     910 
     911        list($code, $response) = $this->execute('SELECT', $params); 
    897912 
    898913        if ($code == self::ERROR_OK) { 
     
    916931                        $this->data['PERMANENTFLAGS'] = explode(' ', $match[1]); 
    917932                    } 
     933                } 
     934                // QRESYNC FETCH response (RFC5162) 
     935                else if (preg_match('/^\* ([0-9+]) FETCH/i', $line, $match)) { 
     936                    $line       = substr($line, strlen($match[0])); 
     937                    $fetch_data = $this->tokenizeResponse($line, 1); 
     938                    $data       = array('id' => $match[1]); 
     939 
     940                    for ($i=0, $size=count($fetch_data); $i<$size; $i+=2) { 
     941                        $data[strtolower($fetch_data[$i])] = $fetch_data[$i+1]; 
     942                    } 
     943 
     944                    $this->data['QRESYNC'][$data['uid']] = $data; 
     945                } 
     946                // QRESYNC VANISHED response (RFC5162) 
     947                else if (preg_match('/^\* VANISHED [EARLIER]*/i', $line, $match)) { 
     948                    $line   = substr($line, strlen($match[0])); 
     949                    $v_data = $this->tokenizeResponse($line, 1); 
     950 
     951                    $this->data['VANISHED'] = $v_data; 
    918952                } 
    919953            } 
     
    15311565     * @param array  $query_items FETCH command data items 
    15321566     * @param string $mod_seq     Modification sequence for CHANGEDSINCE (RFC4551) query 
     1567     * @param bool   $vanished    Enables VANISHED parameter (RFC5162) for CHANGEDSINCE query 
    15331568     * 
    15341569     * @return array List of rcube_mail_header elements, False on error 
     
    15361571     * @since 0.6 
    15371572     */ 
    1538     function fetch($mailbox, $message_set, $is_uid = false, $query_items = array(), $mod_seq = null) 
     1573    function fetch($mailbox, $message_set, $is_uid = false, $query_items = array(), 
     1574        $mod_seq = null, $vanished = false) 
    15391575    { 
    15401576        if (!$this->select($mailbox)) { 
     
    15501586 
    15511587        if ($mod_seq !== null && $this->hasCapability('CONDSTORE')) { 
    1552             $request .= " (CHANGEDSINCE $mod_seq)"; 
     1588            $request .= " (CHANGEDSINCE $mod_seq" . ($vanished ? " VANISHED" : '') .")"; 
    15531589        } 
    15541590 
     
    17511787                } 
    17521788            } 
     1789 
     1790            // VANISHED response (QRESYNC RFC5162) 
     1791            // Sample: * VANISHED (EARLIER) 300:310,405,411 
     1792 
     1793            else if (preg_match('/^\* VANISHED [EARLIER]*/i', $line, $match)) { 
     1794                $line   = substr($line, strlen($match[0])); 
     1795                $v_data = $this->tokenizeResponse($line, 1); 
     1796 
     1797                $this->data['VANISHED'] = $v_data; 
     1798            } 
     1799 
    17531800        } while (!$this->startsWith($line, $key, true)); 
    17541801 
     
    32113258 
    32123259        if (!empty($arguments)) { 
    3213             $query .= ' ' . implode(' ', $arguments); 
     3260            foreach ($arguments as $arg) { 
     3261                $query .= ' ' . self::r_implode($arg); 
     3262            } 
    32143263        } 
    32153264 
     
    33423391    } 
    33433392 
     3393    static function r_implode($element) 
     3394    { 
     3395        $string = ''; 
     3396 
     3397        if (is_array($element)) { 
     3398            reset($element); 
     3399            while (list($key, $value) = each($element)) { 
     3400                $string .= ' ' . self::r_implode($value); 
     3401            } 
     3402        } 
     3403        else { 
     3404            return $element; 
     3405        } 
     3406 
     3407        return '(' . trim($string) . ')'; 
     3408    } 
     3409 
    33443410    private function _xor($string, $string2) 
    33453411    { 
Note: See TracChangeset for help on using the changeset viewer.