Better support for malformed/absent dates and headerlines ending in only "\n".
[squirrelmail.git] / class / mime / Rfc822Header.class.php
index 7ecb86bbe2617ffb2a681500bf9df1a4f6591aa3..9f106d86b62d334ede869a4062f9666dc1e1a23f 100644 (file)
@@ -17,7 +17,7 @@
  * @package squirrelmail
  */
 class Rfc822Header {
  * @package squirrelmail
  */
 class Rfc822Header {
-    var $date = '',
+    var $date = -1,
         $subject = '',
         $from = array(),
         $sender = '',
         $subject = '',
         $from = array(),
         $sender = '',
@@ -45,12 +45,12 @@ class Rfc822Header {
         if (is_array($hdr)) {
             $hdr = implode('', $hdr);
         }
         if (is_array($hdr)) {
             $hdr = implode('', $hdr);
         }
-        /* First we unfold the header */
-        $hdr = trim(str_replace(array("\r\n\t", "\r\n "),array(' ', ' '), $hdr));
+        /* First we replace \r\n by \n and unfold the header */
+        $hdr = trim(str_replace(array("\r\n", "\n\t", "\n "),array("\n", ' ', ' '), $hdr));
 
         /* Now we can make a new header array with */
         /* each element representing a headerline  */
 
         /* Now we can make a new header array with */
         /* each element representing a headerline  */
-        $hdr = explode("\r\n" , $hdr);
+        $hdr = explode("\n" , $hdr);
         foreach ($hdr as $line) {
             $pos = strpos($line, ':');
             if ($pos > 0) {
         foreach ($hdr as $line) {
             $pos = strpos($line, ':');
             if ($pos > 0) {