Browse Source

* fix for e-mail addresses like: <mailbox@host> (personal name)
now the personal name is no longer interpreted as comment
but is stored as the personal name inside the address object if
there is no other personal name supplied.
in case of:
"personal name1" <mailbox@host> (personal name2)
personal name 1 is used and personal name 2 is treated as comment.
* removed an eval call and replaced by something that doesn't need eval.

stekkel 22 years ago
parent
commit
b54b1c2ac0
1 changed files with 28 additions and 13 deletions
  1. 28 13
      class/mime/Rfc822Header.class.php

+ 28 - 13
class/mime/Rfc822Header.class.php

@@ -53,10 +53,6 @@ class Rfc822Header {
                 $field = substr($line, 0, $pos);
                 $field = substr($line, 0, $pos);
 		if (!strstr($field,' ')) { /* valid field */
 		if (!strstr($field,' ')) { /* valid field */
             	    $value = trim(substr($line, $pos+1));
             	    $value = trim(substr($line, $pos+1));
-            	    if(!preg_match('/^X.*/i', $field) &&
-                       !preg_match('/^Subject/i', $field)) {
-                       $value = $this->stripComments($value);
-                    }
             	    $this->parseField($field, $value);
             	    $this->parseField($field, $value);
 		}
 		}
             }
             }
