added function to search the to and cc headers and return the best match
authorstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 17 Oct 2002 22:22:55 +0000 (22:22 +0000)
committerstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 17 Oct 2002 22:22:55 +0000 (22:22 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@3903 7612ce4b-ef26-0410-bec9-ea0150e637f0

class/mime/Rfc822Header.class.php

index a744b9144f12acaa8f1171b8fd3e8096c97449c7..e168a351f614a20fc7a3fd6cb6c67cebc38ea483 100644 (file)
@@ -51,12 +51,14 @@ class Rfc822Header {
             $pos = strpos($line, ':');
             if ($pos > 0) {
                 $field = substr($line, 0, $pos);
-                $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);
+               if (!strstr($field,' ')) { /* valid field */
+                   $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);
+               }
             }
         }
         if ($this->content_type == '') {
@@ -460,6 +462,64 @@ class Rfc822Header {
         }
         return $arr;
     }
+    
+    function findAddress($address, $recurs = false) {
+       $result = false;
+        if (is_array($address)) {
+           $i=0;
+            foreach($address as $argument) {
+                $match = $this->findAddress($argument, true);
+               $last = end($match);
+               if ($match[1]) {
+                   return $i;
+               } else {
+                   if (count($match[0]) && !$result) {
+                       $result = $i;
+                   }
+               }
+               ++$i;   
+            }
+       } else {
+           $srch_addr = $this->parseAddress($address);
+           $results = array();
+           foreach ($this->to as $to) {
+               if ($to->host == $srch_addr->host) {
+                   if ($to->mailbox == $srch_addr->mailbox) {
+                       $results[] = $srch_addr;
+                       if ($to->personal == $srch_addr->personal) {
+                           if ($recurs) {
+                               return array($results, true);
+                           } else {
+                               return true;
+                           }
+                       }
+                   }
+               }
+           }
+           foreach ($this->cc as $cc) {
+               if ($cc->host == $srch_addr->host) {
+                   if ($cc->mailbox == $srch_addr->mailbox) {
+                       $results[] = $srch_addr;
+                       if ($cc->personal == $srch_addr->personal) {
+                           if ($recurs) {
+                               return array($results, true);
+                           } else {
+                               return true;
+                           }
+                       }
+                   }
+               }
+           }
+           if ($recurs) {
+               return array($results, false);
+           } elseif (count($result)) {
+               return true;
+           } else {
+               return false;
+           }   
+       }
+       return $result;
+    }
 
     function getContentType($type0, $type1) {
         $type0 = $this->content_type->type0;