do not add spaces to references header (#1634294),
[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 *
4b5049de 9 * @copyright &copy; 2003-2007 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).
54 * @return string
55 */
2c9ecd11 56 function getAddress($full = true, $encoded = false) {
19d470aa 57 $result = '';
19d470aa 58 if (is_object($this)) {
53bd5aa2 59 $email = ($this->host ? $this->mailbox.'@'.$this->host
340d67c2 60 : $this->mailbox);
2c9ecd11 61 $personal = trim($this->personal);
340d67c2 62 $is_encoded = false;
cdafbbc5 63 if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/Ui',$personal,$reg)) {
340d67c2 64 $is_encoded = true;
65 }
2c9ecd11 66 if ($personal) {
340d67c2 67 if ($encoded && !$is_encoded) {
2c9ecd11 68 $personal_encoded = encodeHeader($personal);
69 if ($personal !== $personal_encoded) {
70 $personal = $personal_encoded;
71 } else {
72 $personal = '"'.$this->personal.'"';
73 }
74 } else {
340d67c2 75 if (!$is_encoded) {
76 $personal = '"'.$this->personal.'"';
77 }
2c9ecd11 78 }
340d67c2 79 $addr = ($email ? $personal . ' <' .$email.'>'
91e0dccc 80 : $this->personal);
19d470aa 81 $best_dpl = $this->personal;
82 } else {
83 $addr = $email;
84 $best_dpl = $email;
85 }
86 $result = ($full ? $addr : $best_dpl);
87 }
88 return $result;
89 }
91e0dccc 90
0f459286 91 /**
92 * Shorter version of getAddress() function
93 * Returns full encoded address.
94 * @return string
95 * @since 1.4.0
96 */
2c9ecd11 97 function getEncodedAddress() {
98 return $this->getAddress(true, true);
99 }
079f3e12 100
101 /**
102 * Return just the email portion of this address
103 * @return string
104 * @since 1.5.2
105 */
106 function getEmail () {
107 $r = '';
108 if (is_object($this)) {
109 $r = $this->host ? $this->mailbox.'@'.$this->host : $this->mailbox;
110 }
111 return $r;
112 }
19d470aa 113}