Horde_Mime_Part::parseMessage() correctly parses non-MIME parts.
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 20 Aug 2009 19:50:07 +0000 (13:50 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Sat, 22 Aug 2009 15:26:12 +0000 (09:26 -0600)
framework/Crypt/lib/Horde/Crypt/Smime.php
framework/Mime/lib/Horde/Mime/Part.php
framework/Mime/package.xml

index 5049cf3..911351d 100644 (file)
@@ -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"));
index 91462ad..49fc175 100644 (file)
@@ -1724,8 +1724,13 @@ class Horde_Mime_Part
      * @param string $text    The text of the MIME message.
      * @param array $options  Additional options:
      * <pre>
+     * '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
      * </pre>
      *
      * @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.
      *
index c679c42..c4bbb1f 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 dependence on PEAR's Mail_mimeDecode::.
+ <notes>* 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.