From aff2117dfb555c5f73694beff47adecd92e20f96 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 20 Aug 2009 13:50:07 -0600 Subject: [PATCH] Horde_Mime_Part::parseMessage() correctly parses non-MIME parts. --- framework/Crypt/lib/Horde/Crypt/Smime.php | 2 +- framework/Mime/lib/Horde/Mime/Part.php | 38 ++++++++++++++++++++++++++----- framework/Mime/package.xml | 3 ++- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/framework/Crypt/lib/Horde/Crypt/Smime.php b/framework/Crypt/lib/Horde/Crypt/Smime.php index 5049cf3bf..911351dcb 100644 --- a/framework/Crypt/lib/Horde/Crypt/Smime.php +++ b/framework/Crypt/lib/Horde/Crypt/Smime.php @@ -254,7 +254,7 @@ class Horde_Crypt_Smime extends Horde_Crypt $message = $this->encrypt($mime_part->toString(array('headers' => true, 'canonical' => true)), $params); /* Break the result into its components */ - $mime_message = Horde_Mime_Part::parseMessage($message); + $mime_message = Horde_Mime_Part::parseMessage($message, array('forcemime' => true)); $smime_sign = $mime_message->getPart('2'); $smime_sign->setDescription(_("S/MIME Cryptographic Signature")); diff --git a/framework/Mime/lib/Horde/Mime/Part.php b/framework/Mime/lib/Horde/Mime/Part.php index 91462ad89..49fc17577 100644 --- a/framework/Mime/lib/Horde/Mime/Part.php +++ b/framework/Mime/lib/Horde/Mime/Part.php @@ -1724,8 +1724,13 @@ class Horde_Mime_Part * @param string $text The text of the MIME message. * @param array $options Additional options: *
+     * 'forcemime' - (boolean) If true, the message data is assumed to be
+     *               MIME data. If not, a MIME-Version header must exist (RFC
+     *               2045 [4]) to be parsed as a MIME message.
+     *               DEFAULT: false
      * 'structure' - (boolean) If true, returns a structure object instead of
      *               a Horde_Mime_Part object.
+     *               Default: false
      * 
* * @return mixed If 'structure' is true, a structure array. If 'structure' @@ -1737,7 +1742,7 @@ class Horde_Mime_Part /* Find the header. */ list($hdr_pos, $eol) = self::_findHeader($text); - $ob = self::_getStructure(substr($text, 0, $hdr_pos), substr($text, $hdr_pos + $eol)); + $ob = self::_getStructure(substr($text, 0, $hdr_pos), substr($text, $hdr_pos + $eol), null, !empty($options['forcemime'])); return empty($options['structure']) ? self::parseStructure($ob) @@ -1754,13 +1759,32 @@ class Horde_Mime_Part * @return array See Horde_Mime_Part::parseStructure(). */ static protected function _getStructure($header, $body, - $ctype = 'application/octet-stream') + $ctype = 'application/octet-stream', + $forcemime = false) { - $part = array('parts' => array()); - /* Parse headers text into a Horde_Mime_Headers object. */ $hdrs = Horde_Mime_Headers::parseHeaders($header); + /* This is not a MIME message. */ + if (!$forcemime && !$hdrs->getValue('mime-version')) { + $nonmime = array( + 'dparameters' => array(), + 'parameters' => array(), + 'parts' => array(), + 'type' => 'text', + 'subtype' => 'plain' + ); + + if (!empty($body)) { + $nonmime['contents'] = $body; + $nonmime['size'] = strlen(str_replace(array("\r\n", "\n"), array("\n", "\r\n"), $body)); + } + + return $nonmime; + } + + $part = array('parts' => array()); + /* Content type. */ $tmp = $hdrs->getValue('content-type', Horde_Mime_Headers::VALUE_BASE); if (!$tmp) { @@ -1809,7 +1833,7 @@ class Horde_Mime_Part switch ($part['type']) { case 'message': if ($part['subtype'] == 'rfc822') { - $part['parts'][] = self::parseMessage($body, array('structure' => true)); + $part['parts'][] = self::parseMessage($body, array('forcemime' => true, 'structure' => true)); } break; @@ -1834,7 +1858,9 @@ class Horde_Mime_Part * This function can be called statically via: * $data = Horde_Mime_Part::getRawPartText(); * - * @param string $text The full text of the MIME message. + * @param string $text The full text of the MIME message. The text is + * assumed to be MIME data (no MIME-Version checking + * is performed). * @param string $type Either 'header' or 'body'. * @param string $id The MIME ID. * diff --git a/framework/Mime/package.xml b/framework/Mime/package.xml index c679c425e..c4bbb1ff7 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 dependence on PEAR's Mail_mimeDecode::. + * Horde_Mime_Part::parseMessage() correctly parses non-MIME parts. + * Remove dependence on PEAR's Mail_mimeDecode::. * Added Horde_Mime::uudecode(). * Remove support for deprecated mime_magic module. * Use Gnumeric to display MS Excel documents. -- 2.11.0