Added rfc2184 support in order to handle:
[squirrelmail.git] / class / mime / AddressStructure.class.php
index ed5d9f21d9fb0cd8a060433bb966c45507b79ef3..91e04e27c87046ebe3a7fb692b551a49aae75199 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * AddressStructure.class.php
  *
- * Copyright (c) 2002 The SquirrelMail Project Team
+ * Copyright (c) 2003 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * This contains functions needed to handle mime messages.
@@ -18,21 +18,31 @@ class AddressStructure {
         $host     = '',
         $group    = '';
 
-    function getAddress($full = true) {
+    function getAddress($full = true, $encoded = false) {
         $result = '';
-
         if (is_object($this)) {
-            if (isset($this->host) && ($this->host != '')) {
-                $email = $this->mailbox.'@'.$this->host;
-            } else {
-                $email = $this->mailbox;
+            $email = ($this->host ? $this->mailbox.'@'.$this->host
+                                  : $this->mailbox);
+            $personal = trim($this->personal);
+            $is_encoded = false;
+            if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/Ui',$personal,$reg)) {
+                $is_encoded = true;
             }
-            if (trim($this->personal) != '') {
-                if ($email) {
-                    $addr = '"' . $this->personal . '" <' .$email.'>';
+            if ($personal) {
+                if ($encoded && !$is_encoded) {
+                    $personal_encoded = encodeHeader($personal);
+                    if ($personal !== $personal_encoded) {
+                        $personal = $personal_encoded;
+                    } else {
+                        $personal = '"'.$this->personal.'"';
+                    }
                 } else {
-                    $addr = $this->personal;
+                    if (!$is_encoded) {
+                        $personal = '"'.$this->personal.'"';
+                    }
                 }
+                $addr = ($email ? $personal . ' <' .$email.'>'
+                        : $this->personal);                                    
                 $best_dpl = $this->personal;
             } else {
                 $addr = $email;
@@ -42,6 +52,10 @@ class AddressStructure {
         }
         return $result;
     }
+    
+    function getEncodedAddress() {
+        return $this->getAddress(true, true);
+    }
 }
 
 ?>