From: x2003bruneau Date: Thu, 2 Mar 2006 16:29:56 +0000 (+0000) Subject: Gestion des piÚces jointes uuencode dans le cas de message non-multipart (Ex : Outlo... X-Git-Tag: 1.8~273 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=e0f141dd0a826f73c3b274420cad4ce1e82266a8;p=banana.git Gestion des piÚces jointes uuencode dans le cas de message non-multipart (Ex : Outlook Express) git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@22 9869982d-c50d-0410-be91-f2a2ec7c7c7b --- 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'];