From: stekkel Date: Mon, 24 Feb 2003 18:37:39 +0000 (+0000) Subject: Added method to encode email addresses X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2c9ecd119132aff5dfa7bd557a599e89c16da0c2;p=squirrelmail.git Added method to encode email addresses git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@4540 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/class/mime/AddressStructure.class.php b/class/mime/AddressStructure.class.php index 7621b8f3..13824931 100644 --- a/class/mime/AddressStructure.class.php +++ b/class/mime/AddressStructure.class.php @@ -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); + } } ?> diff --git a/class/mime/Rfc822Header.class.php b/class/mime/Rfc822Header.class.php index 21774295..ddaca41a 100644 --- a/class/mime/Rfc822Header.class.php +++ b/class/mime/Rfc822Header.class.php @@ -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(); + } } } }