Fix for deleting message from search expiring cache.
[squirrelmail.git] / class / mime / AddressStructure.class.php
index 56dae5338ddfe1cc6b657d5a7fb1a554366c1045..fb1e5f3cf6f34906b3859ca72a904d861b0d2755 100644 (file)
@@ -3,10 +3,10 @@
 /**
  * AddressStructure.class.php
  *
- * This file contains functions needed to extract email address headers from 
+ * This file contains functions needed to extract email address headers from
  * mime messages.
  *
- * @copyright © 2003-2005 The SquirrelMail Project Team
+ * @copyright © 2003-2009 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
@@ -49,7 +49,7 @@ class AddressStructure {
 
     /**
      * Return address information from mime headers.
-     * @param boolean $full return full address (true) or only email (false)
+     * @param boolean $full return full address (true) or only personal if it exists, otherwise email (false)
      * @param boolean $encoded (since 1.4.0) return rfc2047 encoded address (true) or plain text (false).
      * @return string
      */
@@ -60,20 +60,20 @@ class AddressStructure {
                                   : $this->mailbox);
             $personal = trim($this->personal);
             $is_encoded = false;
-            if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/Ui',$personal,$reg)) {
+            if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/i',$personal,$reg)) {
                 $is_encoded = true;
             }
             if ($personal) {
                 if ($encoded && !$is_encoded) {
                     $personal_encoded = encodeHeader($personal);
                     if ($personal !== $personal_encoded) {
-                        $personal = $personal_encoded;
+                        $personal = '"' . $personal_encoded . '"';
                     } else {
-                        $personal = '"'.$this->personal.'"';
+                        $personal = '"' . $this->personal . '"';
                     }
                 } else {
                     if (!$is_encoded) {
-                        $personal = '"'.$this->personal.'"';
+                        $personal = '"' . $this->personal . '"';
                     }
                 }
                 $addr = ($email ? $personal . ' <' .$email.'>'
@@ -97,5 +97,17 @@ class AddressStructure {
     function getEncodedAddress() {
         return $this->getAddress(true, true);
     }
+    
+    /**
+     * Return just the email portion of this address
+     * @return string
+     * @since 1.5.2
+     */
+    function getEmail () {
+        $r = '';
+        if (is_object($this)) {
+            $r = $this->host ? $this->mailbox.'@'.$this->host : $this->mailbox;
+        }
+        return $r;
+    }
 }
-?>
\ No newline at end of file