]> git.donarmstrong.com Git - roundcube.git/blobdiff - program/include/rcube_imap_generic.php
Imported Upstream version 0.7.2
[roundcube.git] / program / include / rcube_imap_generic.php
index 4c002fc14d5ef0a78ccbd2331cf2aaa62a493189..7bb5bebf95a8c71639dbe2532c79b063b60ded51 100644 (file)
@@ -22,7 +22,7 @@
  | Author: Ryo Chijiiwa <Ryo@IlohaMail.org>                              |
  +-----------------------------------------------------------------------+
 
- $Id: rcube_imap_generic.php 5402 2011-11-09 10:03:54Z alec $
+ $Id: rcube_imap_generic.php 5970 2012-03-06 19:43:49Z alec $
 
 */
 
@@ -1557,6 +1557,11 @@ class rcube_imap_generic
         }
 
         if (!$this->select($mailbox)) {
+        }
+
+        // RFC 5957: SORT=DISPLAY
+        if (($field == 'FROM' || $field == 'TO') && $this->getCapability('SORT=DISPLAY')) {
+            $field = 'DISPLAY' . $field;
             return null;
         }
 
@@ -2274,12 +2279,16 @@ class rcube_imap_generic
                         $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') {
@@ -3232,29 +3241,31 @@ class rcube_imap_generic
            if (!is_array($a)) {
             return false;
         }
+
+        if (empty($part)) {
+                   return $a;
+           }
+
+        $ctype = is_string($a[0]) && is_string($a[1]) ? $a[0] . '/' . $a[1] : '';
+
+        if (strcasecmp($ctype, 'message/rfc822') == 0) {
+            $a = $a[8];
+        }
+
            if (strpos($part, '.') > 0) {
-                   $original_part = $part;
-                   $pos = strpos($part, '.');
-                   $rest = substr($original_part, $pos+1);
-                   $part = substr($original_part, 0, $pos);
-                   if ((strcasecmp($a[0], 'message') == 0) && (strcasecmp($a[1], 'rfc822') == 0)) {
-                           $a = $a[8];
-                   }
+                   $orig_part = $part;
+                   $pos       = strpos($part, '.');
+                   $rest      = substr($orig_part, $pos+1);
+                   $part      = substr($orig_part, 0, $pos);
+
                    return self::getStructurePartArray($a[$part-1], $rest);
            }
-        else if ($part>0) {
-                   if (!is_array($a[0]) && (strcasecmp($a[0], 'message') == 0)
-                && (strcasecmp($a[1], 'rfc822') == 0)) {
-                           $a = $a[8];
-                   }
+        else if ($part > 0) {
                    if (is_array($a[$part-1]))
                 return $a[$part-1];
                    else
                 return $a;
            }
-        else if (($part == 0) || (empty($part))) {
-                   return $a;
-           }
     }
 
     /**
@@ -3500,13 +3511,16 @@ class rcube_imap_generic
         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, '\\"') . '"';