Fixes vim mode line.
[banana.git] / banana / mimepart.inc.php
index 9a4b6ff..d654ea5 100644 (file)
@@ -107,7 +107,7 @@ class BananaMimePart
             $this->body         = null;
             $this->format       = null;
             $this->id           = null;
-        } 
+        }
     }
 
     public function addAttachment(array $file, $content_type = null, $disposition = 'attachment')
@@ -124,7 +124,7 @@ class BananaMimePart
         return false;
     }
 
-    protected function getHeader($title, $filter = null)
+    public function getHeader($title, $filter = null)
     {
         if (!isset($this->headers[$title])) {
             return null;
@@ -136,7 +136,7 @@ class BananaMimePart
             return trim($matches[1]);
         }
         return null;
-    } 
+    }
 
     protected function fromRaw($data)
     {
@@ -174,7 +174,7 @@ class BananaMimePart
             $disposition  = $this->getHeader('content-disposition', '/(inline|attachment)/i');
             $boundary     = $this->getHeader('content-type', '/boundary="?([^ "]+?)"?\s*(;|$)/i');
             $charset      = strtolower($this->getHeader('content-type', '/charset="?([^ "]+?)"?\s*(;|$)/i'));
-            $filename     = $this->getHeader('content-disposition', '/filename="?([^ "]+?)"?\s*(;|$)/i');
+            $filename     = $this->getHeader('content-disposition', '/filename="?([^"]+?)"?\s*(;|$)/i');
             $format       = strtolower($this->getHeader('content-type', '/format="?([^ "]+?)"?\s*(;|$)/i'));
             $id           = $this->getHeader('content-id', '/<(.*?)>/');
             $sign_protocole = strtolower($this->getHeader('content-type', '/protocol="?([^ "]+?)"?\s*(;|$)/i'));
@@ -183,6 +183,10 @@ class BananaMimePart
             }
         }
         list($type, $subtype) = explode('/', $content_type);
+        if ($disposition == 'attachment') {
+            $this->makeDataPart($content, $content_type, $encoding, $filename, $disposition, $id);
+            return;
+        }
         switch ($type) {
           case 'text': case 'message':
             $this->makeTextPart($content, $content_type, $encoding, $charset, $format);
@@ -229,11 +233,11 @@ class BananaMimePart
         foreach ($parts as &$part) {
             $newpart = new BananaMimePart($part);
             if (!is_null($newpart->content_type)) {
-                if ($signed && $newpart->content_type == $this->signature['protocole']) { 
+                if ($signed && $newpart->content_type == $this->signature['protocole']) {
                     $signature = $newpart->body;
-                } elseif ($signed) { 
-                    $signed_message = $part; 
-                } 
+                } elseif ($signed) {
+                    $signed_message = $part;
+                }
                 $this->multipart[] = $newpart;
             }
         }
@@ -260,7 +264,7 @@ class BananaMimePart
     private function findUUEncoded()
     {
         $this->decodeContent();
-        $parts = array(); 
+        $parts = array();
         if (preg_match_all("/\n(begin \d+ ([^\r\n]+)\r?(?:\n(?!end)[^\n]*)*\nend)/",
             $this->body, $matches, PREG_SET_ORDER)) {
             foreach ($matches as &$match) {
@@ -308,7 +312,7 @@ class BananaMimePart
                 if (strpos($line, ':') !== false) {
                     list($hdr, $val) = explode(":", $line, 2);
                     $hdr = strtolower($hdr);
-                    if (in_array($hdr, Banana::$msgparse_headers)) {  
+                    if (in_array($hdr, Banana::$msgparse_headers)) {
                         $headers[$hdr] = ltrim($val);
                     } else {
                         unset($hdr);
@@ -418,15 +422,15 @@ class BananaMimePart
         $content = "";
         if ($with_headers) {
             foreach ($this->getHeaders() as $key => $value) {
-                $line = "$key: $value"; 
+                $line = "$key: $value";
                 $line = explode("\n", wordwrap($line, Banana::$msgshow_wrap));
                 for ($i = 1 ; $i < count($line) ; $i++) {
                     $line[$i] = "\t" . $line[$i];
                 }
                 $content .= implode("\n", $line) . "\n";
-            } 
+            }
             $content .= "\n";
-        } 
+        }
         if ($this->isType('multipart')) {
             $this->setBoundary();
             foreach ($this->multipart as &$part) {
@@ -443,9 +447,9 @@ class BananaMimePart
 
     public function getText()
     {
-        $signed =& $this->getSignedPart(); 
-        if ($signed !== $this) { 
-            return $signed->getText(); 
+        $signed =& $this->getSignedPart();
+        if ($signed !== $this) {
+            return $signed->getText();
         }
         $this->decodeContent();
         return $this->body;
@@ -453,9 +457,9 @@ class BananaMimePart
 
     public function toHtml()
     {
-        $signed =& $this->getSignedPart(); 
-        if ($signed !== $this) { 
-            return $signed->toHtml(); 
+        $signed =& $this->getSignedPart();
+        if ($signed !== $this) {
+            return $signed->toHtml();
         }
         @list($type, $subtype) = $this->getType();
         if ($type == 'image') {
@@ -481,11 +485,11 @@ class BananaMimePart
             if (!$part) {
                 $part = $this->content_type;
             }
-            return '[' . Banana::$page->makeImgLink(array('group' => Banana::$group,
+            return '<span>[' . Banana::$page->makeImgLink(array('group' => Banana::$group,
                                                  'artid' => Banana::$artid,
                                                  'part'  => $part,
                                                  'text'  => $this->filename ? $this->filename : $this->content_type,
-                                                 'img'   => 'save')) . ']';
+                                                 'img'   => 'save')) . ']</span>';
         } elseif ($type == 'multipart' && ($subtype == 'mixed' || $subtype == 'report')) {
             $text = '';
             foreach ($this->multipart as &$part) {
@@ -718,5 +722,5 @@ class BananaMimePart
     }
 }
 
-// vim:set et sw=4 sts=4 ts=4 enc=utf-8:
+// vim:set et sw=4 sts=4 ts=4 fenc=utf-8:
 ?>