From d07194111216f41fa8c256e88a6ad9a923c33d2a Mon Sep 17 00:00:00 2001 From: stekkel Date: Thu, 17 Oct 2002 22:22:55 +0000 Subject: [PATCH] added function to search the to and cc headers and return the best match git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@3903 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- class/mime/Rfc822Header.class.php | 72 ++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 6 deletions(-) diff --git a/class/mime/Rfc822Header.class.php b/class/mime/Rfc822Header.class.php index a744b914..e168a351 100644 --- a/class/mime/Rfc822Header.class.php +++ b/class/mime/Rfc822Header.class.php @@ -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; -- 2.25.1