From b5652641be7ebf4f1b7f115333989d2c971275ea Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Fri, 31 Aug 2012 03:55:00 -0400
Subject: [PATCH] Small improvements in APPEND command handling

---
 program/include/rcube_imap_generic.php |   51 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/program/include/rcube_imap_generic.php b/program/include/rcube_imap_generic.php
index 197164d..c3cfabc 100644
--- a/program/include/rcube_imap_generic.php
+++ b/program/include/rcube_imap_generic.php
@@ -313,8 +313,12 @@
                 else {
                     $this->resultcode = null;
                     // parse response for [APPENDUID 1204196876 3456]
-                    if (preg_match("/^\[APPENDUID [0-9]+ ([0-9,:*]+)\]/i", $str, $m)) {
+                    if (preg_match("/^\[APPENDUID [0-9]+ ([0-9]+)\]/i", $str, $m)) {
                         $this->data['APPENDUID'] = $m[1];
+                    }
+                    // parse response for [COPYUID 1204196876 3456:3457 123:124]
+                    else if (preg_match("/^\[COPYUID [0-9]+ ([0-9,:]+) ([0-9,:]+)\]/i", $str, $m)) {
+                        $this->data['COPYUID'] = array($m[1], $m[2]);
                     }
                 }
                 $this->result = $str;
@@ -1950,6 +1954,9 @@
      */
     function copy($messages, $from, $to)
     {
+        // Clear last COPYUID data
+        unset($this->data['COPYUID']);
+
         if (!$this->select($from)) {
             return false;
         }
@@ -2370,7 +2377,7 @@
         return $this->handlePartBody($mailbox, $id, $is_uid, $part);
     }
 
-    function handlePartBody($mailbox, $id, $is_uid=false, $part='', $encoding=NULL, $print=NULL, $file=NULL)
+    function handlePartBody($mailbox, $id, $is_uid=false, $part='', $encoding=NULL, $print=NULL, $file=NULL, $formatted=true)
     {
         if (!$this->select($mailbox)) {
             return false;
@@ -2487,7 +2494,7 @@
                         continue;
                     $line = convert_uudecode($line);
                 // default
-                } else {
+                } else if ($formatted) {
                     $line = rtrim($line, "\t\r\n\0\x0B") . "\n";
                 }
 
@@ -2531,7 +2538,7 @@
     {
         unset($this->data['APPENDUID']);
 
-        if (!$mailbox) {
+        if ($mailbox === null || $mailbox === '') {
             return false;
         }
 
@@ -2596,7 +2603,7 @@
     {
         unset($this->data['APPENDUID']);
 
-        if (!$mailbox) {
+        if ($mailbox === null || $mailbox === '') {
             return false;
         }
 
@@ -2605,6 +2612,7 @@
         if (file_exists(realpath($path))) {
             $in_fp = fopen($path, 'r');
         }
+
         if (!$in_fp) {
             $this->setError(self::ERROR_UNKNOWN, "Couldn't open $path for reading");
             return false;
@@ -3195,10 +3203,10 @@
      */
     static function getStructurePartData($structure, $part)
     {
-	    $part_a = self::getStructurePartArray($structure, $part);
-	    $data   = array();
+        $part_a = self::getStructurePartArray($structure, $part);
+        $data   = array();
 
-	    if (empty($part_a)) {
+        if (empty($part_a)) {
             return $data;
         }
 
@@ -3231,13 +3239,13 @@
 
     static function getStructurePartArray($a, $part)
     {
-	    if (!is_array($a)) {
+        if (!is_array($a)) {
             return false;
         }
 
         if (empty($part)) {
-		    return $a;
-	    }
+            return $a;
+        }
 
         $ctype = is_string($a[0]) && is_string($a[1]) ? $a[0] . '/' . $a[1] : '';
 
@@ -3245,20 +3253,17 @@
             $a = $a[8];
         }
 
-	    if (strpos($part, '.') > 0) {
-		    $orig_part = $part;
-		    $pos       = strpos($part, '.');
-		    $rest      = substr($orig_part, $pos+1);
-		    $part      = substr($orig_part, 0, $pos);
+        if (strpos($part, '.') > 0) {
+            $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);
-	    }
+            return self::getStructurePartArray($a[$part-1], $rest);
+        }
         else if ($part > 0) {
-		    if (is_array($a[$part-1]))
-                return $a[$part-1];
-		    else
-                return $a;
-	    }
+            return (is_array($a[$part-1])) ? $a[$part-1] : $a;
+        }
     }
 
     /**

--
Gitblit v1.9.1