} 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();
: $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;
+ }
+
}
<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).
--- /dev/null
+--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"
+ }
+}