better parsing of email addresses (also used for processing compose form
[squirrelmail.git] / class / mime / AddressStructure.class.php
CommitLineData
19d470aa 1<?php
2
3/**
4 * AddressStructure.class.php
5 *
76911253 6 * Copyright (c) 2003 The SquirrelMail Project Team
19d470aa 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This contains functions needed to handle mime messages.
10 *
11 * $Id$
12 */
13
14class AddressStructure {
15 var $personal = '',
16 $adl = '',
17 $mailbox = '',
18 $host = '',
19 $group = '';
20
2c9ecd11 21 function getAddress($full = true, $encoded = false) {
19d470aa 22 $result = '';
19d470aa 23 if (is_object($this)) {
53bd5aa2 24 $email = ($this->host ? $this->mailbox.'@'.$this->host
340d67c2 25 : $this->mailbox);
2c9ecd11 26 $personal = trim($this->personal);
340d67c2 27 $is_encoded = false;
28 if (preg_match('/^(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/Ui',$personal,$reg)) {
29 $is_encoded = true;
30 }
2c9ecd11 31 if ($personal) {
340d67c2 32 if ($encoded && !$is_encoded) {
2c9ecd11 33 $personal_encoded = encodeHeader($personal);
34 if ($personal !== $personal_encoded) {
35 $personal = $personal_encoded;
36 } else {
37 $personal = '"'.$this->personal.'"';
38 }
39 } else {
340d67c2 40 if (!$is_encoded) {
41 $personal = '"'.$this->personal.'"';
42 }
2c9ecd11 43 }
340d67c2 44 $addr = ($email ? $personal . ' <' .$email.'>'
45 : $this->personal);
19d470aa 46 $best_dpl = $this->personal;
47 } else {
48 $addr = $email;
49 $best_dpl = $email;
50 }
51 $result = ($full ? $addr : $best_dpl);
52 }
53 return $result;
54 }
2c9ecd11 55
56 function getEncodedAddress() {
57 return $this->getAddress(true, true);
58 }
19d470aa 59}
60
61?>