X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=class%2Fmime%2FAddressStructure.class.php;h=efb12dcd2ea87929c606a447b87cc6b25bebae4f;hp=56dae5338ddfe1cc6b657d5a7fb1a554366c1045;hb=353d074afac6827c90f4bb03e846c5e453d3b5b1;hpb=4b4abf93a9624311afef0c385023724ee46a2b60 diff --git a/class/mime/AddressStructure.class.php b/class/mime/AddressStructure.class.php index 56dae533..efb12dcd 100644 --- a/class/mime/AddressStructure.class.php +++ b/class/mime/AddressStructure.class.php @@ -3,10 +3,10 @@ /** * AddressStructure.class.php * - * This file contains functions needed to extract email address headers from + * This file contains functions needed to extract email address headers from * mime messages. * - * @copyright © 2003-2005 The SquirrelMail Project Team + * @copyright 2003-2018 The SquirrelMail Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version $Id$ * @package squirrelmail @@ -49,31 +49,34 @@ class AddressStructure { /** * Return address information from mime headers. - * @param boolean $full return full address (true) or only email (false) + * @param boolean $full return full address (true) or only personal if it exists, otherwise email (false) * @param boolean $encoded (since 1.4.0) return rfc2047 encoded address (true) or plain text (false). + * @param boolean $unconditionally_quote (since 1.4.21/1.5.2) when TRUE, always quote the personal part, whether or not it is encoded, otherwise quoting is only added if the personal part is not encoded + * * @return string */ - function getAddress($full = true, $encoded = false) { + function getAddress($full = true, $encoded = false, $unconditionally_quote = FALSE) { $result = ''; if (is_object($this)) { $email = ($this->host ? $this->mailbox.'@'.$this->host : $this->mailbox); $personal = trim($this->personal); $is_encoded = false; - if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/Ui',$personal,$reg)) { + if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/i',$personal,$reg)) { $is_encoded = true; } if ($personal) { if ($encoded && !$is_encoded) { - $personal_encoded = encodeHeader($personal); + $personal_encoded = encodeHeader('"' . $personal . '"'); if ($personal !== $personal_encoded) { $personal = $personal_encoded; } else { - $personal = '"'.$this->personal.'"'; + //FIXME: this probably adds quotes around an encoded string which itself is already quoted + $personal = '"' . $this->personal . '"'; } } else { - if (!$is_encoded) { - $personal = '"'.$this->personal.'"'; + if (!$is_encoded || $unconditionally_quote) { + $personal = '"' . $this->personal . '"'; } } $addr = ($email ? $personal . ' <' .$email.'>' @@ -91,11 +94,25 @@ class AddressStructure { /** * Shorter version of getAddress() function * Returns full encoded address. + * @param boolean $unconditionally_quote (since 1.4.21/1.5.2) when TRUE, always quote the personal part, whether or not it is encoded, otherwise quoting is only added if the personal part is not encoded + * * @return string * @since 1.4.0 */ - function getEncodedAddress() { - return $this->getAddress(true, true); + function getEncodedAddress($unconditionally_quote=FALSE) { + return $this->getAddress(true, true, $unconditionally_quote); + } + + /** + * Return just the email portion of this address + * @return string + * @since 1.5.2 + */ + function getEmail () { + $r = ''; + if (is_object($this)) { + $r = $this->host ? $this->mailbox.'@'.$this->host : $this->mailbox; + } + return $r; } } -?> \ No newline at end of file