From 66510e20d36cb8da4f3012ef063de7bfce9b51aa Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 09 May 2012 07:52:28 -0400
Subject: [PATCH] Merge pull request #1 from Brianetta/de-svn

---
 program/include/rcube_imap_generic.php |   95 +++++++++++++++++------------------------------
 1 files changed, 35 insertions(+), 60 deletions(-)

diff --git a/program/include/rcube_imap_generic.php b/program/include/rcube_imap_generic.php
index 4d4698f..77b0cc4 100644
--- a/program/include/rcube_imap_generic.php
+++ b/program/include/rcube_imap_generic.php
@@ -5,9 +5,12 @@
  | program/include/rcube_imap_generic.php                                |
  |                                                                       |
  | This file is part of the Roundcube Webmail client                     |
- | Copyright (C) 2005-2010, The Roundcube Dev Team                       |
- | Copyright (C) 2011, Kolab Systems AG                                  |
- | Licensed under the GNU GPL                                            |
+ | Copyright (C) 2005-2012, The Roundcube Dev Team                       |
+ | Copyright (C) 2011-2012, Kolab Systems AG                             |
+ |                                                                       |
+ | Licensed under the GNU General Public License version 3 or            |
+ | any later version with exceptions for skins & plugins.                |
+ | See the README file for a full license statement.                     |
  |                                                                       |
  | PURPOSE:                                                              |
  |   Provide alternative IMAP library that doesn't rely on the standard  |
@@ -26,42 +29,9 @@
 
 */
 
-/**
- * Struct representing an e-mail message header
- *
- * @package Mail
- * @author  Aleksander Machniak <alec@alec.pl>
- */
-class rcube_mail_header
-{
-    public $id;
-    public $uid;
-    public $subject;
-    public $from;
-    public $to;
-    public $cc;
-    public $replyto;
-    public $in_reply_to;
-    public $date;
-    public $messageID;
-    public $size;
-    public $encoding;
-    public $charset;
-    public $ctype;
-    public $timestamp;
-    public $bodystructure;
-    public $internaldate;
-    public $references;
-    public $priority;
-    public $mdn_to;
-    public $others = array();
-    public $flags = array();
-}
+// for backward compat.
+class rcube_mail_header extends rcube_message_header { }
 
