Frank Brückner 11 лет назад
Родитель
Сommit
83271572b7

+ 374 - 85
library/Zend/Mime.php

@@ -19,7 +19,6 @@
  * @version    $Id$
  */
 
-
 /**
  * Support class for MultiPart Mime Messages
  *
@@ -30,20 +29,20 @@
  */
 class Zend_Mime
 {
-    const TYPE_OCTETSTREAM = 'application/octet-stream';
-    const TYPE_TEXT = 'text/plain';
-    const TYPE_HTML = 'text/html';
-    const ENCODING_7BIT = '7bit';
-    const ENCODING_8BIT = '8bit';
+    const TYPE_OCTETSTREAM         = 'application/octet-stream';
+    const TYPE_TEXT                = 'text/plain';
+    const TYPE_HTML                = 'text/html';
+    const ENCODING_7BIT            = '7bit';
+    const ENCODING_8BIT            = '8bit';
     const ENCODING_QUOTEDPRINTABLE = 'quoted-printable';
-    const ENCODING_BASE64 = 'base64';
-    const DISPOSITION_ATTACHMENT = 'attachment';
-    const DISPOSITION_INLINE = 'inline';
-    const LINELENGTH = 72;
-    const LINEEND = "\n";
-    const MULTIPART_ALTERNATIVE = 'multipart/alternative';
-    const MULTIPART_MIXED = 'multipart/mixed';
-    const MULTIPART_RELATED = 'multipart/related';
+    const ENCODING_BASE64          = 'base64';
+    const DISPOSITION_ATTACHMENT   = 'attachment';
+    const DISPOSITION_INLINE       = 'inline';
+    const LINELENGTH               = 72;
+    const LINEEND                  = "\n";
+    const MULTIPART_ALTERNATIVE    = 'multipart/alternative';
+    const MULTIPART_MIXED          = 'multipart/mixed';
+    const MULTIPART_RELATED        = 'multipart/related';
 
     /**
      * Boundary
@@ -63,61 +62,341 @@ class Zend_Mime
      * @var array
      */
     public static $qpKeys = array(
-        "\x00","\x01","\x02","\x03","\x04","\x05","\x06","\x07",
-        "\x08","\x09","\x0A","\x0B","\x0C","\x0D","\x0E","\x0F",
-        "\x10","\x11","\x12","\x13","\x14","\x15","\x16","\x17",
-        "\x18","\x19","\x1A","\x1B","\x1C","\x1D","\x1E","\x1F",
-        "\x7F","\x80","\x81","\x82","\x83","\x84","\x85","\x86",
-        "\x87","\x88","\x89","\x8A","\x8B","\x8C","\x8D","\x8E",
-        "\x8F","\x90","\x91","\x92","\x93","\x94","\x95","\x96",
-        "\x97","\x98","\x99","\x9A","\x9B","\x9C","\x9D","\x9E",
-        "\x9F","\xA0","\xA1","\xA2","\xA3","\xA4","\xA5","\xA6",
-        "\xA7","\xA8","\xA9","\xAA","\xAB","\xAC","\xAD","\xAE",
-        "\xAF","\xB0","\xB1","\xB2","\xB3","\xB4","\xB5","\xB6",
-        "\xB7","\xB8","\xB9","\xBA","\xBB","\xBC","\xBD","\xBE",
-        "\xBF","\xC0","\xC1","\xC2","\xC3","\xC4","\xC5","\xC6",
-        "\xC7","\xC8","\xC9","\xCA","\xCB","\xCC","\xCD","\xCE",
-        "\xCF","\xD0","\xD1","\xD2","\xD3","\xD4","\xD5","\xD6",
-        "\xD7","\xD8","\xD9","\xDA","\xDB","\xDC","\xDD","\xDE",
-        "\xDF","\xE0","\xE1","\xE2","\xE3","\xE4","\xE5","\xE6",
-        "\xE7","\xE8","\xE9","\xEA","\xEB","\xEC","\xED","\xEE",
-        "\xEF","\xF0","\xF1","\xF2","\xF3","\xF4","\xF5","\xF6",
-        "\xF7","\xF8","\xF9","\xFA","\xFB","\xFC","\xFD","\xFE",
+        "\x00",
+        "\x01",
+        "\x02",
+        "\x03",
+        "\x04",
+        "\x05",
+        "\x06",
+        "\x07",
+        "\x08",
+        "\x09",
+        "\x0A",
+        "\x0B",
+        "\x0C",
+        "\x0D",
+        "\x0E",
+        "\x0F",
+        "\x10",
+        "\x11",
+        "\x12",
+        "\x13",
+        "\x14",
+        "\x15",
+        "\x16",
+        "\x17",
+        "\x18",
+        "\x19",
+        "\x1A",
+        "\x1B",
+        "\x1C",
+        "\x1D",
+        "\x1E",
+        "\x1F",
+        "\x7F",
+        "\x80",
+        "\x81",
+        "\x82",
+        "\x83",
+        "\x84",
+        "\x85",
+        "\x86",
+        "\x87",
+        "\x88",
+        "\x89",
+        "\x8A",
+        "\x8B",
+        "\x8C",
+        "\x8D",
+        "\x8E",
+        "\x8F",
+        "\x90",
+        "\x91",
+        "\x92",
+        "\x93",
+        "\x94",
+        "\x95",
+        "\x96",
+        "\x97",
+        "\x98",
+        "\x99",
+        "\x9A",
+        "\x9B",
+        "\x9C",
+        "\x9D",
+        "\x9E",
+        "\x9F",
+        "\xA0",
+        "\xA1",
+        "\xA2",
+        "\xA3",
+        "\xA4",
+        "\xA5",
+        "\xA6",
+        "\xA7",
+        "\xA8",
+        "\xA9",
+        "\xAA",
+        "\xAB",
+        "\xAC",
+        "\xAD",
+        "\xAE",
+        "\xAF",
+        "\xB0",
+        "\xB1",
+        "\xB2",
+        "\xB3",
+        "\xB4",
+        "\xB5",
+        "\xB6",
+        "\xB7",
+        "\xB8",
+        "\xB9",
+        "\xBA",
+        "\xBB",
+        "\xBC",
+        "\xBD",
+        "\xBE",
+        "\xBF",
+        "\xC0",
+        "\xC1",
+        "\xC2",
+        "\xC3",
+        "\xC4",
+        "\xC5",
+        "\xC6",
+        "\xC7",
+        "\xC8",
+        "\xC9",
+        "\xCA",
+        "\xCB",
+        "\xCC",
+        "\xCD",
+        "\xCE",
+        "\xCF",
+        "\xD0",
+        "\xD1",
+        "\xD2",
+        "\xD3",
+        "\xD4",
+        "\xD5",
+        "\xD6",
+        "\xD7",
+        "\xD8",
+        "\xD9",
+        "\xDA",
+        "\xDB",
+        "\xDC",
+        "\xDD",
+        "\xDE",
+        "\xDF",
+        "\xE0",
+        "\xE1",
+        "\xE2",
+        "\xE3",
+        "\xE4",
+        "\xE5",
+        "\xE6",
+        "\xE7",
+        "\xE8",
+        "\xE9",
+        "\xEA",
+        "\xEB",
+        "\xEC",
+        "\xED",
+        "\xEE",
+        "\xEF",
+        "\xF0",
+        "\xF1",
+        "\xF2",
+        "\xF3",
+        "\xF4",
+        "\xF5",
+        "\xF6",
+        "\xF7",
+        "\xF8",
+        "\xF9",
+        "\xFA",
+        "\xFB",
+        "\xFC",
+        "\xFD",
+        "\xFE",
         "\xFF"
-        );
+    );
 
     /**
      * @var array
      */
     public static $qpReplaceValues = array(
-        "=00","=01","=02","=03","=04","=05","=06","=07",
-        "=08","=09","=0A","=0B","=0C","=0D","=0E","=0F",
-        "=10","=11","=12","=13","=14","=15","=16","=17",
-        "=18","=19","=1A","=1B","=1C","=1D","=1E","=1F",
-        "=7F","=80","=81","=82","=83","=84","=85","=86",
-        "=87","=88","=89","=8A","=8B","=8C","=8D","=8E",
-        "=8F","=90","=91","=92","=93","=94","=95","=96",
-        "=97","=98","=99","=9A","=9B","=9C","=9D","=9E",
-        "=9F","=A0","=A1","=A2","=A3","=A4","=A5","=A6",
-        "=A7","=A8","=A9","=AA","=AB","=AC","=AD","=AE",
-        "=AF","=B0","=B1","=B2","=B3","=B4","=B5","=B6",
-        "=B7","=B8","=B9","=BA","=BB","=BC","=BD","=BE",
-        "=BF","=C0","=C1","=C2","=C3","=C4","=C5","=C6",
-        "=C7","=C8","=C9","=CA","=CB","=CC","=CD","=CE",
-        "=CF","=D0","=D1","=D2","=D3","=D4","=D5","=D6",
-        "=D7","=D8","=D9","=DA","=DB","=DC","=DD","=DE",
-        "=DF","=E0","=E1","=E2","=E3","=E4","=E5","=E6",
-        "=E7","=E8","=E9","=EA","=EB","=EC","=ED","=EE",
-        "=EF","=F0","=F1","=F2","=F3","=F4","=F5","=F6",
-        "=F7","=F8","=F9","=FA","=FB","=FC","=FD","=FE",
+        "=00",
+        "=01",
+        "=02",
+        "=03",
+        "=04",
+        "=05",
+        "=06",
+        "=07",
+        "=08",
+        "=09",
+        "=0A",
+        "=0B",
+        "=0C",
+        "=0D",
+        "=0E",
+        "=0F",
+        "=10",
+        "=11",
+        "=12",
+        "=13",
+        "=14",
+        "=15",
+        "=16",
+        "=17",
+        "=18",
+        "=19",
+        "=1A",
+        "=1B",
+        "=1C",
+        "=1D",
+        "=1E",
+        "=1F",
+        "=7F",
+        "=80",
+        "=81",
+        "=82",
+        "=83",
+        "=84",
+        "=85",
+        "=86",
+        "=87",
+        "=88",
+        "=89",
+        "=8A",
+        "=8B",
+        "=8C",
+        "=8D",
+        "=8E",
+        "=8F",
+        "=90",
+        "=91",
+        "=92",
+        "=93",
+        "=94",
+        "=95",
+        "=96",
+        "=97",
+        "=98",
+        "=99",
+        "=9A",
+        "=9B",
+        "=9C",
+        "=9D",
+        "=9E",
+        "=9F",
+        "=A0",
+        "=A1",
+        "=A2",
+        "=A3",
+        "=A4",
+        "=A5",
+        "=A6",
+        "=A7",
+        "=A8",
+        "=A9",
+        "=AA",
+        "=AB",
+        "=AC",
+        "=AD",
+        "=AE",
+        "=AF",
+        "=B0",
+        "=B1",
+        "=B2",
+        "=B3",
+        "=B4",
+        "=B5",
+        "=B6",
+        "=B7",
+        "=B8",
+        "=B9",
+        "=BA",
+        "=BB",
+        "=BC",
+        "=BD",
+        "=BE",
+        "=BF",
+        "=C0",
+        "=C1",
+        "=C2",
+        "=C3",
+        "=C4",
+        "=C5",
+        "=C6",
+        "=C7",
+        "=C8",
+        "=C9",
+        "=CA",
+        "=CB",
+        "=CC",
+        "=CD",
+        "=CE",
+        "=CF",
+        "=D0",
+        "=D1",
+        "=D2",
+        "=D3",
+        "=D4",
+        "=D5",
+        "=D6",
+        "=D7",
+        "=D8",
+        "=D9",
+        "=DA",
+        "=DB",
+        "=DC",
+        "=DD",
+        "=DE",
+        "=DF",
+        "=E0",
+        "=E1",
+        "=E2",
+        "=E3",
+        "=E4",
+        "=E5",
+        "=E6",
+        "=E7",
+        "=E8",
+        "=E9",
+        "=EA",
+        "=EB",
+        "=EC",
+        "=ED",
+        "=EE",
+        "=EF",
+        "=F0",
+        "=F1",
+        "=F2",
+        "=F3",
+        "=F4",
+        "=F5",
+        "=F6",
+        "=F7",
+        "=F8",
+        "=F9",
+        "=FA",
+        "=FB",
+        "=FC",
+        "=FD",
+        "=FE",
         "=FF"
-        );
+    );
 
     /**
      * @var string
      */
     public static $qpKeysString =
