one more identity action to process
[squirrelmail.git] / class / mime / AddressStructure.class.php
CommitLineData
19d470aa 1<?php
2
3/**
4 * AddressStructure.class.php
5 *
6c84ba1e 6 * Copyright (c) 2003-2005 The SquirrelMail Project Team
19d470aa 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
0f459286 9 * This file contains functions needed to extract email address headers from
10 * mime messages.
19d470aa 11 *
883d9cd3 12 * @version $Id$
2b646597 13 * @package squirrelmail
0f459286 14 * @subpackage mime
15 * @since 1.3.2
19d470aa 16 */
17
2b646597 18/**
0f459286 19 * Class used to work with email address headers
2b646597 20 * @package squirrelmail
0f459286 21 * @subpackage mime
22 * @since 1.3.2
2b646597 23 */
19d470aa 24class AddressStructure {
0f459286 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 = '';
19d470aa 50
0f459286 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 */
2c9ecd11 57 function getAddress($full = true, $encoded = false) {
19d470aa 58 $result = '';
19d470aa 59 if (is_object($this)) {
53bd5aa2 60 $email = ($this->host ? $this->mailbox.'@'.$this->host
340d67c2 61 : $this->mailbox);
2c9ecd11 62 $personal = trim($this->personal);
340d67c2 63 $is_encoded = false;
cdafbbc5 64 if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/Ui',$personal,$reg)) {
340d67c2 65 $is_encoded = true;
66 }
2c9ecd11 67 if ($personal) {
340d67c2 68 if ($encoded && !$is_encoded) {
2c9ecd11 69 $personal_encoded = encodeHeader($personal);
70 if ($personal !== $personal_encoded) {
71 $personal = $personal_encoded;
72 } else {
73 $personal = '"'.$this->personal.'"';
74 }
75 } else {
340d67c2 76 if (!$is_encoded) {
77 $personal = '"'.$this->personal.'"';
78 }
2c9ecd11 79 }
340d67c2 80 $addr = ($email ? $personal . ' <' .$email.'>'
91e0dccc 81 : $this->personal);
19d470aa 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 }
91e0dccc 91
0f459286 92 /**
93 * Shorter version of getAddress() function
94 * Returns full encoded address.
95 * @return string
96 * @since 1.4.0
97 */
2c9ecd11 98 function getEncodedAddress() {
99 return $this->getAddress(true, true);
100 }
19d470aa 101}
8d8da447 102?>