Fix parsing of messages containing UUEncoded data.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 31 Aug 2008 15:01:59 +0000 (17:01 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 31 Aug 2008 15:01:59 +0000 (17:01 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
banana/mbox.inc.php
banana/mimepart.inc.php

index cb4faa2..1f158c9 100644 (file)
@@ -302,7 +302,7 @@ class BananaMBox implements BananaProtocoleInterface
      */
     private function getMBoxPosition(array &$options, $id = null)
     {
-        if (Banana::$spool->overview) {
+        if (Banana::$spool && Banana::$spool->overview) {
             if (!is_null($id) && isset(Banana::$spool->overview[$id])) {
                 $key = $id;
             } else {
index 743ced2..577af46 100644 (file)
@@ -201,7 +201,14 @@ class BananaMimePart
             $parts = $this->findUUEncoded();
             if (count($parts)) {
                 $this->convertToMultiPart();
-                $this->multipart    = array_merge(array($textpart), $parts);
+                $this->multipart = array_merge($this->multipart, $parts);
+                // Restore "message" headers to the previous level"
+                $this->headers = array();
+                foreach (Banana::$msgshow_headers as $hdr) {
+                    if (isset($this->multipart[0]->headers[$hdr])) {
+                        $this->headers[$hdr] = $this->multipart[0]->headers[$hdr];
+                    }
+                }
             }
         }
     }
@@ -260,11 +267,12 @@ class BananaMimePart
                 if ($mime != 'application/x-empty') {
                     $this->body = trim(str_replace($match[0], '', $this->body));
                     $newpart = new BananaMimePart;
+                    self::decodeHeader($match[2]);
                     $newpart->makeDataPart($data, $mime, '8bit', $match[2], 'attachment');
                     $parts[] = $newpart;
                 }
-            }   
-        } 
+            }
+        }
         return $parts;
     }
 
@@ -275,7 +283,7 @@ class BananaMimePart
         return str_replace('_', ' ', $s);
     }
 
-    static public function decodeHeader(&$val, $key)
+    static public function decodeHeader(&$val, $key = null)
     {
         if (preg_match('/[\x80-\xff]/', $val)) {
             if (!is_utf8($val)) {