Gestion des piÚces jointes uuencode dans le cas de message non-multipart (Ex : Outlo...
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Thu, 2 Mar 2006 16:29:56 +0000 (16:29 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:34:35 +0000 (00:34 +0100)
git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@22 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/post.inc.php

index c994908..237e907 100644 (file)
@@ -53,6 +53,7 @@ class BananaPost
             preg_match("/boundary=\"?([^ \"]+)\"?/", $this->headers['content-type'], $mpart_boundary);
             $this->_split_multipart($mpart_type[1], $mpart_boundary[1]);
         } else {
+            $this->_find_uuencode();
             if (preg_match('!charset=([^;]*)\s*(;|$)!', $this->headers['content-type'], $matches)) {
                 $this->body = iconv($matches[1], 'utf-8', $this->body);
             } else {
@@ -61,6 +62,25 @@ class BananaPost
         }
     }
 
+    /** find and add uuencoded attachments
+     */
+    function _find_uuencode()
+    {
+        if (preg_match_all('@\n(begin \d+ ([^\r\n]+)\r?(?:\n(?!end)[^\n]*)*\nend)@', $this->body, $matches, PREG_SET_ORDER)) {
+            foreach ($matches as $match) {
+                $mime = trim(exec('echo '.escapeshellarg($match[1]).' | uudecode -o /dev/stdout | file -bi -'));
+                if ($mime != 'application/x-empty') {
+                    $this->body = str_replace($match[0], '', $this->body);
+                    $body = $match[1];
+                    $header['content-type'] = $mime.'; name="'.$match[2].'"';
+                    $header['content-transfer-encoding'] = 'x-uuencode';
+                    $header['content-disposition'] = 'attachment; filename="'.$match[2].'"';
+                    $this->_add_attachment(Array('headers' => $header, 'body' => $body));
+                }
+            }
+        }
+    }
+
     /** split multipart messages
      * @param $type STRING multipart type description
      * @param $boundary STRING multipart boundary identification string
@@ -174,6 +194,8 @@ class BananaPost
             }                
             if ($file['encoding'] == 'base64') {
                 echo base64_decode($file['data']);
+            } else if ($file['encoding'] == 'x-uuencode') {                
+                passthru('echo '.escapeshellarg($file['data']).' | uudecode -o /dev/stdout');
             } else {
                 header('Content-Transfer-Encoding: '.$file['encoding']);
                 echo $file['data'];