-         "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF";
+        "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF";
 
     /**
      * Check if the given string is "printable"
@@ -141,15 +420,17 @@ class Zend_Mime
      * @param  string $lineEnd    Line end; defaults to {@link LINEEND}
      * @return string
      */
-    public static function encodeQuotedPrintable($str,
+    public static function encodeQuotedPrintable(
+        $str,
         $lineLength = self::LINELENGTH,
-        $lineEnd = self::LINEEND)
+        $lineEnd = self::LINEEND
+    )
     {
         $out = '';
         $str = self::_encodeQuotedPrintable($str);
 
         // Split encoded text into separate lines
-        while(strlen($str) > 0) {
+        while (strlen($str) > 0) {
             $ptr = strlen($str);
             if ($ptr > $lineLength) {
                 $ptr = $lineLength;
@@ -173,6 +454,7 @@ class Zend_Mime
 
         $out = rtrim($out, $lineEnd);
         $out = rtrim($out, '=');
+
         return $out;
     }
 
@@ -187,6 +469,7 @@ class Zend_Mime
         $str = str_replace('=', '=3D', $str);
         $str = str_replace(self::$qpKeys, self::$qpReplaceValues, $str);
         $str = rtrim($str);
+
         return $str;
     }
 
@@ -202,51 +485,54 @@ class Zend_Mime
      * @param  string $lineEnd    Line end; defaults to {@link LINEEND}
      * @return string
      */
-    public static function encodeQuotedPrintableHeader($str, $charset,
-        $lineLength = self::LINELENGTH,
-        $lineEnd = self::LINEEND)
+    public static function encodeQuotedPrintableHeader(
+        $str, $charset, $lineLength = self::LINELENGTH, $lineEnd = self::LINEEND
+    )
     {
         // Reduce line-length by the length of the required delimiter, charsets and encoding
-        $prefix = sprintf('=?%s?Q?', $charset);
-        $lineLength = $lineLength-strlen($prefix)-3;
+        $prefix     = sprintf('=?%s?Q?', $charset);
+        $lineLength = $lineLength - strlen($prefix) - 3;
 
         $str = self::_encodeQuotedPrintable($str);
 
         // Mail-Header required chars have to be encoded also:
-        $str = str_replace(array('?', ' ', '_', ','), array('=3F', '=20', '=5F', '=2C'), $str);
+        $str = str_replace(
+            array('?', ' ', '_', ','), array('=3F', '=20', '=5F', '=2C'), $str
+        );
 
         // initialize first line, we need it anyways
         $lines = array(0 => "");
 
         // Split encoded text into separate lines
         $tmp = "";
-        while(strlen($str) > 0) {
-            $currentLine = max(count($lines)-1, 0);
+        while (strlen($str) > 0) {
+            $currentLine = max(count($lines) - 1, 0);
             $token       = self::getNextQuotedPrintableToken($str);
             $str         = substr($str, strlen($token));
 
             $tmp .= $token;
-            if($token == '=20') {
+            if ($token == '=20') {
                 // only if we have a single char token or space, we can append the
                 // tempstring it to the current line or start a new line if necessary.
-                if(strlen($lines[$currentLine].$tmp) > $lineLength) {
-                    $lines[$currentLine+1] = $tmp;
+                if (strlen($lines[$currentLine] . $tmp) > $lineLength) {
+                    $lines[$currentLine + 1] = $tmp;
                 } else {
                     $lines[$currentLine] .= $tmp;
                 }
                 $tmp = "";
             }
             // don't forget to append the rest to the last line
-            if(strlen($str) == 0) {
+            if (strlen($str) == 0) {
                 $lines[$currentLine] .= $tmp;
             }
         }
 
         // assemble the lines together by pre- and appending delimiters, charset, encoding.
-        for($i = 0; $i < count($lines); $i++) {
-            $lines[$i] = " ".$prefix.$lines[$i]."?=";
+        for ($i = 0; $i < count($lines); $i++) {
+            $lines[$i] = " " . $prefix . $lines[$i] . "?=";
         }
         $str = trim(implode($lineEnd, $lines));
+
         return $str;
     }
 
@@ -258,11 +544,12 @@ class Zend_Mime
      */
     private static function getNextQuotedPrintableToken($str)
     {
-        if(substr($str, 0, 1) == "=") {
+        if (substr($str, 0, 1) == "=") {
             $token = substr($str, 0, 3);
         } else {
             $token = substr($str, 0, 1);
         }
+
         return $token;
     }
 
@@ -275,18 +562,20 @@ class Zend_Mime
      * @param  string $lineEnd    Line end; defaults to {@link LINEEND}
      * @return string
      */
-    public static function encodeBase64Header($str,
-        $charset,
-        $lineLength = self::LINELENGTH,
-        $lineEnd = self::LINEEND)
+    public static function encodeBase64Header(
+        $str, $charset, $lineLength = self::LINELENGTH, $lineEnd = self::LINEEND
+    )
     {
-        $prefix = '=?' . $charset . '?B?';
-        $suffix = '?=';
+        $prefix          = '=?' . $charset . '?B?';
+        $suffix          = '?=';
         $remainingLength = $lineLength - strlen($prefix) - strlen($suffix);
 
         $encodedValue = self::encodeBase64($str, $remainingLength, $lineEnd);
-        $encodedValue = str_replace($lineEnd, $suffix . $lineEnd . ' ' . $prefix, $encodedValue);
+        $encodedValue = str_replace(
+            $lineEnd, $suffix . $lineEnd . ' ' . $prefix, $encodedValue
+        );
         $encodedValue = $prefix . $encodedValue . $suffix;
+
         return $encodedValue;
     }
 
@@ -299,9 +588,9 @@ class Zend_Mime
      * @param  string $lineEnd    Line end; defaults to {@link LINEEND}
      * @return string
      */
-    public static function encodeBase64($str,
-        $lineLength = self::LINELENGTH,
-        $lineEnd = self::LINEEND)
+    public static function encodeBase64(
+        $str, $lineLength = self::LINELENGTH, $lineEnd = self::LINEEND
+    )
     {
         return rtrim(chunk_split(base64_encode($str), $lineLength, $lineEnd));
     }

+ 55 - 23
library/Zend/Mime/Decode.php

@@ -48,7 +48,7 @@ class Zend_Mime_Decode
         $body = str_replace("\r", '', $body);
 
         $start = 0;
-        $res = array();
+        $res   = array();
         // find every mime part limiter and cut out the
         // string before it.
         // the part before the first boundary string is discarded:
@@ -68,12 +68,13 @@ class Zend_Mime_Decode
 
         // no more parts, find end boundary
         $p = strpos($body, '--' . $boundary . '--', $start);
-        if ($p===false) {
+        if ($p === false) {
             throw new Zend_Exception('Not a valid Mime Message: End Missing');
         }
 
         // the remaining part also needs to be parsed:
-        $res[] = substr($body, $start, $p-$start);
+        $res[] = substr($body, $start, $p - $start);
+
         return $res;
     }
 
@@ -83,11 +84,13 @@ class Zend_Mime_Decode
      *
      * @param  string $message  raw message content
      * @param  string $boundary boundary as found in content-type
-     * @param  string $EOL EOL string; defaults to {@link Zend_Mime::LINEEND}
+     * @param  string $EOL      EOL string; defaults to {@link Zend_Mime::LINEEND}
      * @return array|null parts as array('header' => array(name => value), 'body' => content), null if no parts found
      * @throws Zend_Exception
      */
-    public static function splitMessageStruct($message, $boundary, $EOL = Zend_Mime::LINEEND)
+    public static function splitMessageStruct(
+        $message, $boundary, $EOL = Zend_Mime::LINEEND
+    )
     {
         $parts = self::splitMime($message, $boundary);
         if (count($parts) <= 0) {
@@ -96,9 +99,12 @@ class Zend_Mime_Decode
         $result = array();
         foreach ($parts as $part) {
             self::splitMessage($part, $headers, $body, $EOL);
-            $result[] = array('header' => $headers,
-                              'body'   => $body    );
+            $result[] = array(
+                'header' => $headers,
+                'body'   => $body
+            );
         }
+
         return $result;
     }
 
@@ -111,17 +117,28 @@ class Zend_Mime_Decode
      * @param  string $message raw message with header and optional content
      * @param  array  $headers output param, array with headers as array(name => value)
      * @param  string $body    output param, content of message
-     * @param  string $EOL EOL string; defaults to {@link Zend_Mime::LINEEND}
+     * @param  string $EOL     EOL string; defaults to {@link Zend_Mime::LINEEND}
      * @return null
      */
-    public static function splitMessage($message, &$headers, &$body, $EOL = Zend_Mime::LINEEND)
+    public static function splitMessage(
+        $message, &$headers, &$body, $EOL = Zend_Mime::LINEEND
+    )
     {
         // check for valid header at first line
         $firstline = strtok($message, "\n");
         if (!preg_match('%^[^\s]+[^:]*:%', $firstline)) {
             $headers = array();
             // TODO: we're ignoring \r for now - is this function fast enough and is it safe to asume noone needs \r?
-            $body = str_replace(array("\r", "\n"), array('', $EOL), $message);
+            $body = str_replace(
+                array(
+                    "\r",
+                    "\n"
+                ), array(
+                    '',
+                    $EOL
+                ), $message
+            );
+
             return;
         }
 
@@ -129,20 +146,27 @@ class Zend_Mime_Decode
         // default is set new line
         if (strpos($message, $EOL . $EOL)) {
             list($headers, $body) = explode($EOL . $EOL, $message, 2);
-        // next is the standard new line
-        } else if ($EOL != "\r\n" && strpos($message, "\r\n\r\n")) {
-            list($headers, $body) = explode("\r\n\r\n", $message, 2);
-        // next is the other "standard" new line
-        } else if ($EOL != "\n" && strpos($message, "\n\n")) {
-            list($headers, $body) = explode("\n\n", $message, 2);
-        // at last resort find anything that looks like a new line
+            // next is the standard new line
         } else {
-            @list($headers, $body) = @preg_split("%([\r\n]+)\\1%U", $message, 2);
+            if ($EOL != "\r\n" && strpos($message, "\r\n\r\n")) {
+                list($headers, $body) = explode("\r\n\r\n", $message, 2);
+                // next is the other "standard" new line
+            } else {
+                if ($EOL != "\n" && strpos($message, "\n\n")) {
+                    list($headers, $body) = explode("\n\n", $message, 2);
+                    // at last resort find anything that looks like a new line
+                } else {
+                    @list($headers, $body) =
+                        @preg_split("%([\r\n]+)\\1%U", $message, 2);
+                }
+            }
         }
 
-        $headers = iconv_mime_decode_headers($headers, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
+        $headers = iconv_mime_decode_headers(
+            $headers, ICONV_MIME_DECODE_CONTINUE_ON_ERROR
+        );
 
-        if ($headers === false ) {
+        if ($headers === false) {
             // an error occurs during the decoding
             return;
         }
@@ -162,7 +186,10 @@ class Zend_Mime_Decode
                 $headers[$lower][] = $header;
                 continue;
             }
-            $headers[$lower] = array($headers[$lower], $header);
+            $headers[$lower] = array(
+                $headers[$lower],
+                $header
+            );
         }
     }
 
@@ -187,14 +214,17 @@ class Zend_Mime_Decode
      * @throws Zend_Exception
      * @return string|array wanted part or all parts as array($firstName => firstPart, partname => value)
      */
-    public static function splitHeaderField($field, $wantedPart = null, $firstName = 0)
+    public static function splitHeaderField(
+        $field, $wantedPart = null, $firstName = 0
+    )
     {
         $wantedPart = strtolower($wantedPart);
-        $firstName = strtolower($firstName);
+        $firstName  = strtolower($firstName);
 
         // special case - a bit optimized
         if ($firstName === $wantedPart) {
             $field = strtok($field, ';');
+
             return $field[0] == '"' ? substr($field, 1, -1) : $field;
         }
 
@@ -211,8 +241,10 @@ class Zend_Mime_Decode
                 if ($matches[2][$key][0] != '"') {
                     return $matches[2][$key];
                 }
+
                 return substr($matches[2][$key], 1, -1);
             }
+
             return null;
         }
 

+ 2 - 3
library/Zend/Mime/Exception.php

@@ -19,13 +19,11 @@
  * @version    $Id$
  */
 
-
 /**
  * Zend_Exception
  */
 require_once 'Zend/Exception.php';
 
-
 /**
  * @category   Zend
  * @package    Zend_Mime
@@ -33,5 +31,6 @@ require_once 'Zend/Exception.php';
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
 class Zend_Mime_Exception extends Zend_Exception
-{}
+{
+}
 

+ 22 - 17
library/Zend/Mime/Message.php

@@ -19,7 +19,6 @@
  * @version    $Id$
  */
 
-
 /**
  * Zend_Mime
  */
@@ -30,7 +29,6 @@ require_once 'Zend/Mime.php';
  */
 require_once 'Zend/Mime/Part.php';
 
-
 /**
  * @category   Zend
  * @package    Zend_Mime
@@ -39,8 +37,8 @@ require_once 'Zend/Mime/Part.php';
  */
 class Zend_Mime_Message
 {
-
     protected $_parts = array();
+
     protected $_mime = null;
 
     /**
@@ -134,7 +132,7 @@ class Zend_Mime_Message
      */
     public function generateMessage($EOL = Zend_Mime::LINEEND)
     {
-        if (! $this->isMultiPart()) {
+        if (!$this->isMultiPart()) {
             $body = array_shift($this->_parts);
             $body = $body->getContent($EOL);
         } else {
@@ -146,9 +144,9 @@ class Zend_Mime_Message
 
             foreach (array_keys($this->_parts) as $p) {
                 $body .= $boundaryLine
-                       . $this->getPartHeaders($p, $EOL)
-                       . $EOL
-                       . $this->getPartContent($p, $EOL);
+                         . $this->getPartHeaders($p, $EOL)
+                         . $EOL
+                         . $this->getPartContent($p, $EOL);
             }
 
             $body .= $mime->mimeEnd($EOL);
@@ -203,11 +201,11 @@ class Zend_Mime_Message
     protected static function _disassembleMime($body, $boundary)
     {
         $start = 0;
-        $res = array();
+        $res   = array();
         // find every mime part limiter and cut out the
         // string before it.
         // the part before the first boundary string is discarded:
-        $p = strpos($body, '--'.$boundary."\n", $start);
+        $p = strpos($body, '--' . $boundary . "\n", $start);
         if ($p === false) {
             // no parts found!
             return array();
@@ -216,19 +214,21 @@ class Zend_Mime_Message
         // position after first boundary line
         $start = $p + 3 + strlen($boundary);
 
-        while (($p = strpos($body, '--' . $boundary . "\n", $start)) !== false) {
-            $res[] = substr($body, $start, $p-$start);
+        while (($p = strpos($body, '--' . $boundary . "\n", $start))
+               !== false) {
+            $res[] = substr($body, $start, $p - $start);
             $start = $p + 3 + strlen($boundary);
         }
 
         // no more parts, find end boundary
         $p = strpos($body, '--' . $boundary . '--', $start);
-        if ($p===false) {
+        if ($p === false) {
             throw new Zend_Exception('Not a valid Mime Message: End Missing');
         }
 
         // the remaining part also needs to be parsed:
-        $res[] = substr($body, $start, $p-$start);
+        $res[] = substr($body, $start, $p - $start);
+
         return $res;
     }
 
@@ -242,7 +242,9 @@ class Zend_Mime_Message
      * @throws Zend_Exception
      * @return Zend_Mime_Message
      */
-    public static function createFromMessage($message, $boundary, $EOL = Zend_Mime::LINEEND)
+    public static function createFromMessage(
+        $message, $boundary, $EOL = Zend_Mime::LINEEND
+    )
     {
         require_once 'Zend/Mime/Decode.php';
         $parts = Zend_Mime_Decode::splitMessageStruct($message, $boundary, $EOL);
@@ -255,7 +257,7 @@ class Zend_Mime_Message
                 /**
                  * @todo check for characterset and filename
                  */
-                switch(strtolower($key)) {
+                switch (strtolower($key)) {
                     case 'content-type':
                         $newPart->type = $value;
                         break;
@@ -263,7 +265,7 @@ class Zend_Mime_Message
                         $newPart->encoding = $value;
                         break;
                     case 'content-id':
-                        $newPart->id = trim($value,'<>');
+                        $newPart->id = trim($value, '<>');
                         break;
                     case 'content-disposition':
                         $newPart->disposition = $value;
@@ -278,11 +280,14 @@ class Zend_Mime_Message
                         $newPart->language = $value;
                         break;
                     default:
-                        throw new Zend_Exception('Unknown header ignored for MimePart:' . $key);
+                        throw new Zend_Exception(
+                            'Unknown header ignored for MimePart:' . $key
+                        );
                 }
             }
             $res->addPart($newPart);
         }
+
         return $res;
     }
 }

+ 47 - 16
library/Zend/Mime/Part.php

@@ -32,7 +32,8 @@ require_once 'Zend/Mime.php';
  * @copyright  Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
-class Zend_Mime_Part {
+class Zend_Mime_Part
+{
 
     /**
      * Type
@@ -121,7 +122,7 @@ class Zend_Mime_Part {
      * The (unencoded) content of the Part as passed
      * as a string or stream
      *
-     * @param mixed $content  String or Stream containing the content
+     * @param mixed $content String or Stream containing the content
      */
     public function __construct($content)
     {
@@ -147,7 +148,7 @@ class Zend_Mime_Part {
      */
     public function isStream()
     {
-      return $this->_isStream;
+        return $this->_isStream;
     }
 
     /**
@@ -161,7 +162,9 @@ class Zend_Mime_Part {
     {
         if (!$this->_isStream) {
             require_once 'Zend/Mime/Exception.php';
-            throw new Zend_Mime_Exception('Attempt to get a stream from a string part');
+            throw new Zend_Mime_Exception(
+                'Attempt to get a stream from a string part'
+            );
         }
 
         //stream_filter_remove(); // ??? is that right?
@@ -178,9 +181,12 @@ class Zend_Mime_Part {
                 );
                 if (!is_resource($filter)) {
                     require_once 'Zend/Mime/Exception.php';
-                    throw new Zend_Mime_Exception('Failed to append quoted-printable filter');
+                    throw new Zend_Mime_Exception(
+                        'Failed to append quoted-printable filter'
+                    );
                 }
                 break;
+
             case Zend_Mime::ENCODING_BASE64:
                 $filter = stream_filter_append(
                     $this->_content,
@@ -193,11 +199,15 @@ class Zend_Mime_Part {
                 );
                 if (!is_resource($filter)) {
                     require_once 'Zend/Mime/Exception.php';
-                    throw new Zend_Mime_Exception('Failed to append base64 filter');
+                    throw new Zend_Mime_Exception(
+                        'Failed to append base64 filter'
+                    );
                 }
                 break;
+
             default:
         }
+
         return $this->_content;
     }
 
@@ -216,7 +226,7 @@ class Zend_Mime_Part {
             return Zend_Mime::encode($this->_content, $this->encoding, $EOL);
         }
     }
-    
+
     /**
      * Get the RAW unencoded content from this part
      *
@@ -248,17 +258,26 @@ class Zend_Mime_Part {
 
         if ($this->boundary) {
             $contentType .= ';' . $EOL
-                          . " boundary=\"" . $this->boundary . '"';
+                            . " boundary=\"" . $this->boundary . '"';
         }
 
-        $headers[] = array('Content-Type', $contentType);
+        $headers[] = array(
+            'Content-Type',
+            $contentType
+        );
 
         if ($this->encoding) {
-            $headers[] = array('Content-Transfer-Encoding', $this->encoding);
+            $headers[] = array(
+                'Content-Transfer-Encoding',
+                $this->encoding
+            );
         }
 
         if ($this->id) {
-            $headers[]  = array('Content-ID', '<' . $this->id . '>');
+            $headers[] = array(
+                'Content-ID',
+                '<' . $this->id . '>'
+            );
         }
 
         if ($this->disposition) {
@@ -266,19 +285,31 @@ class Zend_Mime_Part {
             if ($this->filename) {
                 $disposition .= '; filename="' . $this->filename . '"';
             }
-            $headers[] = array('Content-Disposition', $disposition);
+            $headers[] = array(
+                'Content-Disposition',
+                $disposition
+            );
         }
 
         if ($this->description) {
-            $headers[] = array('Content-Description', $this->description);
+            $headers[] = array(
+                'Content-Description',
+                $this->description
+            );
         }
 
         if ($this->location) {
-            $headers[] = array('Content-Location', $this->location);
+            $headers[] = array(
+                'Content-Location',
+                $this->location
+            );
         }
 
-        if ($this->language){
-            $headers[] = array('Content-Language', $this->language);
+        if ($this->language) {
+            $headers[] = array(
+                'Content-Language',
+                $this->language
+            );
         }
 
         return $headers;