Add support for SpamAssassin's X-Spam-Status header (#1589520).
[squirrelmail.git] / class / mime / AddressStructure.class.php
1 <?php
2
3 /**
4 * AddressStructure.class.php
5 *
6 * This file contains functions needed to extract email address headers from
7 * mime messages.
8 *
9 * @copyright &copy; 2003-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
12 * @package squirrelmail
13 * @subpackage mime
14 * @since 1.3.2
15 */
16
17 /**
18 * Class used to work with email address headers
19 * @package squirrelmail
20 * @subpackage mime
21 * @since 1.3.2
22 */
23 class AddressStructure {
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 = '';
49
50 /**
51 * Return address information from mime headers.
52 * @param boolean $full return full address (true) or only personal if it exists, otherwise email (false)
53 * @param boolean $encoded (since 1.4.0) return rfc2047 encoded address (true) or plain text (false).
54 * @return string
55 */
56 function getAddress($full = true, $encoded = false) {
57 $result = '';
58 if (is_object($this)) {
59 $email = ($this->host ? $this->mailbox.'@'.$this->host
60 : $this->mailbox);
61 $personal = trim($this->personal);
62 $is_encoded = false;
63 if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/Ui',$personal,$reg)) {
64 $is_encoded = true;
65 }
66 if ($personal) {
67 if ($encoded && !$is_encoded) {
68 $personal_encoded = encodeHeader($personal);
69 if ($personal !== $personal_encoded) {
70 $personal = $personal_encoded;
71 } else {
72 $personal = '"'.$this->personal.'"';
73 }
74 } else {
75 if (!$is_encoded) {
76 $personal = '"'.$this->personal.'"';
77 }
78 }
79 $addr = ($email ? $personal . ' <' .$email.'>'
80 : $this->personal);
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 }
90
91 /**
92 * Shorter version of getAddress() function
93 * Returns full encoded address.
94 * @return string
95 * @since 1.4.0
96 */
97 function getEncodedAddress() {
98 return $this->getAddress(true, true);
99 }
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 }
113 }