Readd uudecoding to test/plain Viewer
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 21 Nov 2008 07:07:18 +0000 (00:07 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 21 Nov 2008 07:07:18 +0000 (00:07 -0700)
imp/config/mime_drivers.php.dist
imp/lib/Mime/Viewer/plain.php

index 88b304e..04a68ea 100644 (file)
@@ -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
 );
 
 /**
index 08e317c..dadb613 100644 (file)
@@ -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);
+    }
 }