From e0f141dd0a826f73c3b274420cad4ce1e82266a8 Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Thu, 2 Mar 2006 16:29:56 +0000 Subject: [PATCH] =?utf8?q?Gestion=20des=20pi=C3=83=C5=A1ces=20jointes=20uu?= =?utf8?q?encode=20dans=20le=20cas=20de=20message=20non-multipart=20(Ex=20?= =?utf8?q?:=20Outlook=20Express)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@22 9869982d-c50d-0410-be91-f2a2ec7c7c7b --- banana/post.inc.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/banana/post.inc.php b/banana/post.inc.php index c994908..237e907 100644 --- a/banana/post.inc.php +++ b/banana/post.inc.php @@ -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']; -- 2.1.4