From fc8eb922d00d39dc91391fc9be30fb34f5937b8f Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 21 Nov 2008 00:07:18 -0700 Subject: [PATCH] Readd uudecoding to test/plain Viewer --- imp/config/mime_drivers.php.dist | 7 ++++- imp/lib/Mime/Viewer/plain.php | 58 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/imp/config/mime_drivers.php.dist b/imp/config/mime_drivers.php.dist index 88b304e58..04a68ea5c 100644 --- a/imp/config/mime_drivers.php.dist +++ b/imp/config/mime_drivers.php.dist @@ -62,7 +62,12 @@ $mime_drivers['imp']['plain'] = array( * messages, set the maximum size of the displayed message here (in * bytes). If exceeded, the user will only be able to download the part. * Set to 0 to disable this check. */ - 'limit_inline_size' => 1048576 + 'limit_inline_size' => 1048576, + /* If you want to scan ALL incoming text/plain messages for UUencoded + * data, set the following to true. This is very performance intensive and + * can take a long time for large messages. It is not recommended (as + * UUencoded data is very rare anymore) and is disabled by default. */ + 'uudecode' => false ); /** diff --git a/imp/lib/Mime/Viewer/plain.php b/imp/lib/Mime/Viewer/plain.php index 08e317c9a..dadb61362 100644 --- a/imp/lib/Mime/Viewer/plain.php +++ b/imp/lib/Mime/Viewer/plain.php @@ -119,7 +119,7 @@ class IMP_Horde_Mime_Viewer_plain extends Horde_Mime_Viewer_plain */ public function embeddedMimeParts() { - return !empty($GLOBALS['conf']['utils']['gnupg']) && $GLOBALS['prefs']->getValue('pgp_scan_body'); + return (!empty($GLOBALS['conf']['utils']['gnupg']) && $GLOBALS['prefs']->getValue('pgp_scan_body')) || $this->getConfigParam('uudecode'); } /** @@ -132,6 +132,24 @@ class IMP_Horde_Mime_Viewer_plain extends Horde_Mime_Viewer_plain */ public function getEmbeddedMimeParts() { + $ret = null; + + if (!empty($GLOBALS['conf']['utils']['gnupg']) && + $GLOBALS['prefs']->getValue('pgp_scan_body')) { + $ret = $this->_parsePGP(); + } + + if (is_null($ret) && $this->getConfigParam('uudecode')) { + $ret = $this->_parseUUencode(); + } + + return $ret; + } + + /* + */ + protected function _parsePGP() + { /* Avoid infinite loop. */ $imp_pgp = &Horde_Crypt::singleton(array('imp', 'pgp')); $parts = $imp_pgp->parsePGPData($this->_mimepart->getContents()); @@ -218,4 +236,42 @@ class IMP_Horde_Mime_Viewer_plain extends Horde_Mime_Viewer_plain return array($mime_id => $new_part); } + + protected function _parseUUencode() + { + $text = String::convertCharset($this->_mimepart->getContents(), $this->_mimepart->getCharset()); + + /* Don't want to use convert_uudecode() here as there may be multiple + * files residing in the text. */ + require_once 'Mail/mimeDecode.php'; + $files = &Mail_mimeDecode::uudecode($text); + if (empty($files)) { + return null; + } + + $new_part = is_a($this->_mimepart, 'Horde_Mime_Message') + ? new Horde_Mime_Message() + : new Horde_Mime_Part(); + $new_part->setType('multipart/mixed'); + $mime_id = $this->_mimepart->getMimeId(); + + $text_part = new Horde_Mime_Part(); + $text_part->setType('text/plain'); + $text_part->setCharset(NLS::getCharset()); + $text_part->setContents(preg_replace("/begin ([0-7]{3}) (.+)\r?\n(.+)\r?\nend/Us", "\n", $text)); + $new_part->addPart($text_part); + + reset($files); + while (list(,$file) = each($files)) { + $uupart = new Horde_Mime_Part(); + $uupart->setType('application/octet-stream'); + $uupart->setContents($file['filedata']); + $uupart->setName(strip_tags($file['filename'])); + $new_part->addPart($uupart); + } + + $new_part->buildMimeIds(is_a($new_part, 'Horde_Mime_Message') ? null : $mime_id); + + return array($mime_id => $new_part); + } } -- 2.11.0