diff --git a/include/pear/Mail/mimeDecode.php b/include/pear/Mail/mimeDecode.php
index f2a768005e1ec4fdccf57a5e523c2e643a224e74..931166957e2c8d1e9c2fa9e3052c2b09db6cb18d 100644
--- a/include/pear/Mail/mimeDecode.php
+++ b/include/pear/Mail/mimeDecode.php
@@ -404,10 +404,16 @@ class Mail_mimeDecode extends PEAR
      */
     function _splitBodyHeader(&$input)
     {
-        // The headers should end within the first 500k of the email...
-        if (preg_match("/^.*?(\r?\n\r?\n)(.)/s", $input, $match, PREG_OFFSET_CAPTURE)) {
-            return array(substr($input, 0, $match[1][1]),
-                   new StringView($input, $match[2][1]));
+        if ($input instanceof StringView)
+            $check = $input->substr(0, 64<<10);
+        else
+            $check = &$input;
+        if (preg_match("/^.*?(\r?\n\r?\n)(.)/s", $check, $match, PREG_OFFSET_CAPTURE)) {
+            $headers = ($input instanceof StringView)
+                ? (string) $input->substr(0, $match[1][1]) : substr($input, 0, $match[1][1]);
+            $body = ($input instanceof StringView)
+                ? $input->substr($match[2][1]) : new StringView($input, $match[2][1]);
+            return array($headers, $body);
         }
         $this->_error = 'Could not split header and body';
         return false;
@@ -887,6 +893,11 @@ class StringView {
             : substr($this->string, $this->start);
     }
 
+    function substr($start, $end=false) {
+        return new StringView($this->string, $this->start + $start,
+            $end ? min($this->start + $end, $this->end ?: PHP_INT_MAX) : $this->end);
+    }
+
     function split($boundary) {
         $matches = array();
         if (!preg_match_all('/^' . preg_quote($boundary) . '/m', $this->string,