From be9aacaa5296dfca63fb3a01c2dc52538d1546aa Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Sat, 17 Nov 2012 12:31:31 -0500
Subject: [PATCH] Bring back lost localization for the about page

---
 program/include/rcube_imap_generic.php |   74 ++++++++++++++++++++++++------------
 1 files changed, 49 insertions(+), 25 deletions(-)

diff --git a/program/include/rcube_imap_generic.php b/program/include/rcube_imap_generic.php
index cce53ae..a0a8f3b 100644
--- a/program/include/rcube_imap_generic.php
+++ b/program/include/rcube_imap_generic.php
@@ -30,8 +30,8 @@
 /**
  * PHP based wrapper class to connect to an IMAP server
  *
- * @package Mail
- * @author  Aleksander Machniak <alec@alec.pl>
+ * @package    Framework
+ * @subpackage Storage
  */
 class rcube_imap_generic
 {
@@ -2180,7 +2180,7 @@
                             $result[$id]->encoding = $string;
                         break;
                         case 'content-type':
-                            $ctype_parts = preg_split('/[; ]/', $string);
+                            $ctype_parts = preg_split('/[; ]+/', $string);
                             $result[$id]->ctype = strtolower(array_shift($ctype_parts));
                             if (preg_match('/charset\s*=\s*"?([a-z0-9\-\.\_]+)"?/i', $string, $regs)) {
                                 $result[$id]->charset = $regs[1];
@@ -2379,7 +2379,7 @@
         return $this->handlePartBody($mailbox, $id, $is_uid, $part);
     }
 
-    function handlePartBody($mailbox, $id, $is_uid=false, $part='', $encoding=NULL, $print=NULL, $file=NULL, $formatted=true)
+    function handlePartBody($mailbox, $id, $is_uid=false, $part='', $encoding=NULL, $print=NULL, $file=NULL, $formatted=false)
     {
         if (!$this->select($mailbox)) {
             return false;
@@ -2417,6 +2417,7 @@
         }
 
         if ($binary) {
+            // WARNING: Use $formatting argument with care, this may break binary data stream
             $mode = -1;
         }
 
@@ -2540,10 +2541,12 @@
      *
      * @param string $mailbox Mailbox name
      * @param string $message Message content
+     * @param array  $flags   Message flags
+     * @param string $date    Message internal date
      *
      * @return string|bool On success APPENDUID response (if available) or True, False on failure
      */
-    function append($mailbox, &$message)
+    function append($mailbox, &$message, $flags = array(), $date = null)
     {
         unset($this->data['APPENDUID']);
 
@@ -2559,12 +2562,17 @@
             return false;
         }
 
+        // build APPEND command
         $key = $this->nextTag();
-        $request = sprintf("$key APPEND %s (\\Seen) {%d%s}", $this->escape($mailbox),
-            $len, ($this->prefs['literal+'] ? '+' : ''));
+        $request = "$key APPEND " . $this->escape($mailbox) . ' (' . $this->flagsToStr($flags) . ')';
+        if (!empty($date)) {
+            $request .= ' ' . $this->escape($date);
+        }
+        $request .= ' {' . $len . ($this->prefs['literal+'] ? '+' : '') . '}';
 
+        // send APPEND command
         if ($this->putLine($request)) {
-            // Don't wait when LITERAL+ is supported
+            // Do not wait when LITERAL+ is supported
             if (!$this->prefs['literal+']) {
                 $line = $this->readReply();
 
@@ -2605,10 +2613,12 @@
      * @param string $mailbox Mailbox name
      * @param string $path    Path to the file with message body
      * @param string $headers Message headers
+     * @param array  $flags   Message flags
+     * @param string $date    Message internal date
      *
      * @return string|bool On success APPENDUID response (if available) or True, False on failure
      */
-    function appendFromFile($mailbox, $path, $headers=null)
+    function appendFromFile($mailbox, $path, $headers=null, $flags = array(), $date = null)
     {
         unset($this->data['APPENDUID']);
 
@@ -2639,11 +2649,15 @@
             $len += strlen($headers) + strlen($body_separator);
         }
 
-        // send APPEND command
+        // build APPEND command
         $key = $this->nextTag();
-        $request = sprintf("$key APPEND %s (\\Seen) {%d%s}", $this->escape($mailbox),
-            $len, ($this->prefs['literal+'] ? '+' : ''));
+        $request = "$key APPEND " . $this->escape($mailbox) . ' (' . $this->flagsToStr($flags) . ')';
+        if (!empty($date)) {
+            $request .= ' ' . $this->escape($date);
+        }
+        $request .= ' {' . $len . ($this->prefs['literal+'] ? '+' : '') . '}';
 
+        // send APPEND command
         if ($this->putLine($request)) {
             // Don't wait when LITERAL+ is supported
             if (!$this->prefs['literal+']) {
@@ -3517,6 +3531,10 @@
      */
     static function uncompressMessageSet($messages)
     {
+        if (empty($messages)) {
+            return array();
+        }
+
         $result   = array();
         $messages = explode(',', $messages);
 
@@ -3525,7 +3543,7 @@
             $max   = max($items[0], $items[1]);
 
             for ($x=$items[0]; $x<=$max; $x++) {
-                $result[] = $x;
+                $result[] = (int)$x;
             }
             unset($messages[$idx]);
         }
@@ -3543,6 +3561,24 @@
         }
 
         return $result;
+    }
+
+    /**
+     * Converts flags array into string for inclusion in IMAP command
+     *
+     * @param array $flags Flags (see self::flags)
+     *
+     * @return string Space-separated list of flags
+     */
+    private function flagsToStr($flags)
+    {
+        foreach ((array)$flags as $idx => $flag) {
+            if ($flag = $this->flags[strtoupper($flag)]) {
+                $flags[$idx] = $flag;
+            }
+        }
+
+        return implode(' ', (array)$flags);
     }
 
     /**
@@ -3620,18 +3656,6 @@
 
         // literal-string
         return sprintf("{%d}\r\n%s", strlen($string), $string);
-    }
-
-    /**
-     * Unescapes quoted-string
-     *
-     * @param string  $string       IMAP string
-     *
-     * @return string String
-     */
-    static function unEscape($string)
-    {
-        return stripslashes($string);
     }
 
     /**

--
Gitblit v1.9.1