Revert my changes on this plugin, I didn't notice that the globals were dynamically...
[squirrelmail.git] / class / mime / Rfc822Header.class.php
index 4dc03fab48f4a55f883cd794f95887c89100c567..e809797660a0b6fd7d386f6f3be659bce6c4bbeb 100644 (file)
@@ -3,12 +3,12 @@
 /**
  * Rfc822Header.class.php
  *
- * Copyright (c) 2003 The SquirrelMail Project Team
+ * Copyright (c) 2003-2004 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * This contains functions needed to handle mime messages.
  *
- * $Id$
+ * @version $Id$
  * @package squirrelmail
  */
 
@@ -17,7 +17,7 @@
  * @package squirrelmail
  */
 class Rfc822Header {
-    var $date = '',
+    var $date = -1,
         $subject = '',
         $from = array(),
         $sender = '',
@@ -45,12 +45,12 @@ class Rfc822Header {
         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  */
-        $hdr = explode("\r\n" , $hdr);
+        $hdr = explode("\n" , $hdr);
         foreach ($hdr as $line) {
             $pos = strpos($line, ':');
             if ($pos > 0) {
@@ -227,7 +227,6 @@ class Rfc822Header {
 
     function getAddressTokens($address) {
         $aTokens = array();
-        $aAddress = array();
         $aSpecials = array('(' ,'<' ,',' ,';' ,':');
         $aReplace =  array(' (',' <',' ,',' ;',' :');
         $address = str_replace($aSpecials,$aReplace,$address);
@@ -412,7 +411,7 @@ class Rfc822Header {
 
     function parseAddress($address,$ar=false,$aAddress=array(),$sGroup='',$sHost='',$lookup=false) {
         $aTokens = $this->getAddressTokens($address);
-        $sPersonal = $sEmail = $sComment = $sGroup = '';
+        $sPersonal = $sEmail = $sGroup = '';
         $aStack = $aComment = array();
         foreach ($aTokens as $sToken) {
             $cChar = $sToken{0};
@@ -568,7 +567,7 @@ class Rfc822Header {
             if ($pos > 0)  {
                 $key = trim(substr($prop, 0, $pos));
                 $val = trim(substr($prop, $pos+1));
-                if ($val{0} == '"') {
+                if (strlen($val) > 0 && $val{0} == '"') {
                     $val = substr($val, 1, -1);
                 }
                 $propResultArray[$key] = $val;
@@ -621,7 +620,7 @@ class Rfc822Header {
         if (is_array($arr)) {
             foreach($arr as $arg) {
                 if ($this->getAddr_s($arg, $separator, $encoded)) {
-                    $s .= $separator . $result;
+                    $s .= $separator;
                 }
             }
             $s = ($s ? substr($s, 2) : $s);
@@ -692,7 +691,6 @@ class Rfc822Header {
             $i=0;
             foreach($address as $argument) {
                 $match = $this->findAddress($argument, true);
-                $last = end($match);
                 if ($match[1]) {
                     return $i;
                 } else {
@@ -753,4 +751,4 @@ class Rfc822Header {
     }
 }
 
-?>
+?>
\ No newline at end of file