commit | author | age
|
0c2596
|
1 |
<?php |
A |
2 |
|
a95874
|
3 |
/** |
0c2596
|
4 |
+-----------------------------------------------------------------------+ |
A |
5 |
| This file is part of the Roundcube Webmail client | |
|
6 |
| Copyright (C) 2005-2012, The Roundcube Dev Team | |
|
7 |
| Copyright (C) 2011-2012, Kolab Systems AG | |
|
8 |
| | |
|
9 |
| Licensed under the GNU General Public License version 3 or | |
|
10 |
| any later version with exceptions for skins & plugins. | |
|
11 |
| See the README file for a full license statement. | |
|
12 |
| | |
|
13 |
| PURPOSE: | |
|
14 |
| E-mail message headers representation | |
|
15 |
+-----------------------------------------------------------------------+ |
|
16 |
| Author: Aleksander Machniak <alec@alec.pl> | |
|
17 |
+-----------------------------------------------------------------------+ |
|
18 |
*/ |
|
19 |
|
|
20 |
/** |
|
21 |
* Struct representing an e-mail message header |
|
22 |
* |
9ab346
|
23 |
* @package Framework |
AM |
24 |
* @subpackage Storage |
|
25 |
* @author Aleksander Machniak <alec@alec.pl> |
0c2596
|
26 |
*/ |
A |
27 |
class rcube_message_header |
|
28 |
{ |
|
29 |
/** |
|
30 |
* Message sequence number |
|
31 |
* |
|
32 |
* @var int |
|
33 |
*/ |
|
34 |
public $id; |
|
35 |
|
|
36 |
/** |
|
37 |
* Message unique identifier |
|
38 |
* |
|
39 |
* @var int |
|
40 |
*/ |
|
41 |
public $uid; |
|
42 |
|
|
43 |
/** |
|
44 |
* Message subject |
|
45 |
* |
|
46 |
* @var string |
|
47 |
*/ |
|
48 |
public $subject; |
|
49 |
|
|
50 |
/** |
|
51 |
* Message sender (From) |
|
52 |
* |
|
53 |
* @var string |
|
54 |
*/ |
|
55 |
public $from; |
|
56 |
|
|
57 |
/** |
|
58 |
* Message recipient (To) |
|
59 |
* |
|
60 |
* @var string |
|
61 |
*/ |
|
62 |
public $to; |
|
63 |
|
|
64 |
/** |
|
65 |
* Message additional recipients (Cc) |
|
66 |
* |
|
67 |
* @var string |
|
68 |
*/ |
|
69 |
public $cc; |
|
70 |
|
|
71 |
/** |
|
72 |
* Message Reply-To header |
|
73 |
* |
|
74 |
* @var string |
|
75 |
*/ |
|
76 |
public $replyto; |
|
77 |
|
|
78 |
/** |
|
79 |
* Message In-Reply-To header |
|
80 |
* |
|
81 |
* @var string |
|
82 |
*/ |
|
83 |
public $in_reply_to; |
|
84 |
|
|
85 |
/** |
|
86 |
* Message date (Date) |
|
87 |
* |
|
88 |
* @var string |
|
89 |
*/ |
|
90 |
public $date; |
|
91 |
|
|
92 |
/** |
|
93 |
* Message identifier (Message-ID) |
|
94 |
* |
|
95 |
* @var string |
|
96 |
*/ |
|
97 |
public $messageID; |
|
98 |
|
|
99 |
/** |
|
100 |
* Message size |
|
101 |
* |
|
102 |
* @var int |
|
103 |
*/ |
|
104 |
public $size; |
|
105 |
|
|
106 |
/** |
|
107 |
* Message encoding |
|
108 |
* |
|
109 |
* @var string |
|
110 |
*/ |
|
111 |
public $encoding; |
|
112 |
|
|
113 |
/** |
|
114 |
* Message charset |
|
115 |
* |
|
116 |
* @var string |
|
117 |
*/ |
|
118 |
public $charset; |
|
119 |
|
|
120 |
/** |
|
121 |
* Message Content-type |
|
122 |
* |
|
123 |
* @var string |
|
124 |
*/ |
|
125 |
public $ctype; |
|
126 |
|
|
127 |
/** |
|
128 |
* Message timestamp (based on message date) |
|
129 |
* |
|
130 |
* @var int |
|
131 |
*/ |
|
132 |
public $timestamp; |
|
133 |
|
|
134 |
/** |
|
135 |
* IMAP bodystructure string |
|
136 |
* |
|
137 |
* @var string |
|
138 |
*/ |
|
139 |
public $bodystructure; |
|
140 |
|
|
141 |
/** |
|
142 |
* IMAP internal date |
|
143 |
* |
|
144 |
* @var string |
|
145 |
*/ |
|
146 |
public $internaldate; |
|
147 |
|
|
148 |
/** |
|
149 |
* Message References header |
|
150 |
* |
|
151 |
* @var string |
|
152 |
*/ |
|
153 |
public $references; |
|
154 |
|
|
155 |
/** |
|
156 |
* Message priority (X-Priority) |
|
157 |
* |
|
158 |
* @var int |
|
159 |
*/ |
|
160 |
public $priority; |
|
161 |
|
|
162 |
/** |
|
163 |
* Message receipt recipient |
|
164 |
* |
|
165 |
* @var string |
|
166 |
*/ |
|
167 |
public $mdn_to; |
|
168 |
|
|
169 |
/** |
628706
|
170 |
* IMAP folder this message is stored in |
T |
171 |
* |
|
172 |
* @var string |
|
173 |
*/ |
|
174 |
public $folder; |
|
175 |
|
|
176 |
/** |
0c2596
|
177 |
* Other message headers |
A |
178 |
* |
|
179 |
* @var array |
|
180 |
*/ |
|
181 |
public $others = array(); |
|
182 |
|
|
183 |
/** |
|
184 |
* Message flags |
|
185 |
* |
|
186 |
* @var array |
|
187 |
*/ |
|
188 |
public $flags = array(); |
111f50
|
189 |
|
A |
190 |
// map header to rcube_message_header object property |
|
191 |
private $obj_headers = array( |
|
192 |
'date' => 'date', |
|
193 |
'from' => 'from', |
|
194 |
'to' => 'to', |
|
195 |
'subject' => 'subject', |
|
196 |
'reply-to' => 'replyto', |
|
197 |
'cc' => 'cc', |
|
198 |
'bcc' => 'bcc', |
628706
|
199 |
'mbox' => 'folder', |
T |
200 |
'folder' => 'folder', |
111f50
|
201 |
'content-transfer-encoding' => 'encoding', |
A |
202 |
'in-reply-to' => 'in_reply_to', |
|
203 |
'content-type' => 'ctype', |
00b98e
|
204 |
'charset' => 'charset', |
111f50
|
205 |
'references' => 'references', |
A |
206 |
'return-receipt-to' => 'mdn_to', |
|
207 |
'disposition-notification-to' => 'mdn_to', |
|
208 |
'x-confirm-reading-to' => 'mdn_to', |
|
209 |
'message-id' => 'messageID', |
|
210 |
'x-priority' => 'priority', |
|
211 |
); |
|
212 |
|
|
213 |
/** |
|
214 |
* Returns header value |
|
215 |
*/ |
0f5dee
|
216 |
public function get($name, $decode = true) |
111f50
|
217 |
{ |
A |
218 |
$name = strtolower($name); |
|
219 |
|
|
220 |
if (isset($this->obj_headers[$name])) { |
0f5dee
|
221 |
$value = $this->{$this->obj_headers[$name]}; |
AM |
222 |
} |
|
223 |
else { |
|
224 |
$value = $this->others[$name]; |
111f50
|
225 |
} |
A |
226 |
|
4fdaa0
|
227 |
if ($decode) { |
539fe0
|
228 |
if (is_array($value)) { |
19926d
|
229 |
foreach ($value as $key => $val) { |
1d0ffd
|
230 |
$val = rcube_mime::decode_header($val, $this->charset); |
539fe0
|
231 |
$value[$key] = rcube_charset::clean($val); |
BB |
232 |
} |
19926d
|
233 |
} |
AM |
234 |
else { |
539fe0
|
235 |
$value = rcube_mime::decode_header($value, $this->charset); |
BB |
236 |
$value = rcube_charset::clean($value); |
|
237 |
} |
4fdaa0
|
238 |
} |
AM |
239 |
|
|
240 |
return $value; |
111f50
|
241 |
} |
A |
242 |
|
|
243 |
/** |
|
244 |
* Sets header value |
|
245 |
*/ |
|
246 |
public function set($name, $value) |
|
247 |
{ |
|
248 |
$name = strtolower($name); |
|
249 |
|
|
250 |
if (isset($this->obj_headers[$name])) { |
|
251 |
$this->{$this->obj_headers[$name]} = $value; |
|
252 |
} |
|
253 |
else { |
|
254 |
$this->others[$name] = $value; |
|
255 |
} |
|
256 |
} |
a8a72e
|
257 |
|
TB |
258 |
|
|
259 |
/** |
|
260 |
* Factory method to instantiate headers from a data array |
|
261 |
* |
|
262 |
* @param array Hash array with header values |
|
263 |
* @return object rcube_message_header instance filled with headers values |
|
264 |
*/ |
|
265 |
public static function from_array($arr) |
|
266 |
{ |
|
267 |
$obj = new rcube_message_header; |
|
268 |
foreach ($arr as $k => $v) |
|
269 |
$obj->set($k, $v); |
|
270 |
|
|
271 |
return $obj; |
|
272 |
} |
0c2596
|
273 |
} |
A |
274 |
|
|
275 |
|
|
276 |
/** |
|
277 |
* Class for sorting an array of rcube_message_header objects in a predetermined order. |
|
278 |
* |
a07224
|
279 |
* @package Framework |
TB |
280 |
* @subpackage Storage |
0c2596
|
281 |
* @author Aleksander Machniak <alec@alec.pl> |
A |
282 |
*/ |
|
283 |
class rcube_message_header_sorter |
|
284 |
{ |
|
285 |
private $uids = array(); |
|
286 |
|
|
287 |
|
|
288 |
/** |
|
289 |
* Set the predetermined sort order. |
|
290 |
* |
|
291 |
* @param array $index Numerically indexed array of IMAP UIDs |
|
292 |
*/ |
|
293 |
function set_index($index) |
|
294 |
{ |
|
295 |
$index = array_flip($index); |
|
296 |
|
|
297 |
$this->uids = $index; |
|
298 |
} |
|
299 |
|
|
300 |
/** |
|
301 |
* Sort the array of header objects |
|
302 |
* |
|
303 |
* @param array $headers Array of rcube_message_header objects indexed by UID |
|
304 |
*/ |
|
305 |
function sort_headers(&$headers) |
|
306 |
{ |
|
307 |
uksort($headers, array($this, "compare_uids")); |
|
308 |
} |
|
309 |
|
|
310 |
/** |
|
311 |
* Sort method called by uksort() |
|
312 |
* |
|
313 |
* @param int $a Array key (UID) |
|
314 |
* @param int $b Array key (UID) |
|
315 |
*/ |
|
316 |
function compare_uids($a, $b) |
|
317 |
{ |
|
318 |
// then find each sequence number in my ordered list |
|
319 |
$posa = isset($this->uids[$a]) ? intval($this->uids[$a]) : -1; |
|
320 |
$posb = isset($this->uids[$b]) ? intval($this->uids[$b]) : -1; |
|
321 |
|
|
322 |
// return the relative position as the comparison value |
|
323 |
return $posa - $posb; |
|
324 |
} |
|
325 |
} |