Added method to encode email addresses
[squirrelmail.git] / class / mime / AddressStructure.class.php
index f2144c1..1382493 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,14 +18,25 @@ class AddressStructure {
         $host     = '',
         $group    = '';
 
-    function getAddress($full = true) {
+    function getAddress($full = true, $encoded = false) {
         $result = '';
 
         if (is_object($this)) {
             $email = ($this->host ? $this->mailbox.'@'.$this->host
                                  : $this->mailbox);
-            if (trim($this->personal)) {
-               $addr = ($email ? '"' . $this->personal . '" <' .$email.'>'
+            $personal = trim($this->personal);
+            if ($personal) {
+                if ($encoded) {
+                    $personal_encoded = encodeHeader($personal);
+                    if ($personal !== $personal_encoded) {
+                        $personal = $personal_encoded;
+                    } else {
+                        $personal = '"'.$this->personal.'"';
+                    }
+                } else {
+                    $personal = '"'.$this->personal.'"';
+                }
+               $addr = ($email ? $personal . ' <' .$email.'>'
                                : $this->personal);
                 $best_dpl = $this->personal;
             } else {
@@ -36,6 +47,10 @@ class AddressStructure {
         }
         return $result;
     }
+    
+    function getEncodedAddress() {
+        return $this->getAddress(true, true);
+    }
 }
 
 ?>