| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace Javanile\Imap2\Roundcube; |
| 5 |
|
| 6 |
class MessageHeader |
| 7 |
{ |
| 8 |
public $id; |
| 9 |
|
| 10 |
public $uid; |
| 11 |
|
| 12 |
public $subject; |
| 13 |
|
| 14 |
public $from; |
| 15 |
|
| 16 |
public $to; |
| 17 |
|
| 18 |
public $cc; |
| 19 |
|
| 20 |
public $replyto; |
| 21 |
|
| 22 |
public $in_reply_to; |
| 23 |
|
| 24 |
public $date; |
| 25 |
|
| 26 |
public $messageID; |
| 27 |
|
| 28 |
public $size; |
| 29 |
|
| 30 |
public $encoding; |
| 31 |
|
| 32 |
public $charset; |
| 33 |
|
| 34 |
public $ctype; |
| 35 |
|
| 36 |
public $timestamp; |
| 37 |
|
| 38 |
public $bodystructure; |
| 39 |
|
| 40 |
public $internaldate; |
| 41 |
|
| 42 |
public $references; |
| 43 |
|
| 44 |
public $priority; |
| 45 |
|
| 46 |
public $mdn_to; |
| 47 |
|
| 48 |
public $folder; |
| 49 |
|
| 50 |
public $others = array(); |
| 51 |
|
| 52 |
public $flags = array(); |
| 53 |
|
| 54 |
private $obj_headers = array( |
| 55 |
'date' => 'date', |
| 56 |
'from' => 'from', |
| 57 |
'to' => 'to', |
| 58 |
'subject' => 'subject', |
| 59 |
'reply-to' => 'replyto', |
| 60 |
'cc' => 'cc', |
| 61 |
'bcc' => 'bcc', |
| 62 |
'mbox' => 'folder', |
| 63 |
'folder' => 'folder', |
| 64 |
'content-transfer-encoding' => 'encoding', |
| 65 |
'in-reply-to' => 'in_reply_to', |
| 66 |
'content-type' => 'ctype', |
| 67 |
'charset' => 'charset', |
| 68 |
'references' => 'references', |
| 69 |
'return-receipt-to' => 'mdn_to', |
| 70 |
'disposition-notification-to' => 'mdn_to', |
| 71 |
'x-confirm-reading-to' => 'mdn_to', |
| 72 |
'message-id' => 'messageID', |
| 73 |
'x-priority' => 'priority', |
| 74 |
); |
| 75 |
|
| 76 |
public function get($name, $decode = true) |
| 77 |
{ |
| 78 |
$name = strtolower($name); |
| 79 |
|
| 80 |
if (isset($this->obj_headers[$name])) { |
| 81 |
$value = $this->{$this->obj_headers[$name]}; |
| 82 |
} |
| 83 |
else { |
| 84 |
$value = $this->others[$name]; |
| 85 |
} |
| 86 |
|
| 87 |
if ($decode) { |
| 88 |
if (is_array($value)) { |
| 89 |
foreach ($value as $key => $val) { |
| 90 |
$val = Mime::decode_header($val, $this->charset); |
| 91 |
$value[$key] = Charset::clean($val); |
| 92 |
} |
| 93 |
} |
| 94 |
else { |
| 95 |
$value = Mime::decode_header($value, $this->charset); |
| 96 |
$value = Charset::clean($value); |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
return $value; |
| 101 |
} |
| 102 |
|
| 103 |
public function set($name, $value) |
| 104 |
{ |
| 105 |
$name = strtolower($name); |
| 106 |
|
| 107 |
if (isset($this->obj_headers[$name])) { |
| 108 |
$this->{$this->obj_headers[$name]} = $value; |
| 109 |
} |
| 110 |
else { |
| 111 |
$this->others[$name] = $value; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
public static function from_array($arr) |
| 117 |
{ |
| 118 |
$obj = new MessageHeader; |
| 119 |
foreach ($arr as $k => $v) |
| 120 |
$obj->set($k, $v); |
| 121 |
|
| 122 |
return $obj; |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
|