X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=class%2Fmime%2FAddressStructure.class.php;h=259804fe93d81ba096fc8120624653e509ff627a;hp=ed5d9f21d9fb0cd8a060433bb966c45507b79ef3;hb=16dd8736f68b753f06df30ff39892ef18579e2ce;hpb=19d470aa121cacdd916319ec6b55af180562805e diff --git a/class/mime/AddressStructure.class.php b/class/mime/AddressStructure.class.php index ed5d9f21..259804fe 100644 --- a/class/mime/AddressStructure.class.php +++ b/class/mime/AddressStructure.class.php @@ -3,36 +3,84 @@ /** * AddressStructure.class.php * - * Copyright (c) 2002 The SquirrelMail Project Team - * Licensed under the GNU GPL. For full terms see the file COPYING. + * This file contains functions needed to extract email address headers from + * mime messages. * - * This contains functions needed to handle mime messages. - * - * $Id$ + * @copyright 2003-2012 The SquirrelMail Project Team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + * @version $Id$ + * @package squirrelmail + * @subpackage mime + * @since 1.3.2 */ +/** + * Class used to work with email address headers + * @package squirrelmail + * @subpackage mime + * @since 1.3.2 + */ class AddressStructure { - var $personal = '', - $adl = '', - $mailbox = '', - $host = '', - $group = ''; + /** + * Personal information + * @var string + */ + var $personal = ''; + /** + * @todo check use of this variable. var is not used in class. + * @var string + */ + var $adl = ''; + /** + * Mailbox name. + * @var string + */ + var $mailbox = ''; + /** + * Server address. + * @var string + */ + var $host = ''; + /** + * @todo check use of this variable. var is not used in class. + * @var string + */ + var $group = ''; - function getAddress($full = true) { + /** + * Return address information from mime headers. + * @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, $unconditionally_quote = FALSE) { $result = ''; - if (is_object($this)) { - if (isset($this->host) && ($this->host != '')) { - $email = $this->mailbox.'@'.$this->host; - } else { - $email = $this->mailbox; + $email = ($this->host ? $this->mailbox.'@'.$this->host + : $this->mailbox); + $personal = trim($this->personal); + $is_encoded = false; + if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/i',$personal,$reg)) { + $is_encoded = true; } - if (trim($this->personal) != '') { - if ($email) { - $addr = '"' . $this->personal . '" <' .$email.'>'; + if ($personal) { + if ($encoded && !$is_encoded) { + $personal_encoded = encodeHeader('"' . $personal . '"'); + if ($personal !== $personal_encoded) { + $personal = $personal_encoded; + } else { + //FIXME: this probably adds quotes around an encoded string which itself is already quoted + $personal = '"' . $this->personal . '"'; + } } else { - $addr = $this->personal; + if (!$is_encoded || $unconditionally_quote) { + $personal = '"' . $this->personal . '"'; + } } + $addr = ($email ? $personal . ' <' .$email.'>' + : $this->personal); $best_dpl = $this->personal; } else { $addr = $email; @@ -42,6 +90,29 @@ class AddressStructure { } return $result; } -} -?> + /** + * 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($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; + } +}