From e647fd856f75d91348629104ceabee4a80b256a3 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 7 Jul 2009 01:35:47 -0600 Subject: [PATCH] Added Horde_Mime::uudecode() --- framework/Mime/lib/Horde/Mime.php | 33 ++++++++++++++++++- framework/Mime/package.xml | 3 +- framework/Mime/test/Horde/Mime/uudecode.phpt | 49 ++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 framework/Mime/test/Horde/Mime/uudecode.phpt diff --git a/framework/Mime/lib/Horde/Mime.php b/framework/Mime/lib/Horde/Mime.php index 583cca71d..d58ab0f76 100644 --- a/framework/Mime/lib/Horde/Mime.php +++ b/framework/Mime/lib/Horde/Mime.php @@ -442,7 +442,6 @@ class Horde_Mime } else { /* Give $string a bogus body part or else decode() will * complain. */ - require_once 'Mail/mimeDecode.php'; $mime_decode = new Mail_mimeDecode($type . ': ' . $data . "\n\nA"); $res = $mime_decode->decode(); @@ -607,4 +606,36 @@ class Horde_Mime : $id; } + /** + * Scans $input for uuencoded data and converts it to unencoded data. + * + * @param string $input The input data + * + * @return array A list of arrays, with each array corresponding to + * a file in the input and containing the following keys: + *
+     * 'data' - (string) Unencoded data.
+     * 'name' - (string) Filename.
+     * 'perms' - (string) Octal permissions.
+     * 
+ */ + static public function uudecode($input) + { + $data = array(); + + /* Find all uuencoded sections. */ + if (preg_match_all("/begin ([0-7]{3}) (.+)\r?\n(.+)\r?\nend/Us", $input, $matches, PREG_SET_ORDER)) { + reset($matches); + while (list(,$v) = each($matches)) { + $data[] = array( + 'data' => convert_uudecode($v[3]), + 'name' => $v[2], + 'perm' => $v[1] + ); + } + } + + return $data; + } + } diff --git a/framework/Mime/package.xml b/framework/Mime/package.xml index d3032dffe..55d73637d 100644 --- a/framework/Mime/package.xml +++ b/framework/Mime/package.xml @@ -31,7 +31,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> alpha LGPL - * Remove support for deprecated mime_magic module. + * Added Horde_Mime::uudecode(). + * Remove support for deprecated mime_magic module. * Use Gnumeric to display MS Excel documents. * Use AbiWord to display MS Word documents (Request #8011). * Add support for decoding IDN (RFC 3490) names (Request #5836). diff --git a/framework/Mime/test/Horde/Mime/uudecode.phpt b/framework/Mime/test/Horde/Mime/uudecode.phpt new file mode 100644 index 000000000..d8446240e --- /dev/null +++ b/framework/Mime/test/Horde/Mime/uudecode.phpt @@ -0,0 +1,49 @@ +--TEST-- +Horde_Mime::uudecode() test +--FILE-- + +--EXPECT-- +array(2) { + [0]=> + array(3) { + ["data"]=> + string(11) "Test string" + ["name"]=> + string(8) "test.txt" + ["perm"]=> + string(3) "644" + } + [1]=> + array(3) { + ["data"]=> + string(10) "2nd string" + ["name"]=> + string(9) "test2.txt" + ["perm"]=> + string(3) "644" + } +} -- 2.11.0