one more identity action to process
[squirrelmail.git] / class / mime / AddressStructure.class.php
1 <?php
2
3 /**
4 * AddressStructure.class.php
5 *
6 * Copyright (c) 2003-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This file contains functions needed to extract email address headers from
10 * mime messages.
11 *
12 * @version $Id$
13 * @package squirrelmail
14 * @subpackage mime
15 * @since 1.3.2
16 */
17
18 /**
19 * Class used to work with email address headers
20 * @package squirrelmail
21 * @subpackage mime
22 * @since 1.3.2
23 */
24 class AddressStructure {
25 /**
26 * Personal information
27 * @var string
28 */
29 var $personal = '';
30 /**
31 * @todo check use of this variable. var is not used in class.
32 * @var string
33 */
34 var $adl = '';
35 /**
36 * Mailbox name.
37 * @var string
38 */
39 var $mailbox = '';
40 /**
41 * Server address.
42 * @var string
43 */
44 var $host = '';
45 /**
46 * @todo check use of this variable. var is not used in class.
47 * @var string
48 */
49 var $group = '';
50
51 /**
52 * Return address information from mime headers.
53 * @param boolean $full return full address (true) or only email (false)
54 * @param boolean $encoded (since 1.4.0) return rfc2047 encoded address (true) or plain text (false).
55 * @return string
56 */
57 function getAddress($full = true, $encoded = false) {
58 $result = '';
59 if (is_object($this)) {
60 $email = ($this->host ? $this->mailbox.'@'.$this->host
61 : $this->mailbox);
62 $personal = trim($this->personal);
63 $is_encoded = false;
64 if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/Ui',$personal,$reg)) {
65 $is_encoded = true;
66 }
67 if ($personal) {
68 if ($encoded && !$is_encoded) {
69 $personal_encoded = encodeHeader($personal);
70 if ($personal !== $personal_encoded) {
71 $personal = $personal_encoded;
72 } else {
73 $personal = '"'.$this->personal.'"';
74 }
75 } else {
76 if (!$is_encoded) {
77 $personal = '"'.$this->personal.'"';
78 }
79 }
80 $addr = ($email ? $personal . ' <' .$email.'>'
81 : $this->personal);
82 $best_dpl = $this->personal;
83 } else {
84 $addr = $email;
85 $best_dpl = $email;
86 }
87 $result = ($full ? $addr : $best_dpl);
88 }
89 return $result;
90 }
91
92 /**
93 * Shorter version of getAddress() function
94 * Returns full encoded address.
95 * @return string
96 * @since 1.4.0
97 */
98 function getEncodedAddress() {
99 return $this->getAddress(true, true);
100 }
101 }
102 ?>