Added Horde_Mime::uudecode()
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 7 Jul 2009 07:35:47 +0000 (01:35 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 7 Jul 2009 16:35:06 +0000 (10:35 -0600)
framework/Mime/lib/Horde/Mime.php
framework/Mime/package.xml
framework/Mime/test/Horde/Mime/uudecode.phpt [new file with mode: 0644]

index 583cca7..d58ab0f 100644 (file)
@@ -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:
+     * <pre>
+     * 'data' - (string) Unencoded data.
+     * 'name' - (string) Filename.
+     * 'perms' - (string) Octal permissions.
+     * </pre>
+     */
+    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;
+    }
+
 }
index d3032df..55d7363 100644 (file)
@@ -31,7 +31,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
   <api>alpha</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Remove support for deprecated mime_magic module.
+ <notes>* 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 (file)
index 0000000..d844624
--- /dev/null
@@ -0,0 +1,49 @@
+--TEST--
+Horde_Mime::uudecode() test
+--FILE--
+<?php
+
+require dirname(__FILE__) . '/../../../lib/Horde/Mime.php';
+
+$encode_1 = convert_uuencode("Test string");
+$encode_2 = convert_uuencode("2nd string");
+
+$data = <<<EOF
+
+Ignore this text.
+
+begin 644 test.txt
+$encode_1
+end
+
+More text to ignore.
+
+begin 644 test2.txt
+$encode_2
+end
+EOF;
+
+var_dump(Horde_Mime::uudecode($data));
+
+?>
+--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"
+  }
+}