-// For backward compatibility with cached messages (#1486602)
-class iilBasicHeader extends rcube_mail_header
-{
-}
 
 /**
  * PHP based wrapper class to connect to an IMAP server
@@ -1349,12 +1319,16 @@
                         $folders[$mailbox] = array();
                     }
 
-                    // Add to options array
-                    if (empty($this->data['LIST'][$mailbox]))
-                        $this->data['LIST'][$mailbox] = $opts;
-                    else if (!empty($opts))
-                        $this->data['LIST'][$mailbox] = array_unique(array_merge(
-                            $this->data['LIST'][$mailbox], $opts));
+                    // store LSUB options only if not empty, this way
+                    // we can detect a situation when LIST doesn't return specified folder
+                    if (!empty($opts) || $cmd == 'LIST') {
+                        // Add to options array
+                        if (empty($this->data['LIST'][$mailbox]))
+                            $this->data['LIST'][$mailbox] = $opts;
+                        else if (!empty($opts))
+                            $this->data['LIST'][$mailbox] = array_unique(array_merge(
+                                $this->data['LIST'][$mailbox], $opts));
+                    }
                 }
                 // * STATUS <mailbox> (<result>)
                 else if ($cmd == 'STATUS') {
@@ -1450,7 +1424,7 @@
 
         // Invoke SEARCH as a fallback
         $index = $this->search($mailbox, 'ALL UNSEEN', false, array('COUNT'));
-        if (!$index->isError()) {
+        if (!$index->is_error()) {
             return $index->count();
         }
 
@@ -1538,8 +1512,6 @@
      */
     function sort($mailbox, $field, $add='', $return_uid=false, $encoding = 'US-ASCII')
     {
-        require_once dirname(__FILE__) . '/rcube_result_index.php';
-
         $field = strtoupper($field);
         if ($field == 'INTERNALDATE') {
             $field = 'ARRIVAL';
@@ -1554,6 +1526,11 @@
 
         if (!$this->select($mailbox)) {
             return new rcube_result_index($mailbox);
+        }
+
+        // RFC 5957: SORT=DISPLAY
+        if (($field == 'FROM' || $field == 'TO') && $this->getCapability('SORT=DISPLAY')) {
+            $field = 'DISPLAY' . $field;
         }
 
         // message IDs
@@ -1583,8 +1560,6 @@
      */
     function thread($mailbox, $algorithm='REFERENCES', $criteria='', $return_uid=false, $encoding='US-ASCII')
     {
-        require_once dirname(__FILE__) . '/rcube_result_thread.php';
-
         $old_sel = $this->selected;
 
         if (!$this->select($mailbox)) {
@@ -1623,8 +1598,6 @@
      */
     function search($mailbox, $criteria, $return_uid=false, $items=array())
     {
-        require_once dirname(__FILE__) . '/rcube_result_index.php';
-
         $old_sel = $this->selected;
 
         if (!$this->select($mailbox)) {
@@ -1638,7 +1611,7 @@
 
         // If ESEARCH is supported always use ALL
         // but not when items are specified or using simple id2uid search
-        if (empty($items) && ((int) $criteria != $criteria)) {
+        if (empty($items) && preg_match('/[^0-9]/', $criteria)) {
             $items = array('ALL');
         }
 
@@ -1684,8 +1657,6 @@
     function index($mailbox, $message_set, $index_field='', $skip_deleted=true,
         $uidfetch=false, $return_uid=false)
     {
-        require_once dirname(__FILE__) . '/rcube_result_index.php';
-
         $msg_index = $this->fetchHeaderIndex($mailbox, $message_set,
             $index_field, $skip_deleted, $uidfetch, $return_uid);
 
@@ -2022,7 +1993,7 @@
      * @param string $mod_seq     Modification sequence for CHANGEDSINCE (RFC4551) query
      * @param bool   $vanished    Enables VANISHED parameter (RFC5162) for CHANGEDSINCE query
      *
-     * @return array List of rcube_mail_header elements, False on error
+     * @return array List of rcube_message_header elements, False on error
      * @since 0.6
      */
     function fetch($mailbox, $message_set, $is_uid = false, $query_items = array(),
@@ -2062,14 +2033,15 @@
             if (preg_match('/^\* ([0-9]+) FETCH/', $line, $m)) {
                 $id = intval($m[1]);
 
-                $result[$id]            = new rcube_mail_header;
+                $result[$id]            = new rcube_message_header;
                 $result[$id]->id        = $id;
                 $result[$id]->subject   = '';
                 $result[$id]->messageID = 'mid:' . $id;
 
-                $lines = array();
-                $line  = substr($line, strlen($m[0]) + 2);
-                $ln    = 0;
+                $headers = null;
+                $lines   = array();
+                $line    = substr($line, strlen($m[0]) + 2);
+                $ln      = 0;
 
                 // get complete entry
                 while (preg_match('/\{([0-9]+)\}\r\n$/', $line, $m)) {
@@ -3604,13 +3576,16 @@
         if ($string === null) {
             return 'NIL';
         }
+
         if ($string === '') {
             return '""';
         }
+
         // atom-string (only safe characters)
-        if (!$force_quotes && !preg_match('/[\x00-\x20\x22\x28-\x2A\x5B-\x5D\x7B\x7D\x80-\xFF]/', $string)) {
+        if (!$force_quotes && !preg_match('/[\x00-\x20\x22\x25\x28-\x2A\x5B-\x5D\x7B\x7D\x80-\xFF]/', $string)) {
             return $string;
         }
+
         // quoted-string
         if (!preg_match('/[\r\n\x00\x80-\xFF]/', $string)) {
             return '"' . addcslashes($string, '\\"') . '"';

--
Gitblit v1.9.1