Added method to encode email addresses
authorstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 24 Feb 2003 18:37:39 +0000 (18:37 +0000)
committerstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 24 Feb 2003 18:37:39 +0000 (18:37 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@4540 7612ce4b-ef26-0410-bec9-ea0150e637f0

class/mime/AddressStructure.class.php
class/mime/Rfc822Header.class.php

index 7621b8f3b2cbb5da9179876cdb8572dd1d86707f..1382493124a76dfaee676735c6d362b755491482 100644 (file)
@@ -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);
+    }
 }
 
 ?>
index 217742954bc6b49a045e3f06a1171714cd65aa58..ddaca41a5ecec92379704d048c14b5e95b6bf370 100644 (file)
@@ -458,28 +458,37 @@ class Rfc822Header {
      * example1: header->getAddr_s('to').
      * example2: header->getAddr_s(array('to', 'cc', 'bcc'))
      */
-    function getAddr_s($arr, $separator = ',') {
+    function getAddr_s($arr, $separator = ',',$encoded=false) {
         $s = '';
 
         if (is_array($arr)) {
             foreach($arr as $arg) {
-                if ($this->getAddr_s($arg)) {
+                if ($this->getAddr_s($arg, $separator, $encoded)) {
                     $s .= $separator . $result;
                 }
             }
             $s = ($s ? substr($s, 2) : $s);
         } else {
-            eval('$addr = $this->' . $arr . ';') ;
+            $addr = $this->{$arr};
+            //eval('$addr = $this->' . $arr . ';') ;
             if (is_array($addr)) {
                 foreach ($addr as $addr_o) {
                     if (is_object($addr_o)) {
-                        $s .= $addr_o->getAddress() . $separator;
+                        if ($encoded) {
+                            $s .= $addr_o->getEncodedAddress() . $separator;
+                        } else {
+                            $s .= $addr_o->getAddress() . $separator;
+                        }
                     }
                 }
                 $s = substr($s, 0, -strlen($separator));
             } else {
                 if (is_object($addr)) {
-                    $s .= $addr->getAddress();
+                    if ($encoded) {
+                        $s .= $addr->getEncodedAddress();
+                    } else {
+                        $s .= $addr->getAddress();
+                    }
                 }
             }
         }