Added method to encode email addresses
[squirrelmail.git] / class / mime / AddressStructure.class.php
index 7621b8f3b2cbb5da9179876cdb8572dd1d86707f..1382493124a76dfaee676735c6d362b755491482 100644 (file)
@@ -18,14 +18,25 @@ class AddressStructure {
         $host     = '',
         $group    = '';
 
         $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);
         $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 {
                                : $this->personal);
                 $best_dpl = $this->personal;
             } else {
@@ -36,6 +47,10 @@ class AddressStructure {
         }
         return $result;
     }
         }
         return $result;
     }
+    
+    function getEncodedAddress() {
+        return $this->getAddress(true, true);
+    }
 }
 
 ?>
 }
 
 ?>