Add full date and time as "title" (mouseover) text for dates shown on the message...
[squirrelmail.git] / class / mime / AddressStructure.class.php
CommitLineData
19d470aa 1<?php
2
3/**
4 * AddressStructure.class.php
5 *
9f374891 6 * This file contains functions needed to extract email address headers from
0f459286 7 * mime messages.
19d470aa 8 *
79ba18dc 9 * @copyright 2003-2013 The SquirrelMail Project Team
4b4abf93 10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
883d9cd3 11 * @version $Id$
2b646597 12 * @package squirrelmail
0f459286 13 * @subpackage mime
14 * @since 1.3.2
19d470aa 15 */
16
2b646597 17/**
0f459286 18 * Class used to work with email address headers
2b646597 19 * @package squirrelmail
0f459286 20 * @subpackage mime
21 * @since 1.3.2
2b646597 22 */
19d470aa 23class AddressStructure {
0f459286 24 /**
25 * Personal information
26 * @var string
27 */
28 var $personal = '';
29 /**
30 * @todo check use of this variable. var is not used in class.
31 * @var string
32 */
33 var $adl = '';
34 /**
35 * Mailbox name.
36 * @var string
37 */
38 var $mailbox = '';
39 /**
40 * Server address.
41 * @var string
42 */
43 var $host = '';
44 /**
45 * @todo check use of this variable. var is not used in class.
46 * @var string
47 */
48 var $group = '';
19d470aa 49
0f459286 50 /**
51 * Return address information from mime headers.
9f374891 52 * @param boolean $full return full address (true) or only personal if it exists, otherwise email (false)
0f459286 53 * @param boolean $encoded (since 1.4.0) return rfc2047 encoded address (true) or plain text (false).
a9b9e5d3 54 * @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
55 *
0f459286 56 * @return string
57 */
a9b9e5d3 58 function getAddress($full = true, $encoded = false, $unconditionally_quote = FALSE) {
19d470aa 59 $result = '';
19d470aa 60 if (is_object($this)) {
53bd5aa2 61 $email = ($this->host ? $this->mailbox.'@'.$this->host
340d67c2 62 : $this->mailbox);
2c9ecd11 63 $personal = trim($this->personal);
340d67c2 64 $is_encoded = false;
3ca290d9 65 if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/i',$personal,$reg)) {
340d67c2 66 $is_encoded = true;
67 }
2c9ecd11 68 if ($personal) {
340d67c2 69 if ($encoded && !$is_encoded) {
6b76cffa 70 $personal_encoded = encodeHeader('"' . $personal . '"');
2c9ecd11 71 if ($personal !== $personal_encoded) {
6b76cffa 72 $personal = $personal_encoded;
2c9ecd11 73 } else {
a9b9e5d3 74 //FIXME: this probably adds quotes around an encoded string which itself is already quoted
1f98d935 75 $personal = '"' . $this->personal . '"';
2c9ecd11 76 }
77 } else {
a9b9e5d3 78 if (!$is_encoded || $unconditionally_quote) {
1f98d935 79 $personal = '"' . $this->personal . '"';
340d67c2 80 }
2c9ecd11 81 }
340d67c2 82 $addr = ($email ? $personal . ' <' .$email.'>'
91e0dccc 83 : $this->personal);
19d470aa 84 $best_dpl = $this->personal;
85 } else {
86 $addr = $email;
87 $best_dpl = $email;
88 }
89 $result = ($full ? $addr : $best_dpl);
90 }
91 return $result;
92 }
91e0dccc 93
0f459286 94 /**
95 * Shorter version of getAddress() function
96 * Returns full encoded address.
a9b9e5d3 97 * @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
98 *
0f459286 99 * @return string
100 * @since 1.4.0
101 */
a9b9e5d3 102 function getEncodedAddress($unconditionally_quote=FALSE) {
103 return $this->getAddress(true, true, $unconditionally_quote);
2c9ecd11 104 }
079f3e12 105
106 /**
107 * Return just the email portion of this address
108 * @return string
109 * @since 1.5.2
110 */
111 function getEmail () {
112 $r = '';
113 if (is_object($this)) {
114 $r = $this->host ? $this->mailbox.'@'.$this->host : $this->mailbox;
115 }
116 return $r;
117 }
19d470aa 118}