@@ -68,7 +64,6 @@ class Rfc822Header {
 
 
     function stripComments($value) {
     function stripComments($value) {
         $result = '';
         $result = '';
-
         $cnt = strlen($value);
         $cnt = strlen($value);
         for ($i = 0; $i < $cnt; ++$i) {
         for ($i = 0; $i < $cnt; ++$i) {
             switch ($value{$i}) {
             switch ($value{$i}) {
@@ -113,6 +108,7 @@ class Rfc822Header {
         $field = strtolower($field);
         $field = strtolower($field);
         switch($field) {
         switch($field) {
             case 'date':
             case 'date':
+		$value = $this->stripComments($value);
                 $d = strtr($value, array('  ' => ' '));
                 $d = strtr($value, array('  ' => ' '));
                 $d = explode(' ', $d);
                 $d = explode(' ', $d);
                 $this->date = getTimeStamp($d);
                 $this->date = getTimeStamp($d);
@@ -142,53 +138,67 @@ class Rfc822Header {
                 $this->in_reply_to = $value;
                 $this->in_reply_to = $value;
                 break;
                 break;
             case 'message-id':
             case 'message-id':
+		$value = $this->stripComments($value);
                 $this->message_id = $value;
                 $this->message_id = $value;
                 break;
                 break;
 	    case 'references':
 	    case 'references':
+		$value = $this->stripComments($value);
 	        $this->references = $value;
 	        $this->references = $value;
 		break;
 		break;
             case 'disposition-notification-to':
             case 'disposition-notification-to':
+		$value = $this->stripComments($value);
                 $this->dnt = $this->parseAddress($value);
                 $this->dnt = $this->parseAddress($value);
                 break;
                 break;
             case 'mime-version':
             case 'mime-version':
+		$value = $this->stripComments($value);
                 $value = str_replace(' ', '', $value);
                 $value = str_replace(' ', '', $value);
                 $this->mime = ($value == '1.0' ? true : $this->mime);
                 $this->mime = ($value == '1.0' ? true : $this->mime);
                 break;
                 break;
             case 'content-type':
             case 'content-type':
+		$value = $this->stripComments($value);
                 $this->parseContentType($value);
                 $this->parseContentType($value);
                 break;
                 break;
             case 'content-disposition':
             case 'content-disposition':
+		$value = $this->stripComments($value);
                 $this->parseDisposition($value);
                 $this->parseDisposition($value);
                 break;
                 break;
             case 'user-agent':
             case 'user-agent':
             case 'x-mailer':
             case 'x-mailer':
-                $this->xmailer = $value;
+        	$this->xmailer = $value;
                 break;
                 break;
             case 'x-priority':
             case 'x-priority':
                 $this->priority = $value;
                 $this->priority = $value;
                 break;
                 break;
             case 'list-post':
             case 'list-post':
+		$value = $this->stripComments($value);
                 $this->mlist('post', $value);
                 $this->mlist('post', $value);
                 break;
                 break;
             case 'list-reply':
             case 'list-reply':
+		$value = $this->stripComments($value);	    
                 $this->mlist('reply', $value);
                 $this->mlist('reply', $value);
                 break;
                 break;
             case 'list-subscribe':
             case 'list-subscribe':
+		$value = $this->stripComments($value);	    
                 $this->mlist('subscribe', $value);
                 $this->mlist('subscribe', $value);
                 break;
                 break;
             case 'list-unsubscribe':
             case 'list-unsubscribe':
+		$value = $this->stripComments($value);
                 $this->mlist('unsubscribe', $value);
                 $this->mlist('unsubscribe', $value);
                 break;
                 break;
             case 'list-archive':
             case 'list-archive':
+		$value = $this->stripComments($value);
                 $this->mlist('archive', $value);
                 $this->mlist('archive', $value);
                 break;
                 break;
             case 'list-owner':
             case 'list-owner':
+		$value = $this->stripComments($value);
                 $this->mlist('owner', $value);
                 $this->mlist('owner', $value);
                 break;
                 break;
             case 'list-help':
             case 'list-help':
+		$value = $this->stripComments($value);
                 $this->mlist('help', $value);
                 $this->mlist('help', $value);
                 break;
                 break;
             case 'list-id':
             case 'list-id':
+		$value = $this->stripComments($value);
                 $this->mlist('id', $value);
                 $this->mlist('id', $value);
                 break;
                 break;
             default:
             default:
@@ -217,6 +227,7 @@ class Rfc822Header {
         $j = strlen($address);
         $j = strlen($address);
         $name = '';
         $name = '';
         $addr = '';
         $addr = '';
+	$comment = '';
         while ($pos < $j) {
         while ($pos < $j) {
             switch ($address{$pos}) {
             switch ($address{$pos}) {
                 case '"': /* get the personal name */
                 case '"': /* get the personal name */
@@ -242,12 +253,13 @@ class Rfc822Header {
                     break;
                     break;
                 case '(':  /* rip off comments */
                 case '(':  /* rip off comments */
                     $addr_start = $pos;
                     $addr_start = $pos;
-                    for (++$pos; ($pos < $j) && ($address{$pos} != ')'); ++$pos) {
-                        $addr .= $address{$pos};
-                    }
-                    $address_start = substr($address, 0, $addr_start);
-                    $address_end   = substr($address, $pos + 1);
-                    $address       = $address_start . $address_end;
+		    $pos = strpos($address,')');
+		    if ($pos !== false) {
+			$comment = substr($address, $addr_start+1,($pos-$addr_start-1));
+                	$address_start = substr($address, 0, $addr_start);
+                	$address_end   = substr($address, $pos + 1);
+                	$address       = $address_start . $address_end;
+		    }
                     $j = strlen($address);
                     $j = strlen($address);
                     $pos = $addr_start + 1;
                     $pos = $addr_start + 1;
                     break;
                     break;
@@ -260,6 +272,7 @@ class Rfc822Header {
 
 
                     $at = strpos($addr, '@');
                     $at = strpos($addr, '@');
                     $addr_structure = new AddressStructure();
                     $addr_structure = new AddressStructure();
+		    if (!$name && $comment) $name = $comment;
                     $addr_structure->personal = $name;
                     $addr_structure->personal = $name;
                     $addr_structure->group = $group;
                     $addr_structure->group = $group;
                     if ($at) {
                     if ($at) {
@@ -319,6 +332,7 @@ class Rfc822Header {
         } else if ($name == '') {
         } else if ($name == '') {
             $name = trim(substr($address, 0, $addr_start));
             $name = trim(substr($address, 0, $addr_start));
         }
         }
+        if (!$name && $comment) $name = $comment;
         $at = strpos($addr, '@');
         $at = strpos($addr, '@');
         $addr_structure = new AddressStructure();
         $addr_structure = new AddressStructure();
         $addr_structure->group = $group;
         $addr_structure->group = $group;
@@ -476,7 +490,7 @@ class Rfc822Header {
                 $arr = $this->getAddr_a($argument, $excl_arr, $arr);
                 $arr = $this->getAddr_a($argument, $excl_arr, $arr);
             }
             }
         } else {
         } else {
-            eval('$addr = $this->' . $arg . ';') ;
+	    $addr = $this->{$arg};
             if (is_array($addr)) {
             if (is_array($addr)) {
                 foreach ($addr as $next_addr) {
                 foreach ($addr as $next_addr) {
                     if (is_object($next_addr)) {
                     if (is_object($next_addr)) {
@@ -561,6 +575,7 @@ class Rfc822Header {
 		return false;
 		return false;
 	    }	
 	    }	
 	}
 	}
+        //exit;
 	return $result;
 	return $result;
     }
     }