0
|
1 <?php
|
|
2
|
|
3 /**
|
|
4 +-----------------------------------------------------------------------+
|
|
5 | program/steps/mail/func.inc |
|
|
6 | |
|
|
7 | This file is part of the Roundcube Webmail client |
|
|
8 | Copyright (C) 2005-2014, The Roundcube Dev Team |
|
|
9 | |
|
|
10 | Licensed under the GNU General Public License version 3 or |
|
|
11 | any later version with exceptions for skins & plugins. |
|
|
12 | See the README file for a full license statement. |
|
|
13 | |
|
|
14 | PURPOSE: |
|
|
15 | Provide webmail functionality and GUI objects |
|
|
16 | |
|
|
17 +-----------------------------------------------------------------------+
|
|
18 | Author: Thomas Bruederli <roundcube@gmail.com> |
|
|
19 | Author: Aleksander Machniak <alec@alec.pl> |
|
|
20 +-----------------------------------------------------------------------+
|
|
21 */
|
|
22
|
|
23 // always instantiate storage object (but not connect to server yet)
|
|
24 $RCMAIL->storage_init();
|
|
25
|
|
26 // init environment - set current folder, page, list mode
|
|
27 rcmail_init_env();
|
|
28
|
|
29 // set message set for search result
|
|
30 if (!empty($_REQUEST['_search']) && isset($_SESSION['search'])
|
|
31 && $_SESSION['search_request'] == $_REQUEST['_search']
|
|
32 ) {
|
|
33 $RCMAIL->storage->set_search_set($_SESSION['search']);
|
|
34
|
|
35 $OUTPUT->set_env('search_request', $_REQUEST['_search']);
|
|
36 $OUTPUT->set_env('search_text', $_SESSION['last_text_search']);
|
|
37 }
|
|
38
|
|
39 // remove mbox part from _uid
|
|
40 if (($_uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_GPC)) && !is_array($_uid) && preg_match('/^\d+-.+/', $_uid)) {
|
|
41 list($_uid, $mbox) = explode('-', $_uid, 2);
|
|
42 if (isset($_GET['_uid'])) $_GET['_uid'] = $_uid;
|
|
43 if (isset($_POST['_uid'])) $_POST['_uid'] = $_uid;
|
|
44 $_REQUEST['_uid'] = $_uid;
|
|
45 unset($_uid);
|
|
46
|
|
47 // override mbox
|
|
48 if (!empty($mbox)) {
|
|
49 $_GET['_mbox'] = $mbox;
|
|
50 $_POST['_mbox'] = $mbox;
|
|
51 $RCMAIL->storage->set_folder(($_SESSION['mbox'] = $mbox));
|
|
52 }
|
|
53 }
|
|
54
|
|
55 if (!empty($_SESSION['browser_caps']) && !$OUTPUT->ajax_call) {
|
|
56 $OUTPUT->set_env('browser_capabilities', $_SESSION['browser_caps']);
|
|
57 }
|
|
58
|
|
59 // set main env variables, labels and page title
|
|
60 if (empty($RCMAIL->action) || $RCMAIL->action == 'list') {
|
|
61 // connect to storage server and trigger error on failure
|
|
62 $RCMAIL->storage_connect();
|
|
63
|
|
64 $mbox_name = $RCMAIL->storage->get_folder();
|
|
65
|
|
66 if (empty($RCMAIL->action)) {
|
|
67 $OUTPUT->set_env('search_mods', rcmail_search_mods());
|
|
68
|
|
69 if (!empty($_SESSION['search_scope']))
|
|
70 $OUTPUT->set_env('search_scope', $_SESSION['search_scope']);
|
|
71
|
|
72 rcmail_list_pagetitle();
|
|
73 }
|
|
74
|
|
75 $threading = (bool) $RCMAIL->storage->get_threading();
|
|
76 $delimiter = $RCMAIL->storage->get_hierarchy_delimiter();
|
|
77
|
|
78 // set current mailbox and some other vars in client environment
|
|
79 $OUTPUT->set_env('mailbox', $mbox_name);
|
|
80 $OUTPUT->set_env('pagesize', $RCMAIL->storage->get_pagesize());
|
|
81 $OUTPUT->set_env('current_page', max(1, $_SESSION['page']));
|
|
82 $OUTPUT->set_env('delimiter', $delimiter);
|
|
83 $OUTPUT->set_env('threading', $threading);
|
|
84 $OUTPUT->set_env('threads', $threading || $RCMAIL->storage->get_capability('THREAD'));
|
|
85 $OUTPUT->set_env('reply_all_mode', (int) $RCMAIL->config->get('reply_all_mode'));
|
|
86 $OUTPUT->set_env('layout', $RCMAIL->config->get('layout') ?: 'widescreen');
|
|
87
|
|
88 if ($RCMAIL->storage->get_capability('QUOTA')) {
|
|
89 $OUTPUT->set_env('quota', true);
|
|
90 }
|
|
91
|
|
92 // set special folders
|
|
93 foreach (array('drafts', 'trash', 'junk') as $mbox) {
|
|
94 if ($folder = $RCMAIL->config->get($mbox . '_mbox')) {
|
|
95 $OUTPUT->set_env($mbox . '_mailbox', $folder);
|
|
96 }
|
|
97 }
|
|
98
|
|
99 if (!empty($_GET['_uid'])) {
|
|
100 $OUTPUT->set_env('list_uid', $_GET['_uid']);
|
|
101 }
|
|
102
|
|
103 // set configuration
|
|
104 $RCMAIL->set_env_config(array('delete_junk', 'flag_for_deletion', 'read_when_deleted',
|
|
105 'skip_deleted', 'display_next', 'message_extwin', 'forward_attachment'));
|
|
106
|
|
107 if (!$OUTPUT->ajax_call) {
|
|
108 $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash',
|
|
109 'movingmessage', 'copyingmessage', 'deletingmessage', 'markingmessage',
|
|
110 'copy', 'move', 'quota', 'replyall', 'replylist', 'stillsearching',
|
|
111 'flagged', 'unflagged', 'unread', 'deleted', 'replied', 'forwarded',
|
|
112 'priority', 'withattachment', 'fileuploaderror', 'mark', 'markallread',
|
|
113 'folders-cur', 'folders-sub', 'folders-all', 'cancel');
|
|
114 }
|
|
115 }
|
|
116
|
|
117 // register UI objects
|
|
118 $OUTPUT->add_handlers(array(
|
|
119 'mailboxlist' => array($RCMAIL, 'folder_list'),
|
|
120 'quotadisplay' => array($RCMAIL, 'quota_display'),
|
|
121 'messages' => 'rcmail_message_list',
|
|
122 'messagecountdisplay' => 'rcmail_messagecount_display',
|
|
123 'listmenulink' => 'rcmail_options_menu_link',
|
|
124 'mailboxname' => 'rcmail_mailbox_name_display',
|
|
125 'messageheaders' => 'rcmail_message_headers',
|
|
126 'messagefullheaders' => 'rcmail_message_full_headers',
|
|
127 'messagebody' => 'rcmail_message_body',
|
|
128 'messagecontentframe' => 'rcmail_messagecontent_frame',
|
|
129 'messageimportform' => 'rcmail_message_import_form',
|
|
130 'searchfilter' => 'rcmail_search_filter',
|
|
131 'searchinterval' => 'rcmail_search_interval',
|
|
132 'searchform' => array($OUTPUT, 'search_form'),
|
|
133 ));
|
|
134
|
|
135 // register action aliases
|
|
136 $RCMAIL->register_action_map(array(
|
|
137 'refresh' => 'check_recent.inc',
|
|
138 'preview' => 'show.inc',
|
|
139 'print' => 'show.inc',
|
|
140 'move' => 'move_del.inc',
|
|
141 'delete' => 'move_del.inc',
|
|
142 'send' => 'sendmail.inc',
|
|
143 'expunge' => 'folders.inc',
|
|
144 'purge' => 'folders.inc',
|
|
145 'remove-attachment' => 'attachments.inc',
|
|
146 'rename-attachment' => 'attachments.inc',
|
|
147 'display-attachment' => 'attachments.inc',
|
|
148 'upload' => 'attachments.inc',
|
|
149 'group-expand' => 'autocomplete.inc',
|
|
150 ));
|
|
151
|
|
152
|
|
153 /**
|
|
154 * Sets storage properties and session
|
|
155 */
|
|
156 function rcmail_init_env()
|
|
157 {
|
|
158 global $RCMAIL;
|
|
159
|
|
160 $default_threading = $RCMAIL->config->get('default_list_mode', 'list') == 'threads';
|
|
161 $a_threading = $RCMAIL->config->get('message_threading', array());
|
|
162 $message_sort_col = $RCMAIL->config->get('message_sort_col');
|
|
163 $message_sort_order = $RCMAIL->config->get('message_sort_order');
|
|
164
|
|
165 // set imap properties and session vars
|
|
166 if (!strlen($mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_GPC, true))) {
|
|
167 $mbox = strlen($_SESSION['mbox']) ? $_SESSION['mbox'] : 'INBOX';
|
|
168 }
|
|
169
|
|
170 // we handle 'page' argument on 'list' and 'getunread' to prevent from
|
|
171 // race condition and unintentional page overwrite in session
|
|
172 if ($RCMAIL->action == 'list' || $RCMAIL->action == 'getunread') {
|
|
173 if (!($page = intval($_GET['_page']))) {
|
|
174 $page = $_SESSION['page'] ?: 1;
|
|
175 }
|
|
176
|
|
177 $_SESSION['page'] = $page;
|
|
178 }
|
|
179
|
|
180 $RCMAIL->storage->set_folder($_SESSION['mbox'] = $mbox);
|
|
181 $RCMAIL->storage->set_page($_SESSION['page']);
|
|
182
|
|
183 // set default sort col/order to session
|
|
184 if (!isset($_SESSION['sort_col'])) {
|
|
185 $_SESSION['sort_col'] = $message_sort_col ?: '';
|
|
186 }
|
|
187 if (!isset($_SESSION['sort_order'])) {
|
|
188 $_SESSION['sort_order'] = strtoupper($message_sort_order) == 'ASC' ? 'ASC' : 'DESC';
|
|
189 }
|
|
190
|
|
191 // set threads mode
|
|
192 if (isset($_GET['_threads'])) {
|
|
193 if ($_GET['_threads']) {
|
|
194 // re-set current page number when listing mode changes
|
|
195 if (!$a_threading[$_SESSION['mbox']]) {
|
|
196 $RCMAIL->storage->set_page($_SESSION['page'] = 1);
|
|
197 }
|
|
198
|
|
199 $a_threading[$_SESSION['mbox']] = true;
|
|
200 }
|
|
201 else {
|
|
202 // re-set current page number when listing mode changes
|
|
203 if ($a_threading[$_SESSION['mbox']]) {
|
|
204 $RCMAIL->storage->set_page($_SESSION['page'] = 1);
|
|
205 }
|
|
206
|
|
207 $a_threading[$_SESSION['mbox']] = false;
|
|
208 }
|
|
209
|
|
210 $RCMAIL->user->save_prefs(array('message_threading' => $a_threading));
|
|
211 }
|
|
212
|
|
213 $threading = isset($a_threading[$_SESSION['mbox']]) ? $a_threading[$_SESSION['mbox']] : $default_threading;
|
|
214
|
|
215 $RCMAIL->storage->set_threading($threading);
|
|
216 }
|
|
217
|
|
218 /**
|
|
219 * Sets page title
|
|
220 */
|
|
221 function rcmail_list_pagetitle()
|
|
222 {
|
|
223 global $RCMAIL;
|
|
224
|
|
225 if ($RCMAIL->output->get_env('search_request')) {
|
|
226 $pagetitle = $RCMAIL->gettext('searchresult');
|
|
227 }
|
|
228 else {
|
|
229 $mbox_name = $RCMAIL->output->get_env('mailbox') ?: $RCMAIL->storage->get_folder();
|
|
230 $delimiter = $RCMAIL->storage->get_hierarchy_delimiter();
|
|
231 $pagetitle = $RCMAIL->localize_foldername($mbox_name, true);
|
|
232 $pagetitle = str_replace($delimiter, " \xC2\xBB ", $pagetitle);
|
|
233 }
|
|
234
|
|
235 $RCMAIL->output->set_pagetitle($pagetitle);
|
|
236 }
|
|
237
|
|
238 /**
|
|
239 * Returns default search mods
|
|
240 */
|
|
241 function rcmail_search_mods()
|
|
242 {
|
|
243 global $RCMAIL;
|
|
244
|
|
245 $mods = $RCMAIL->config->get('search_mods');
|
|
246
|
|
247 if (empty($mods)) {
|
|
248 $mods = array('*' => array('subject' => 1, 'from' => 1));
|
|
249
|
|
250 foreach (array('sent', 'drafts') as $mbox) {
|
|
251 if ($mbox = $RCMAIL->config->get($mbox . '_mbox')) {
|
|
252 $mods[$mbox] = array('subject' => 1, 'to' => 1);
|
|
253 }
|
|
254 }
|
|
255 }
|
|
256
|
|
257 return $mods;
|
|
258 }
|
|
259
|
|
260 /**
|
|
261 * Returns 'to' if current folder is configured Sent or Drafts
|
|
262 * or their subfolders, otherwise returns 'from'.
|
|
263 *
|
|
264 * @return string Column name
|
|
265 */
|
|
266 function rcmail_message_list_smart_column_name()
|
|
267 {
|
|
268 global $RCMAIL;
|
|
269
|
|
270 $delim = $RCMAIL->storage->get_hierarchy_delimiter();
|
|
271 $mbox = $RCMAIL->output->get_env('mailbox') ?: $RCMAIL->storage->get_folder();
|
|
272 $sent_mbox = $RCMAIL->config->get('sent_mbox');
|
|
273 $drafts_mbox = $RCMAIL->config->get('drafts_mbox');
|
|
274
|
|
275 if ((strpos($mbox.$delim, $sent_mbox.$delim) === 0 || strpos($mbox.$delim, $drafts_mbox.$delim) === 0)
|
|
276 && strtoupper($mbox) != 'INBOX'
|
|
277 ) {
|
|
278 return 'to';
|
|
279 }
|
|
280
|
|
281 return 'from';
|
|
282 }
|
|
283
|
|
284 /**
|
|
285 * Returns configured messages list sorting column name
|
|
286 * The name is context-sensitive, which means if sorting is set to 'fromto'
|
|
287 * it will return 'from' or 'to' according to current folder type.
|
|
288 *
|
|
289 * @return string Column name
|
|
290 */
|
|
291 function rcmail_sort_column()
|
|
292 {
|
|
293 global $RCMAIL;
|
|
294
|
|
295 if (isset($_SESSION['sort_col'])) {
|
|
296 $column = $_SESSION['sort_col'];
|
|
297 }
|
|
298 else {
|
|
299 $column = $RCMAIL->config->get('message_sort_col');
|
|
300 }
|
|
301
|
|
302 // get name of smart From/To column in folder context
|
|
303 if ($column == 'fromto') {
|
|
304 $column = rcmail_message_list_smart_column_name();
|
|
305 }
|
|
306
|
|
307 return $column;
|
|
308 }
|
|
309
|
|
310 /**
|
|
311 * Returns configured message list sorting order
|
|
312 *
|
|
313 * @return string Sorting order (ASC|DESC)
|
|
314 */
|
|
315 function rcmail_sort_order()
|
|
316 {
|
|
317 global $RCMAIL;
|
|
318
|
|
319 if (isset($_SESSION['sort_order'])) {
|
|
320 return $_SESSION['sort_order'];
|
|
321 }
|
|
322
|
|
323 return $RCMAIL->config->get('message_sort_order');
|
|
324 }
|
|
325
|
|
326 /**
|
|
327 * return the message list as HTML table
|
|
328 */
|
|
329 function rcmail_message_list($attrib)
|
|
330 {
|
|
331 global $RCMAIL, $OUTPUT;
|
|
332
|
|
333 // add some labels to client
|
|
334 $OUTPUT->add_label('from', 'to');
|
|
335
|
|
336 // add id to message list table if not specified
|
|
337 if (!strlen($attrib['id'])) {
|
|
338 $attrib['id'] = 'rcubemessagelist';
|
|
339 }
|
|
340
|
|
341 // define list of cols to be displayed based on parameter or config
|
|
342 if (empty($attrib['columns'])) {
|
|
343 $list_cols = $RCMAIL->config->get('list_cols');
|
|
344 $a_show_cols = !empty($list_cols) && is_array($list_cols) ? $list_cols : array('subject');
|
|
345
|
|
346 $OUTPUT->set_env('col_movable', !in_array('list_cols', (array)$RCMAIL->config->get('dont_override')));
|
|
347 }
|
|
348 else {
|
|
349 $a_show_cols = preg_split('/[\s,;]+/', str_replace(array("'", '"'), '', $attrib['columns']));
|
|
350 $attrib['columns'] = $a_show_cols;
|
|
351 }
|
|
352
|
|
353 // save some variables for use in ajax list
|
|
354 $_SESSION['list_attrib'] = $attrib;
|
|
355
|
|
356 // make sure 'threads' and 'subject' columns are present
|
|
357 if (!in_array('subject', $a_show_cols))
|
|
358 array_unshift($a_show_cols, 'subject');
|
|
359 if (!in_array('threads', $a_show_cols))
|
|
360 array_unshift($a_show_cols, 'threads');
|
|
361
|
|
362 $listcols = $a_show_cols;
|
|
363
|
|
364 // Widescreen layout uses hardcoded list of columns
|
|
365 if ($RCMAIL->config->get('layout', 'widescreen') == 'widescreen') {
|
|
366 $a_show_cols = array('threads', 'subject', 'fromto', 'date', 'flag', 'attachment');
|
|
367 $listcols = $a_show_cols;
|
|
368 array_shift($listcols);
|
|
369 }
|
|
370
|
|
371 // set client env
|
|
372 $OUTPUT->add_gui_object('messagelist', $attrib['id']);
|
|
373 $OUTPUT->set_env('autoexpand_threads', intval($RCMAIL->config->get('autoexpand_threads')));
|
|
374 $OUTPUT->set_env('sort_col', $_SESSION['sort_col']);
|
|
375 $OUTPUT->set_env('sort_order', $_SESSION['sort_order']);
|
|
376 $OUTPUT->set_env('messages', array());
|
|
377 $OUTPUT->set_env('listcols', $listcols);
|
|
378
|
|
379 $OUTPUT->include_script('list.js');
|
|
380
|
|
381 $table = new html_table($attrib);
|
|
382
|
|
383 if (!$attrib['noheader']) {
|
|
384 foreach (rcmail_message_list_head($attrib, $a_show_cols) as $cell)
|
|
385 $table->add_header(array('class' => $cell['className'], 'id' => $cell['id']), $cell['html']);
|
|
386 }
|
|
387
|
|
388 return $table->show();
|
|
389 }
|
|
390
|
|
391 /**
|
|
392 * return javascript commands to add rows to the message list
|
|
393 */
|
|
394 function rcmail_js_message_list($a_headers, $insert_top=false, $a_show_cols=null)
|
|
395 {
|
2
|
396 // Will _not_ have been sorted if sort_col is a flag param, e.g. dates
|
0
|
397 global $RCMAIL, $OUTPUT;
|
|
398
|
|
399 if (empty($a_show_cols)) {
|
|
400 if (!empty($_SESSION['list_attrib']['columns']))
|
|
401 $a_show_cols = $_SESSION['list_attrib']['columns'];
|
|
402 else {
|
|
403 $list_cols = $RCMAIL->config->get('list_cols');
|
|
404 $a_show_cols = !empty($list_cols) && is_array($list_cols) ? $list_cols : array('subject');
|
|
405 }
|
|
406 }
|
|
407 else {
|
|
408 if (!is_array($a_show_cols)) {
|
|
409 $a_show_cols = preg_split('/[\s,;]+/', str_replace(array("'", '"'), '', $a_show_cols));
|
|
410 }
|
|
411 $head_replace = true;
|
|
412 }
|
|
413
|
|
414 $delimiter = $RCMAIL->storage->get_hierarchy_delimiter();
|
|
415 $search_set = $RCMAIL->storage->get_search_set();
|
|
416 $multifolder = $search_set && $search_set[1]->multi;
|
|
417
|
|
418 // add/remove 'folder' column to the list on multi-folder searches
|
|
419 if ($multifolder && !in_array('folder', $a_show_cols)) {
|
|
420 $a_show_cols[] = 'folder';
|
|
421 $head_replace = true;
|
|
422 }
|
|
423 else if (!$multifolder && ($found = array_search('folder', $a_show_cols)) !== false) {
|
|
424 unset($a_show_cols[$found]);
|
|
425 $head_replace = true;
|
|
426 }
|
|
427
|
|
428 $mbox = $RCMAIL->output->get_env('mailbox') ?: $RCMAIL->storage->get_folder();
|
|
429
|
|
430 // make sure 'threads' and 'subject' columns are present
|
|
431 if (!in_array('subject', $a_show_cols))
|
|
432 array_unshift($a_show_cols, 'subject');
|
|
433 if (!in_array('threads', $a_show_cols))
|
|
434 array_unshift($a_show_cols, 'threads');
|
|
435
|
|
436 // Make sure there are no duplicated columns (#1486999)
|
|
437 $a_show_cols = array_unique($a_show_cols);
|
|
438 $_SESSION['list_attrib']['columns'] = $a_show_cols;
|
|
439
|
|
440 // Widescreen layout uses hardcoded list of columns
|
|
441 if ($RCMAIL->config->get('layout', 'widescreen') == 'widescreen') {
|
|
442 $a_show_cols = array('threads', 'subject', 'fromto', 'date', 'flag', 'attachment');
|
|
443 }
|
|
444
|
|
445 // Plugins may set header's list_cols/list_flags and other rcube_message_header variables
|
|
446 // and list columns
|
|
447 $plugin = $RCMAIL->plugins->exec_hook('messages_list',
|
|
448 array('messages' => $a_headers, 'cols' => $a_show_cols));
|
|
449
|
|
450 $a_show_cols = $plugin['cols'];
|
|
451 $a_headers = $plugin['messages'];
|
2
|
452 #rcube::write_log('thunderbird_labels','plugh: '.print_r($a_headers,true));
|
0
|
453 if ($RCMAIL->config->get('layout', 'widescreen') == 'widescreen') {
|
|
454 if (!$RCMAIL->storage->get_threading()) {
|
|
455 if (($idx = array_search('threads', $a_show_cols)) !== false) {
|
|
456 unset($a_show_cols[$idx]);
|
|
457 }
|
|
458 }
|
|
459 }
|
|
460
|
|
461 $thead = $head_replace ? rcmail_message_list_head($_SESSION['list_attrib'], $a_show_cols) : NULL;
|
|
462
|
|
463 // get name of smart From/To column in folder context
|
|
464 if (array_search('fromto', $a_show_cols) !== false) {
|
|
465 $smart_col = rcmail_message_list_smart_column_name();
|
|
466 }
|
|
467
|
|
468 $OUTPUT->command('set_message_coltypes', array_values($a_show_cols), $thead, $smart_col);
|
|
469
|
|
470 if ($multifolder && $_SESSION['search_scope'] == 'all') {
|
|
471 $OUTPUT->command('select_folder', '');
|
|
472 }
|
|
473
|
|
474 $OUTPUT->set_env('multifolder_listing', $multifolder);
|
|
475
|
|
476 if (empty($a_headers)) {
|
|
477 return;
|
|
478 }
|
|
479
|
|
480 // remove 'threads', 'attachment', 'flag', 'status' columns, we don't need them here
|
|
481 foreach (array('threads', 'attachment', 'flag', 'status', 'priority') as $col) {
|
|
482 if (($key = array_search($col, $a_show_cols)) !== FALSE) {
|
|
483 unset($a_show_cols[$key]);
|
|
484 }
|
|
485 }
|
|
486
|
|
487 $sort_col = $_SESSION['sort_col'];
|
|
488
|
|
489 // loop through message headers
|
|
490 foreach ($a_headers as $header) {
|
|
491 if (empty($header) || !$header->size) {
|
|
492 continue;
|
|
493 }
|
|
494
|
|
495 // make message UIDs unique by appending the folder name
|
|
496 if ($multifolder) {
|
|
497 $header->uid .= '-'.$header->folder;
|
|
498 $header->flags['skip_mbox_check'] = true;
|
|
499 if ($header->parent_uid)
|
|
500 $header->parent_uid .= '-'.$header->folder;
|
|
501 }
|
|
502
|
|
503 $a_msg_cols = array();
|
|
504 $a_msg_flags = array();
|
|
505
|
|
506 // format each col; similar as in rcmail_message_list()
|
|
507 foreach ($a_show_cols as $col) {
|
|
508 $col_name = $col == 'fromto' ? $smart_col : $col;
|
|
509
|
|
510 if (in_array($col_name, array('from', 'to', 'cc', 'replyto'))) {
|
|
511 $cont = rcmail_address_string($header->$col_name, 3, false, null, $header->charset);
|
|
512 if (empty($cont)) $cont = ' '; // for widescreen mode
|
|
513 }
|
|
514 else if ($col == 'subject') {
|
|
515 $cont = trim(rcube_mime::decode_header($header->$col, $header->charset));
|
|
516 if (!$cont) $cont = $RCMAIL->gettext('nosubject');
|
|
517 $cont = rcube::Q($cont);
|
|
518 }
|
|
519 else if ($col == 'size')
|
|
520 $cont = $RCMAIL->show_bytes($header->$col);
|
|
521 else if ($col == 'date')
|
|
522 $cont = $RCMAIL->format_date($sort_col == 'arrival' ? $header->internaldate : $header->date);
|
|
523 else if ($col == 'folder') {
|
|
524 if ($last_folder !== $header->folder) {
|
|
525 $last_folder = $header->folder;
|
|
526 $last_folder_name = $RCMAIL->localize_foldername($last_folder, true);
|
|
527 $last_folder_name = str_replace($delimiter, " \xC2\xBB ", $last_folder_name);
|
|
528 }
|
|
529
|
|
530 $cont = rcube::Q($last_folder_name);
|
|
531 }
|
|
532 else
|
|
533 $cont = rcube::Q($header->$col);
|
|
534
|
|
535 $a_msg_cols[$col] = $cont;
|
|
536 }
|
|
537
|
|
538 $a_msg_flags = array_change_key_case(array_map('intval', (array) $header->flags));
|
|
539 if ($header->depth)
|
|
540 $a_msg_flags['depth'] = $header->depth;
|
|
541 else if ($header->has_children)
|
|
542 $roots[] = $header->uid;
|
|
543 if ($header->parent_uid)
|
|
544 $a_msg_flags['parent_uid'] = $header->parent_uid;
|
|
545 if ($header->has_children)
|
|
546 $a_msg_flags['has_children'] = $header->has_children;
|
|
547 if ($header->unread_children)
|
|
548 $a_msg_flags['unread_children'] = $header->unread_children;
|
|
549 if ($header->flagged_children)
|
|
550 $a_msg_flags['flagged_children'] = $header->flagged_children;
|
|
551 if ($header->others['list-post'])
|
|
552 $a_msg_flags['ml'] = 1;
|
|
553 if ($header->priority)
|
|
554 $a_msg_flags['prio'] = (int) $header->priority;
|
|
555
|
|
556 $a_msg_flags['ctype'] = rcube::Q($header->ctype);
|
|
557 $a_msg_flags['mbox'] = $header->folder;
|
|
558
|
|
559 // merge with plugin result (Deprecated, use $header->flags)
|
|
560 if (!empty($header->list_flags) && is_array($header->list_flags))
|
|
561 $a_msg_flags = array_merge($a_msg_flags, $header->list_flags);
|
|
562 if (!empty($header->list_cols) && is_array($header->list_cols))
|
|
563 $a_msg_cols = array_merge($a_msg_cols, $header->list_cols);
|
|
564
|
|
565 $OUTPUT->command('add_message_row', $header->uid, $a_msg_cols, $a_msg_flags, $insert_top);
|
|
566 }
|
|
567
|
|
568 if ($RCMAIL->storage->get_threading()) {
|
|
569 $OUTPUT->command('init_threads', (array) $roots, $mbox);
|
|
570 }
|
|
571 }
|
|
572
|
|
573 /*
|
|
574 * Creates <THEAD> for message list table
|
|
575 */
|
|
576 function rcmail_message_list_head($attrib, $a_show_cols)
|
|
577 {
|
|
578 global $RCMAIL;
|
|
579
|
|
580 // check to see if we have some settings for sorting
|
|
581 $sort_col = $_SESSION['sort_col'];
|
|
582 $sort_order = $_SESSION['sort_order'];
|
|
583
|
|
584 $dont_override = (array) $RCMAIL->config->get('dont_override');
|
|
585 $disabled_sort = in_array('message_sort_col', $dont_override);
|
|
586 $disabled_order = in_array('message_sort_order', $dont_override);
|
|
587
|
|
588 $RCMAIL->output->set_env('disabled_sort_col', $disabled_sort);
|
|
589 $RCMAIL->output->set_env('disabled_sort_order', $disabled_order);
|
|
590
|
|
591 // define sortable columns
|
|
592 if ($disabled_sort)
|
|
593 $a_sort_cols = $sort_col && !$disabled_order ? array($sort_col) : array();
|
|
594 else
|
2
|
595 $a_sort_cols = array('subject', 'date', 'from', 'to', 'fromto', 'size', 'cc','dates');
|
|
596
|
|
597 #rcube::write_log('mail','asc: '.print_r($a_sort_cols,true));
|
0
|
598 if (!empty($attrib['optionsmenuicon'])) {
|
|
599 $list_menu = rcmail_options_menu_link($attrib);
|
|
600 }
|
|
601
|
|
602 $cells = $coltypes = array();
|
|
603
|
|
604 // get name of smart From/To column in folder context
|
|
605 if (array_search('fromto', $a_show_cols) !== false) {
|
|
606 $smart_col = rcmail_message_list_smart_column_name();
|
|
607 }
|
|
608
|
|
609 foreach ($a_show_cols as $col) {
|
|
610 $label = '';
|
|
611 $sortable = false;
|
|
612 $rel_col = $col == 'date' && $sort_col == 'arrival' ? 'arrival' : $col;
|
|
613
|
|
614 // get column name
|
|
615 switch ($col) {
|
|
616 case 'flag':
|
|
617 $col_name = html::span('flagged', $RCMAIL->gettext('flagged'));
|
|
618 break;
|
|
619 case 'attachment':
|
|
620 case 'priority':
|
|
621 $col_name = html::span($col, $RCMAIL->gettext($col));
|
|
622 break;
|
|
623 case 'status':
|
|
624 $col_name = html::span($col, $RCMAIL->gettext('readstatus'));
|
|
625 break;
|
|
626 case 'threads':
|
|
627 $col_name = (string) $list_menu;
|
|
628 break;
|
|
629 case 'fromto':
|
|
630 $label = $RCMAIL->gettext($smart_col);
|
|
631 $col_name = rcube::Q($label);
|
|
632 break;
|
|
633 default:
|
|
634 $label = $RCMAIL->gettext($col);
|
|
635 $col_name = rcube::Q($label);
|
|
636 }
|
|
637
|
|
638 // make sort links
|
|
639 if (in_array($col, $a_sort_cols)) {
|
|
640 $sortable = true;
|
|
641 $col_name = html::a(array(
|
|
642 'href' => "./#sort",
|
|
643 'class' => 'sortcol',
|
|
644 'rel' => $rel_col,
|
|
645 'title' => $RCMAIL->gettext('sortby')
|
|
646 ), $col_name);
|
|
647 }
|
|
648 else if ($col_name[0] != '<') {
|
|
649 $col_name = '<span class="' . $col .'">' . $col_name . '</span>';
|
|
650 }
|
|
651
|
|
652 $sort_class = $rel_col == $sort_col && !$disabled_order ? " sorted$sort_order" : '';
|
|
653 $class_name = $col.$sort_class;
|
|
654
|
|
655 // put it all together
|
|
656 $cells[] = array('className' => $class_name, 'id' => "rcm$col", 'html' => $col_name);
|
|
657 $coltypes[$col] = array('className' => $class_name, 'id' => "rcm$col", 'label' => $label, 'sortable' => $sortable);
|
|
658 }
|
|
659
|
|
660 $RCMAIL->output->set_env('coltypes', $coltypes);
|
|
661 return $cells;
|
|
662 }
|
|
663
|
|
664 function rcmail_options_menu_link($attrib)
|
|
665 {
|
|
666 global $RCMAIL;
|
|
667
|
|
668 $onclick = 'return ' . rcmail_output::JS_OBJECT_NAME . ".command('menu-open', 'messagelistmenu', this, event)";
|
|
669 $inner = $title = $RCMAIL->gettext('listoptions');
|
|
670
|
|
671 if (is_string($attrib['optionsmenuicon']) && $attrib['optionsmenuicon'] != 'true') {
|
|
672 $inner = html::img(array('src' => $RCMAIL->output->abs_url($attrib['optionsmenuicon'], true), 'alt' => $title));
|
|
673 }
|
|
674
|
|
675 return html::a(array(
|
|
676 'href' => '#list-options',
|
|
677 'onclick' => $onclick,
|
|
678 'class' => 'listmenu',
|
|
679 'id' => 'listmenulink',
|
|
680 'title' => $title,
|
|
681 'tabindex' => '0',
|
|
682 ), $inner);
|
|
683 }
|
|
684
|
|
685 /**
|
|
686 * Return an HTML iframe for loading mail content
|
|
687 */
|
|
688 function rcmail_messagecontent_frame($attrib)
|
|
689 {
|
|
690 global $OUTPUT;
|
|
691
|
|
692 if (empty($attrib['id'])) {
|
|
693 $attrib['id'] = 'rcmailcontentwindow';
|
|
694 }
|
|
695
|
|
696 return $OUTPUT->frame($attrib, true);
|
|
697 }
|
|
698
|
|
699 function rcmail_messagecount_display($attrib)
|
|
700 {
|
|
701 global $RCMAIL;
|
|
702
|
|
703 if (!$attrib['id']) {
|
|
704 $attrib['id'] = 'rcmcountdisplay';
|
|
705 }
|
|
706
|
|
707 $RCMAIL->output->add_gui_object('countdisplay', $attrib['id']);
|
|
708
|
|
709 $content = $RCMAIL->action != 'show' ? rcmail_get_messagecount_text() : $RCMAIL->gettext('loading');
|
|
710
|
|
711 return html::span($attrib, $content);
|
|
712 }
|
|
713
|
|
714 function rcmail_get_messagecount_text($count = null, $page = null)
|
|
715 {
|
|
716 global $RCMAIL;
|
|
717
|
|
718 if ($page === null) {
|
|
719 $page = $RCMAIL->storage->get_page();
|
|
720 }
|
|
721
|
|
722 $page_size = $RCMAIL->storage->get_pagesize();
|
|
723 $start_msg = ($page-1) * $page_size + 1;
|
|
724 $max = $count;
|
|
725
|
|
726 if ($max === null && $RCMAIL->action) {
|
|
727 $max = $RCMAIL->storage->count(null, $RCMAIL->storage->get_threading() ? 'THREADS' : 'ALL');
|
|
728 }
|
|
729
|
|
730 if (!$max) {
|
|
731 $out = $RCMAIL->storage->get_search_set() ? $RCMAIL->gettext('nomessages') : $RCMAIL->gettext('mailboxempty');
|
|
732 }
|
|
733 else {
|
|
734 $out = $RCMAIL->gettext(array('name' => $RCMAIL->storage->get_threading() ? 'threadsfromto' : 'messagesfromto',
|
|
735 'vars' => array('from' => $start_msg,
|
|
736 'to' => min($max, $start_msg + $page_size - 1),
|
|
737 'count' => $max)));
|
|
738 }
|
|
739
|
|
740 return rcube::Q($out);
|
|
741 }
|
|
742
|
|
743 function rcmail_mailbox_name_display($attrib)
|
|
744 {
|
|
745 global $RCMAIL;
|
|
746
|
|
747 if (!$attrib['id']) {
|
|
748 $attrib['id'] = 'rcmmailboxname';
|
|
749 }
|
|
750
|
|
751 $RCMAIL->output->add_gui_object('mailboxname', $attrib['id']);
|
|
752
|
|
753 return html::span($attrib, rcmail_get_mailbox_name_text());
|
|
754 }
|
|
755
|
|
756 function rcmail_get_mailbox_name_text()
|
|
757 {
|
|
758 global $RCMAIL;
|
|
759 return $RCMAIL->localize_foldername($RCMAIL->output->get_env('mailbox') ?: $RCMAIL->storage->get_folder());
|
|
760 }
|
|
761
|
|
762 function rcmail_send_unread_count($mbox_name, $force=false, $count=null, $mark='')
|
|
763 {
|
|
764 global $RCMAIL;
|
|
765
|
|
766 $old_unseen = rcmail_get_unseen_count($mbox_name);
|
|
767 $unseen = $count;
|
|
768
|
|
769 if ($unseen === null) {
|
|
770 $unseen = $RCMAIL->storage->count($mbox_name, 'UNSEEN', $force);
|
|
771 }
|
|
772
|
|
773 if ($unseen != $old_unseen || ($mbox_name == 'INBOX')) {
|
|
774 $RCMAIL->output->command('set_unread_count', $mbox_name, $unseen,
|
|
775 ($mbox_name == 'INBOX'), $unseen && $mark ? $mark : '');
|
|
776 }
|
|
777
|
|
778 rcmail_set_unseen_count($mbox_name, $unseen);
|
|
779
|
|
780 return $unseen;
|
|
781 }
|
|
782
|
|
783 function rcmail_set_unseen_count($mbox_name, $count)
|
|
784 {
|
|
785 // @TODO: this data is doubled (session and cache tables) if caching is enabled
|
|
786
|
|
787 // Make sure we have an array here (#1487066)
|
|
788 if (!is_array($_SESSION['unseen_count'])) {
|
|
789 $_SESSION['unseen_count'] = array();
|
|
790 }
|
|
791
|
|
792 $_SESSION['unseen_count'][$mbox_name] = $count;
|
|
793 }
|
|
794
|
|
795 function rcmail_get_unseen_count($mbox_name)
|
|
796 {
|
|
797 if (is_array($_SESSION['unseen_count']) && array_key_exists($mbox_name, $_SESSION['unseen_count'])) {
|
|
798 return $_SESSION['unseen_count'][$mbox_name];
|
|
799 }
|
|
800 }
|
|
801
|
|
802 /**
|
|
803 * Sets message is_safe flag according to 'show_images' option value
|
|
804 *
|
|
805 * @param object rcube_message Message
|
|
806 */
|
|
807 function rcmail_check_safe($message)
|
|
808 {
|
|
809 global $RCMAIL;
|
|
810
|
|
811 if (!$message->is_safe
|
|
812 && ($show_images = $RCMAIL->config->get('show_images'))
|
|
813 && $message->has_html_part()
|
|
814 ) {
|
|
815 switch ($show_images) {
|
|
816 case 1: // known senders only
|
|
817 // get default addressbook, like in addcontact.inc
|
|
818 $CONTACTS = $RCMAIL->get_address_book(-1, true);
|
|
819
|
|
820 if ($CONTACTS && $message->sender['mailto']) {
|
|
821 $result = $CONTACTS->search('email', $message->sender['mailto'], 1, false);
|
|
822 if ($result->count) {
|
|
823 $message->set_safe(true);
|
|
824 }
|
|
825 }
|
|
826
|
|
827 $RCMAIL->plugins->exec_hook('message_check_safe', array('message' => $message));
|
|
828 break;
|
|
829
|
|
830 case 2: // always
|
|
831 $message->set_safe(true);
|
|
832 break;
|
|
833 }
|
|
834 }
|
|
835
|
|
836 return !empty($message->is_safe);
|
|
837 }
|
|
838
|
|
839 /**
|
|
840 * Cleans up the given message HTML Body (for displaying)
|
|
841 *
|
|
842 * @param string HTML
|
|
843 * @param array Display parameters
|
|
844 * @param array CID map replaces (inline images)
|
|
845 * @return string Clean HTML
|
|
846 */
|
|
847 function rcmail_wash_html($html, $p, $cid_replaces = array())
|
|
848 {
|
|
849 global $REMOTE_OBJECTS;
|
|
850
|
|
851 $p += array('safe' => false, 'inline_html' => true);
|
|
852
|
|
853 // charset was converted to UTF-8 in rcube_storage::get_message_part(),
|
|
854 // change/add charset specification in HTML accordingly,
|
|
855 // washtml cannot work without that
|
|
856 $meta = '<meta http-equiv="Content-Type" content="text/html; charset='.RCUBE_CHARSET.'" />';
|
|
857
|
|
858 // remove old meta tag and add the new one, making sure
|
|
859 // that it is placed in the head (#1488093)
|
|
860 $html = preg_replace('/<meta[^>]+charset=[a-z0-9-_]+[^>]*>/Ui', '', $html);
|
|
861 $html = preg_replace('/(<head[^>]*>)/Ui', '\\1'.$meta, $html, -1, $rcount);
|
|
862 if (!$rcount) {
|
|
863 $html = '<head>' . $meta . '</head>' . $html;
|
|
864 }
|
|
865
|
|
866 // clean HTML with washhtml by Frederic Motte
|
|
867 $wash_opts = array(
|
|
868 'show_washed' => false,
|
|
869 'allow_remote' => $p['safe'],
|
|
870 'blocked_src' => 'program/resources/blocked.gif',
|
|
871 'charset' => RCUBE_CHARSET,
|
|
872 'cid_map' => $cid_replaces,
|
|
873 'html_elements' => array('body'),
|
|
874 );
|
|
875
|
|
876 if (!$p['inline_html']) {
|
|
877 $wash_opts['html_elements'] = array('html','head','title','body');
|
|
878 }
|
|
879 if ($p['safe']) {
|
|
880 $wash_opts['html_elements'][] = 'link';
|
|
881 $wash_opts['html_attribs'] = array('rel','type');
|
|
882 }
|
|
883
|
|
884 // overwrite washer options with options from plugins
|
|
885 if (isset($p['html_elements']))
|
|
886 $wash_opts['html_elements'] = $p['html_elements'];
|
|
887 if (isset($p['html_attribs']))
|
|
888 $wash_opts['html_attribs'] = $p['html_attribs'];
|
|
889
|
|
890 // initialize HTML washer
|
|
891 $washer = new rcube_washtml($wash_opts);
|
|
892
|
|
893 if (!$p['skip_washer_form_callback']) {
|
|
894 $washer->add_callback('form', 'rcmail_washtml_callback');
|
|
895 }
|
|
896
|
|
897 // allow CSS styles, will be sanitized by rcmail_washtml_callback()
|
|
898 if (!$p['skip_washer_style_callback']) {
|
|
899 $washer->add_callback('style', 'rcmail_washtml_callback');
|
|
900 }
|
|
901
|
|
902 // modify HTML links to open a new window if clicked
|
|
903 if (!$p['skip_washer_link_callback']) {
|
|
904 $washer->add_callback('a', 'rcmail_washtml_link_callback');
|
|
905 $washer->add_callback('area', 'rcmail_washtml_link_callback');
|
|
906
|
|
907 if ($p['safe'])
|
|
908 $washer->add_callback('link', 'rcmail_washtml_link_callback');
|
|
909 }
|
|
910
|
|
911 // Remove non-UTF8 characters (#1487813)
|
|
912 $html = rcube_charset::clean($html);
|
|
913
|
|
914 $html = $washer->wash($html);
|
|
915 $REMOTE_OBJECTS = $washer->extlinks;
|
|
916
|
|
917 return $html;
|
|
918 }
|
|
919
|
|
920 /**
|
|
921 * Convert the given message part to proper HTML
|
|
922 * which can be displayed the message view
|
|
923 *
|
|
924 * @param string Message part body
|
|
925 * @param rcube_message_part Message part
|
|
926 * @param array Display parameters array
|
|
927 *
|
|
928 * @return string Formatted HTML string
|
|
929 */
|
|
930 function rcmail_print_body($body, $part, $p = array())
|
|
931 {
|
|
932 global $RCMAIL;
|
|
933
|
|
934 // trigger plugin hook
|
|
935 $data = $RCMAIL->plugins->exec_hook('message_part_before',
|
|
936 array('type' => $part->ctype_secondary, 'body' => $body, 'id' => $part->mime_id)
|
|
937 + $p + array('safe' => false, 'plain' => false, 'inline_html' => true));
|
|
938
|
|
939 // convert html to text/plain
|
|
940 if ($data['plain'] && ($data['type'] == 'html' || $data['type'] == 'enriched')) {
|
|
941 if ($data['type'] == 'enriched') {
|
|
942 $data['body'] = rcube_enriched::to_html($data['body']);
|
|
943 }
|
|
944
|
|
945 $body = $RCMAIL->html2text($data['body']);
|
|
946 $part->ctype_secondary = 'plain';
|
|
947 }
|
|
948 // text/html
|
|
949 else if ($data['type'] == 'html') {
|
|
950 $body = rcmail_wash_html($data['body'], $data, $part->replaces);
|
|
951 $part->ctype_secondary = $data['type'];
|
|
952 }
|
|
953 // text/enriched
|
|
954 else if ($data['type'] == 'enriched') {
|
|
955 $body = rcube_enriched::to_html($data['body']);
|
|
956 $body = rcmail_wash_html($body, $data, $part->replaces);
|
|
957 $part->ctype_secondary = 'html';
|
|
958 }
|
|
959 else {
|
|
960 // assert plaintext
|
|
961 $body = $data['body'];
|
|
962 $part->ctype_secondary = $data['type'] = 'plain';
|
|
963 }
|
|
964
|
|
965 // free some memory (hopefully)
|
|
966 unset($data['body']);
|
|
967
|
|
968 // plaintext postprocessing
|
|
969 if ($part->ctype_secondary == 'plain') {
|
|
970 $flowed = $part->ctype_parameters['format'] == 'flowed';
|
|
971 $delsp = $part->ctype_parameters['delsp'] == 'yes';
|
|
972 $body = rcmail_plain_body($body, $flowed, $delsp);
|
|
973 }
|
|
974
|
|
975 // allow post-processing of the message body
|
|
976 $data = $RCMAIL->plugins->exec_hook('message_part_after',
|
|
977 array('type' => $part->ctype_secondary, 'body' => $body, 'id' => $part->mime_id) + $data);
|
|
978
|
|
979 return $data['body'];
|
|
980 }
|
|
981
|
|
982 /**
|
|
983 * Handle links and citation marks in plain text message
|
|
984 *
|
|
985 * @param string Plain text string
|
|
986 * @param boolean Set to True if the source text is in format=flowed
|
|
987 *
|
|
988 * @return string Formatted HTML string
|
|
989 */
|
|
990 function rcmail_plain_body($body, $flowed = false, $delsp = false)
|
|
991 {
|
|
992 $options = array('flowed' => $flowed, 'wrap' => !$flowed, 'replacer' => 'rcmail_string_replacer',
|
|
993 'delsp' => $delsp);
|
|
994 $text2html = new rcube_text2html($body, false, $options);
|
|
995 $body = $text2html->get_html();
|
|
996
|
|
997 return $body;
|
|
998 }
|
|
999
|
|
1000 /**
|
|
1001 * Callback function for washtml cleaning class
|
|
1002 */
|
|
1003 function rcmail_washtml_callback($tagname, $attrib, $content, $washtml)
|
|
1004 {
|
|
1005 switch ($tagname) {
|
|
1006 case 'form':
|
|
1007 $out = html::div('form', $content);
|
|
1008 break;
|
|
1009
|
|
1010 case 'style':
|
|
1011 // Crazy big styles may freeze the browser (#1490539)
|
|
1012 // remove content with more than 5k lines
|
|
1013 if (substr_count($content, "\n") > 5000) {
|
|
1014 $out = '';
|
|
1015 break;
|
|
1016 }
|
|
1017
|
|
1018 // decode all escaped entities and reduce to ascii strings
|
|
1019 $stripped = preg_replace('/[^a-zA-Z\(:;]/', '', rcube_utils::xss_entity_decode($content));
|
|
1020
|
|
1021 // now check for evil strings like expression, behavior or url()
|
|
1022 if (!preg_match('/expression|behavior|javascript:|import[^a]/i', $stripped)) {
|
|
1023 if (!$washtml->get_config('allow_remote') && preg_match('/url\((?!data:image)/', $stripped)) {
|
|
1024 $washtml->extlinks = true;
|
|
1025 }
|
|
1026 else {
|
|
1027 $out = html::tag('style', array('type' => 'text/css'), $content);
|
|
1028 }
|
|
1029 break;
|
|
1030 }
|
|
1031
|
|
1032 default:
|
|
1033 $out = '';
|
|
1034 }
|
|
1035
|
|
1036 return $out;
|
|
1037 }
|
|
1038
|
|
1039 /**
|
|
1040 * return table with message headers
|
|
1041 */
|
|
1042 function rcmail_message_headers($attrib, $headers=null)
|
|
1043 {
|
|
1044 global $MESSAGE, $PRINT_MODE, $RCMAIL;
|
|
1045 static $sa_attrib;
|
|
1046
|
|
1047 // keep header table attrib
|
|
1048 if (is_array($attrib) && !$sa_attrib && !$attrib['valueof']) {
|
|
1049 $sa_attrib = $attrib;
|
|
1050 }
|
|
1051 else if (!is_array($attrib) && is_array($sa_attrib)) {
|
|
1052 $attrib = $sa_attrib;
|
|
1053 }
|
|
1054
|
|
1055 if (!isset($MESSAGE)) {
|
|
1056 return false;
|
|
1057 }
|
|
1058
|
|
1059 // get associative array of headers object
|
|
1060 if (!$headers) {
|
|
1061 $headers_obj = $MESSAGE->headers;
|
|
1062 $headers = get_object_vars($MESSAGE->headers);
|
|
1063 }
|
|
1064 else if (is_object($headers)) {
|
|
1065 $headers_obj = $headers;
|
|
1066 $headers = get_object_vars($headers_obj);
|
|
1067 }
|
|
1068 else {
|
|
1069 $headers_obj = rcube_message_header::from_array($headers);
|
|
1070 }
|
|
1071
|
|
1072 // show these headers
|
|
1073 $standard_headers = array('subject', 'from', 'sender', 'to', 'cc', 'bcc', 'replyto',
|
|
1074 'mail-reply-to', 'mail-followup-to', 'date', 'priority');
|
|
1075 $exclude_headers = $attrib['exclude'] ? explode(',', $attrib['exclude']) : array();
|
|
1076 $output_headers = array();
|
|
1077
|
|
1078 foreach ($standard_headers as $hkey) {
|
|
1079 if ($headers[$hkey])
|
|
1080 $value = $headers[$hkey];
|
|
1081 else if ($headers['others'][$hkey])
|
|
1082 $value = $headers['others'][$hkey];
|
|
1083 else if (!$attrib['valueof'])
|
|
1084 continue;
|
|
1085
|
|
1086 if (in_array($hkey, $exclude_headers))
|
|
1087 continue;
|
|
1088
|
|
1089 $ishtml = false;
|
|
1090 $header_title = $RCMAIL->gettext(preg_replace('/(^mail-|-)/', '', $hkey));
|
|
1091
|
|
1092 if ($hkey == 'date') {
|
|
1093 if ($PRINT_MODE)
|
|
1094 $header_value = $RCMAIL->format_date($value, $RCMAIL->config->get('date_long', 'x'));
|
|
1095 else
|
|
1096 $header_value = $RCMAIL->format_date($value);
|
|
1097 }
|
|
1098 else if ($hkey == 'priority') {
|
|
1099 if ($value) {
|
|
1100 $header_value = html::span('prio' . $value, rcube::Q(rcmail_localized_priority($value)));
|
|
1101 $ishtml = true;
|
|
1102 }
|
|
1103 else {
|
|
1104 continue;
|
|
1105 }
|
|
1106 }
|
|
1107 else if ($hkey == 'replyto') {
|
|
1108 if ($headers['replyto'] != $headers['from']) {
|
|
1109 $header_value = rcmail_address_string($value, $attrib['max'], true,
|
|
1110 $attrib['addicon'], $headers['charset'], $header_title);
|
|
1111 $ishtml = true;
|
|
1112 }
|
|
1113 else {
|
|
1114 continue;
|
|
1115 }
|
|
1116 }
|
|
1117 else if ($hkey == 'mail-reply-to') {
|
|
1118 if ($headers['mail-replyto'] != $headers['replyto']
|
|
1119 && $headers['replyto'] != $headers['from']
|
|
1120 ) {
|
|
1121 $header_value = rcmail_address_string($value, $attrib['max'], true,
|
|
1122 $attrib['addicon'], $headers['charset'], $header_title);
|
|
1123 $ishtml = true;
|
|
1124 }
|
|
1125 else {
|
|
1126 continue;
|
|
1127 }
|
|
1128 }
|
|
1129 else if ($hkey == 'sender') {
|
|
1130 if ($headers['sender'] != $headers['from']) {
|
|
1131 $header_value = rcmail_address_string($value, $attrib['max'], true,
|
|
1132 $attrib['addicon'], $headers['charset'], $header_title);
|
|
1133 $ishtml = true;
|
|
1134 }
|
|
1135 else {
|
|
1136 continue;
|
|
1137 }
|
|
1138 }
|
|
1139 else if ($hkey == 'mail-followup-to') {
|
|
1140 $header_value = rcmail_address_string($value, $attrib['max'], true,
|
|
1141 $attrib['addicon'], $headers['charset'], $header_title);
|
|
1142 $ishtml = true;
|
|
1143 }
|
|
1144 else if (in_array($hkey, array('from', 'to', 'cc', 'bcc'))) {
|
|
1145 $header_value = rcmail_address_string($value, $attrib['max'], true,
|
|
1146 $attrib['addicon'], $headers['charset'], $header_title);
|
|
1147 $ishtml = true;
|
|
1148 }
|
|
1149 else if ($hkey == 'subject' && empty($value)) {
|
|
1150 $header_value = $RCMAIL->gettext('nosubject');
|
|
1151 }
|
|
1152 else {
|
|
1153 $value = is_array($value) ? implode(' ', $value) : $value;
|
|
1154 $header_value = trim(rcube_mime::decode_header($value, $headers['charset']));
|
|
1155 }
|
|
1156
|
|
1157 $output_headers[$hkey] = array(
|
|
1158 'title' => $header_title,
|
|
1159 'value' => $header_value,
|
|
1160 'raw' => $value,
|
|
1161 'html' => $ishtml,
|
|
1162 );
|
|
1163 }
|
|
1164
|
|
1165 $plugin = $RCMAIL->plugins->exec_hook('message_headers_output', array(
|
|
1166 'output' => $output_headers,
|
|
1167 'headers' => $headers_obj,
|
|
1168 'exclude' => $exclude_headers, // readonly
|
|
1169 'folder' => $MESSAGE->folder, // readonly
|
|
1170 'uid' => $MESSAGE->uid, // readonly
|
|
1171 ));
|
|
1172
|
|
1173 // single header value is requested
|
|
1174 if (!empty($attrib['valueof'])) {
|
|
1175 $row = $plugin['output'][$attrib['valueof']];
|
|
1176 return $row['html'] ? $row['value'] : rcube::Q($row['value']);
|
|
1177 }
|
|
1178
|
|
1179 // compose html table
|
|
1180 $table = new html_table(array('cols' => 2));
|
|
1181
|
|
1182 foreach ($plugin['output'] as $hkey => $row) {
|
|
1183 $val = $row['html'] ? $row['value'] : rcube::Q($row['value']);
|
|
1184
|
|
1185 $table->add(array('class' => 'header-title'), rcube::Q($row['title']));
|
|
1186 $table->add(array('class' => 'header '.$hkey), $val);
|
|
1187 }
|
|
1188
|
|
1189 return $table->show($attrib);
|
|
1190 }
|
|
1191
|
|
1192 /**
|
|
1193 * Convert Priority header value into a localized string
|
|
1194 */
|
|
1195 function rcmail_localized_priority($value)
|
|
1196 {
|
|
1197 global $RCMAIL;
|
|
1198
|
|
1199 $labels_map = array(
|
|
1200 '1' => 'highest',
|
|
1201 '2' => 'high',
|
|
1202 '3' => 'normal',
|
|
1203 '4' => 'low',
|
|
1204 '5' => 'lowest',
|
|
1205 );
|
|
1206
|
|
1207 if ($value && $labels_map[$value]) {
|
|
1208 return $RCMAIL->gettext($labels_map[$value]);
|
|
1209 }
|
|
1210
|
|
1211 return '';
|
|
1212 }
|
|
1213
|
|
1214 /**
|
|
1215 * return block to show full message headers
|
|
1216 */
|
|
1217 function rcmail_message_full_headers($attrib)
|
|
1218 {
|
|
1219 global $OUTPUT, $RCMAIL;
|
|
1220
|
|
1221 $html = html::div(array('id' => "all-headers", 'class' => "all", 'style' => 'display:none'), html::div(array('id' => 'headers-source'), ''));
|
|
1222 $html .= html::div(array(
|
|
1223 'class' => "more-headers show-headers",
|
|
1224 'onclick' => "return ".rcmail_output::JS_OBJECT_NAME.".command('show-headers','',this)",
|
|
1225 'title' => $RCMAIL->gettext('togglefullheaders')
|
|
1226 ), '');
|
|
1227
|
|
1228 $OUTPUT->add_gui_object('all_headers_row', 'all-headers');
|
|
1229 $OUTPUT->add_gui_object('all_headers_box', 'headers-source');
|
|
1230
|
|
1231 return html::div($attrib, $html);
|
|
1232 }
|
|
1233
|
|
1234 /**
|
|
1235 * Handler for the 'messagebody' GUI object
|
|
1236 *
|
|
1237 * @param array Named parameters
|
|
1238 * @return string HTML content showing the message body
|
|
1239 */
|
|
1240 function rcmail_message_body($attrib)
|
|
1241 {
|
|
1242 global $OUTPUT, $MESSAGE, $RCMAIL, $REMOTE_OBJECTS;
|
|
1243
|
|
1244 if (!is_array($MESSAGE->parts) && empty($MESSAGE->body)) {
|
|
1245 return '';
|
|
1246 }
|
|
1247
|
|
1248 if (!$attrib['id'])
|
|
1249 $attrib['id'] = 'rcmailMsgBody';
|
|
1250
|
|
1251 $safe_mode = $MESSAGE->is_safe || intval($_GET['_safe']);
|
|
1252 $out = '';
|
|
1253 $part_no = 0;
|
|
1254
|
|
1255 $header_attrib = array();
|
|
1256 foreach ($attrib as $attr => $value) {
|
|
1257 if (preg_match('/^headertable([a-z]+)$/i', $attr, $regs)) {
|
|
1258 $header_attrib[$regs[1]] = $value;
|
|
1259 }
|
|
1260 }
|
|
1261
|
|
1262 if (!empty($MESSAGE->parts)) {
|
|
1263 foreach ($MESSAGE->parts as $part) {
|
|
1264 if ($part->type == 'headers') {
|
|
1265 $out .= html::div('message-partheaders', rcmail_message_headers(count($header_attrib) ? $header_attrib : null, $part->headers));
|
|
1266 }
|
|
1267 else if ($part->type == 'content') {
|
|
1268 // unsupported (e.g. encrypted)
|
|
1269 if ($part->realtype) {
|
|
1270 if ($part->realtype == 'multipart/encrypted' || $part->realtype == 'application/pkcs7-mime') {
|
|
1271 if (!empty($_SESSION['browser_caps']['pgpmime']) && ($pgp_mime_part = $MESSAGE->get_multipart_encrypted_part())) {
|
|
1272 $out .= html::span('part-notice', $RCMAIL->gettext('externalmessagedecryption'));
|
|
1273 $OUTPUT->set_env('pgp_mime_part', $pgp_mime_part->mime_id);
|
|
1274 $OUTPUT->set_env('pgp_mime_container', '#' . $attrib['id']);
|
|
1275 $OUTPUT->add_label('loadingdata');
|
|
1276 }
|
|
1277
|
|
1278 if (!$MESSAGE->encrypted_part) {
|
|
1279 $out .= html::span('part-notice', $RCMAIL->gettext('encryptedmessage'));
|
|
1280 }
|
|
1281 }
|
|
1282 continue;
|
|
1283 }
|
|
1284 else if (!$part->size) {
|
|
1285 continue;
|
|
1286 }
|
|
1287
|
|
1288 // Check if we have enough memory to handle the message in it
|
|
1289 // #1487424: we need up to 10x more memory than the body
|
|
1290 else if (!rcube_utils::mem_check($part->size * 10)) {
|
|
1291 $out .= html::span('part-notice', $RCMAIL->gettext('messagetoobig'). ' '
|
|
1292 . html::a('?_task=mail&_action=get&_download=1&_uid='.$MESSAGE->uid.'&_part='.$part->mime_id
|
|
1293 .'&_mbox='. urlencode($MESSAGE->folder), $RCMAIL->gettext('download')));
|
|
1294 continue;
|
|
1295 }
|
|
1296
|
|
1297 // fetch part body
|
|
1298 $body = $MESSAGE->get_part_body($part->mime_id, true);
|
|
1299
|
|
1300 // message is cached but not exists (#1485443), or other error
|
|
1301 if ($body === false) {
|
|
1302 rcmail_message_error($MESSAGE->uid);
|
|
1303 }
|
|
1304
|
|
1305 $plugin = $RCMAIL->plugins->exec_hook('message_body_prefix',
|
|
1306 array('part' => $part, 'prefix' => ''));
|
|
1307
|
|
1308 // Set attributes of the part container
|
|
1309 $container_class = $part->ctype_secondary == 'html' ? 'message-htmlpart' : 'message-part';
|
|
1310 $container_id = $container_class . (++$part_no);
|
|
1311 $container_attrib = array('class' => $container_class, 'id' => $container_id);
|
|
1312
|
|
1313 // Assign container ID to a global variable for use in rcmail_washtml_link_callback()
|
|
1314 $GLOBALS['rcmail_html_container_id'] = $container_id;
|
|
1315
|
|
1316 // Parse the part content for display
|
|
1317 $body = rcmail_print_body($body, $part, array('safe' => $safe_mode, 'plain' => !$RCMAIL->config->get('prefer_html')));
|
|
1318
|
|
1319 // check if the message body is PGP encrypted
|
|
1320 if (strpos($body, '-----BEGIN PGP MESSAGE-----') !== false) {
|
|
1321 $OUTPUT->set_env('is_pgp_content', '#' . $container_id);
|
|
1322 }
|
|
1323
|
|
1324 if ($part->ctype_secondary == 'html') {
|
|
1325 $body = rcmail_html4inline($body, $container_id, 'rcmBody', $container_attrib, $safe_mode);
|
|
1326 }
|
|
1327
|
|
1328 $out .= html::div($container_attrib, $plugin['prefix'] . $body);
|
|
1329 }
|
|
1330 }
|
|
1331 }
|
|
1332 else {
|
|
1333 // Check if we have enough memory to handle the message in it
|
|
1334 // #1487424: we need up to 10x more memory than the body
|
|
1335 if (!rcube_utils::mem_check(strlen($MESSAGE->body) * 10)) {
|
|
1336 $out .= html::span('part-notice', $RCMAIL->gettext('messagetoobig'). ' '
|
|
1337 . html::a('?_task=mail&_action=get&_download=1&_uid='.$MESSAGE->uid.'&_part=0'
|
|
1338 .'&_mbox='. urlencode($MESSAGE->folder), $RCMAIL->gettext('download')));
|
|
1339 }
|
|
1340 else {
|
|
1341 $plugin = $RCMAIL->plugins->exec_hook('message_body_prefix',
|
|
1342 array('part' => $MESSAGE, 'prefix' => ''));
|
|
1343
|
|
1344 $out .= html::div('message-part',
|
|
1345 $plugin['prefix'] . rcmail_plain_body($MESSAGE->body));
|
|
1346 }
|
|
1347 }
|
|
1348
|
|
1349 // list images after mail body
|
|
1350 if ($RCMAIL->config->get('inline_images', true) && !empty($MESSAGE->attachments)) {
|
|
1351 $thumbnail_size = $RCMAIL->config->get('image_thumbnail_size', 240);
|
|
1352 $client_mimetypes = (array)$RCMAIL->config->get('client_mimetypes');
|
|
1353
|
|
1354 foreach ($MESSAGE->attachments as $attach_prop) {
|
|
1355 // skip inline images
|
|
1356 if ($attach_prop->content_id && $attach_prop->disposition == 'inline') {
|
|
1357 continue;
|
|
1358 }
|
|
1359
|
|
1360 // Content-Type: image/*...
|
|
1361 if ($mimetype = rcmail_part_image_type($attach_prop)) {
|
|
1362 // display thumbnails
|
|
1363 if ($thumbnail_size) {
|
|
1364 $supported = in_array($mimetype, $client_mimetypes);
|
|
1365 $show_link = array(
|
|
1366 'href' => $MESSAGE->get_part_url($attach_prop->mime_id, false),
|
|
1367 'onclick' => sprintf(
|
|
1368 'return %s.command(\'load-attachment\',\'%s\',this)',
|
|
1369 rcmail_output::JS_OBJECT_NAME,
|
|
1370 $attach_prop->mime_id)
|
|
1371 );
|
|
1372
|
|
1373 $out .= html::p(array('class' => 'image-attachment', 'style' => $supported ? '' : 'display:none'),
|
|
1374 html::a($show_link + array('class' => 'image-link', 'style' => sprintf('width:%dpx', $thumbnail_size)),
|
|
1375 html::img(array(
|
|
1376 'class' => 'image-thumbnail',
|
|
1377 'src' => $MESSAGE->get_part_url($attach_prop->mime_id, 'image') . '&_thumb=1',
|
|
1378 'title' => $attach_prop->filename,
|
|
1379 'alt' => $attach_prop->filename,
|
|
1380 'style' => sprintf('max-width:%dpx; max-height:%dpx', $thumbnail_size, $thumbnail_size),
|
|
1381 'onload' => $supported ? '' : '$(this).parents(\'p.image-attachment\').show()',
|
|
1382 ))
|
|
1383 ) .
|
|
1384 html::span('image-filename', rcube::Q($attach_prop->filename)) .
|
|
1385 html::span('image-filesize', rcube::Q($RCMAIL->message_part_size($attach_prop))) .
|
|
1386 html::span('attachment-links',
|
|
1387 ($supported ? html::a($show_link, $RCMAIL->gettext('showattachment')) . ' ' : '') .
|
|
1388 html::a($show_link['href'] . '&_download=1', $RCMAIL->gettext('download'))
|
|
1389 ) .
|
|
1390 html::br(array('style' => 'clear:both'))
|
|
1391 );
|
|
1392 }
|
|
1393 else {
|
|
1394 $out .= html::tag('fieldset', 'image-attachment',
|
|
1395 html::tag('legend', 'image-filename', rcube::Q($attach_prop->filename)) .
|
|
1396 html::p(array('align' => 'center'),
|
|
1397 html::img(array(
|
|
1398 'src' => $MESSAGE->get_part_url($attach_prop->mime_id, 'image'),
|
|
1399 'title' => $attach_prop->filename,
|
|
1400 'alt' => $attach_prop->filename,
|
|
1401 )))
|
|
1402 );
|
|
1403 }
|
|
1404 }
|
|
1405 }
|
|
1406 }
|
|
1407
|
|
1408 // tell client that there are blocked remote objects
|
|
1409 if ($REMOTE_OBJECTS && !$safe_mode) {
|
|
1410 $OUTPUT->set_env('blockedobjects', true);
|
|
1411 }
|
|
1412
|
|
1413 return html::div($attrib, $out);
|
|
1414 }
|
|
1415
|
|
1416 function rcmail_part_image_type($part)
|
|
1417 {
|
|
1418 $mimetype = strtolower($part->mimetype);
|
|
1419
|
|
1420 // Skip TIFF/WEBP images if browser doesn't support this format
|
|
1421 // ...until we can convert them to JPEG
|
|
1422 $tiff_support = !empty($_SESSION['browser_caps']) && !empty($_SESSION['browser_caps']['tiff']);
|
|
1423 $tiff_support = $tiff_support || rcube_image::is_convertable('image/tiff');
|
|
1424 $webp_support = !empty($_SESSION['browser_caps']) && !empty($_SESSION['browser_caps']['webp']);
|
|
1425 $webp_support = $webp_support || rcube_image::is_convertable('image/webp');
|
|
1426
|
|
1427 if ((!$tiff_support && $mimetype == 'image/tiff') || (!$webp_support && $mimetype == 'image/webp')) {
|
|
1428 return;
|
|
1429 }
|
|
1430
|
|
1431 // Content-Type: image/*...
|
|
1432 if (strpos($mimetype, 'image/') === 0) {
|
|
1433 return rcmail_fix_mimetype($mimetype);
|
|
1434 }
|
|
1435
|
|
1436 // Many clients use application/octet-stream, we'll detect mimetype
|
|
1437 // by checking filename extension
|
|
1438
|
|
1439 // Supported image filename extensions to image type map
|
|
1440 $types = array(
|
|
1441 'jpg' => 'image/jpeg',
|
|
1442 'jpeg' => 'image/jpeg',
|
|
1443 'png' => 'image/png',
|
|
1444 'gif' => 'image/gif',
|
|
1445 'bmp' => 'image/bmp',
|
|
1446 );
|
|
1447 if ($tiff_support) {
|
|
1448 $types['tif'] = 'image/tiff';
|
|
1449 $types['tiff'] = 'image/tiff';
|
|
1450 }
|
|
1451 if ($webp_support) {
|
|
1452 $types['webp'] = 'image/webp';
|
|
1453 }
|
|
1454
|
|
1455 if ($part->filename
|
|
1456 && $mimetype == 'application/octet-stream'
|
|
1457 && preg_match('/\.([^.]+)$/i', $part->filename, $m)
|
|
1458 && ($extension = strtolower($m[1]))
|
|
1459 && isset($types[$extension])
|
|
1460 ) {
|
|
1461 return $types[$extension];
|
|
1462 }
|
|
1463 }
|
|
1464
|
|
1465 /**
|
|
1466 * Modify a HTML message that it can be displayed inside a HTML page
|
|
1467 */
|
|
1468 function rcmail_html4inline($body, $container_id, $body_class='', &$attributes=array(), $allow_remote=false)
|
|
1469 {
|
|
1470 $last_style_pos = 0;
|
|
1471 $cont_id = $container_id . ($body_class ? ' div.'.$body_class : '');
|
|
1472
|
|
1473 // find STYLE tags
|
|
1474 while (($pos = stripos($body, '<style', $last_style_pos)) && ($pos2 = stripos($body, '</style>', $pos))) {
|
|
1475 $pos = strpos($body, '>', $pos) + 1;
|
|
1476 $len = $pos2 - $pos;
|
|
1477
|
|
1478 // replace all css definitions with #container [def]
|
|
1479 $styles = substr($body, $pos, $len);
|
|
1480 $styles = rcube_utils::mod_css_styles($styles, $cont_id, $allow_remote);
|
|
1481
|
|
1482 $body = substr_replace($body, $styles, $pos, $len);
|
|
1483 $last_style_pos = $pos2 + strlen($styles) - $len;
|
|
1484 }
|
|
1485
|
|
1486 $body = preg_replace(array(
|
|
1487 // add comments around html and other tags
|
|
1488 '/(<!DOCTYPE[^>]*>)/i',
|
|
1489 '/(<\?xml[^>]*>)/i',
|
|
1490 '/(<\/?html[^>]*>)/i',
|
|
1491 '/(<\/?head[^>]*>)/i',
|
|
1492 '/(<title[^>]*>.*<\/title>)/Ui',
|
|
1493 '/(<\/?meta[^>]*>)/i',
|
|
1494 // quote <? of php and xml files that are specified as text/html
|
|
1495 '/<\?/',
|
|
1496 '/\?>/',
|
|
1497 // replace <body> with <div>
|
|
1498 '/<body([^>]*)>/i',
|
|
1499 '/<\/body>/i',
|
|
1500 ),
|
|
1501 array(
|
|
1502 '<!--\\1-->',
|
|
1503 '<!--\\1-->',
|
|
1504 '<!--\\1-->',
|
|
1505 '<!--\\1-->',
|
|
1506 '<!--\\1-->',
|
|
1507 '<!--\\1-->',
|
|
1508 '<?',
|
|
1509 '?>',
|
|
1510 '<div class="' . $body_class . '"\\1>',
|
|
1511 '</div>',
|
|
1512 ),
|
|
1513 $body);
|
|
1514
|
|
1515 // Handle body attributes that doesn't play nicely with div elements
|
|
1516 $regexp = '/<div class="' . preg_quote($body_class, '/') . '"([^>]*)/';
|
|
1517 if (preg_match($regexp, $body, $m)) {
|
|
1518 $style = array();
|
|
1519 $attrs = $m[0];
|
|
1520
|
|
1521 // Get bgcolor, we'll set it as background-color of the message container
|
|
1522 if ($m[1] && preg_match('/bgcolor=["\']*([a-z0-9#]+)["\']*/i', $attrs, $mb)) {
|
|
1523 $style['background-color'] = $mb[1];
|
|
1524 $attrs = preg_replace('/bgcolor=["\']*[a-z0-9#]+["\']*/i', '', $attrs);
|
|
1525 }
|
|
1526
|
|
1527 // Get background, we'll set it as background-image of the message container
|
|
1528 if ($m[1] && preg_match('/background=["\']*([^"\'>\s]+)["\']*/', $attrs, $mb)) {
|
|
1529 $style['background-image'] = 'url('.$mb[1].')';
|
|
1530 $attrs = preg_replace('/background=["\']*([^"\'>\s]+)["\']*/', '', $attrs);
|
|
1531 }
|
|
1532
|
|
1533 if (!empty($style)) {
|
|
1534 $body = preg_replace($regexp, rtrim($attrs), $body, 1);
|
|
1535 }
|
|
1536
|
|
1537 // handle body styles related to background image
|
|
1538 if ($style['background-image']) {
|
|
1539 // get body style
|
|
1540 if (preg_match('/#'.preg_quote($cont_id, '/').'\s+\{([^}]+)}/i', $body, $m)) {
|
|
1541 // get background related style
|
|
1542 $regexp = '/(background-position|background-repeat)\s*:\s*([^;]+);/i';
|
|
1543 if (preg_match_all($regexp, $m[1], $matches, PREG_SET_ORDER)) {
|
|
1544 foreach ($matches as $m) {
|
|
1545 $style[$m[1]] = $m[2];
|
|
1546 }
|
|
1547 }
|
|
1548 }
|
|
1549 }
|
|
1550
|
|
1551 if (!empty($style)) {
|
|
1552 foreach ($style as $idx => $val) {
|
|
1553 $style[$idx] = $idx . ': ' . $val;
|
|
1554 }
|
|
1555
|
|
1556 $attributes['style'] = implode('; ', $style);
|
|
1557 }
|
|
1558 }
|
|
1559 // make sure there's 'rcmBody' div, we need it for proper css modification
|
|
1560 // its name is hardcoded in rcmail_message_body() also
|
|
1561 else {
|
|
1562 $body = '<div class="' . $body_class . '">' . $body . '</div>';
|
|
1563 }
|
|
1564
|
|
1565 return $body;
|
|
1566 }
|
|
1567
|
|
1568 /**
|
|
1569 * Parse link (a, link, area) attributes and set correct target
|
|
1570 */
|
|
1571 function rcmail_washtml_link_callback($tag, $attribs, $content, $washtml)
|
|
1572 {
|
|
1573 global $RCMAIL;
|
|
1574
|
|
1575 $attrib = html::parse_attrib_string($attribs);
|
|
1576
|
|
1577 // Remove non-printable characters in URL (#1487805)
|
|
1578 if ($attrib['href']) {
|
|
1579 $attrib['href'] = preg_replace('/[\x00-\x1F]/', '', $attrib['href']);
|
|
1580 }
|
|
1581
|
|
1582 if ($tag == 'link' && preg_match('/^https?:\/\//i', $attrib['href'])) {
|
|
1583 $tempurl = 'tmp-' . md5($attrib['href']) . '.css';
|
|
1584 $_SESSION['modcssurls'][$tempurl] = $attrib['href'];
|
|
1585 $attrib['href'] = $RCMAIL->url(array('task' => 'utils', 'action' => 'modcss', 'u' => $tempurl, 'c' => $GLOBALS['rcmail_html_container_id']));
|
|
1586 $end = ' />';
|
|
1587 }
|
|
1588 else if (preg_match('/^mailto:(.+)/i', $attrib['href'], $mailto)) {
|
|
1589 list($mailto, $url) = explode('?', html_entity_decode($mailto[1], ENT_QUOTES, 'UTF-8'), 2);
|
|
1590
|
|
1591 // #6020: use raw encoding for correct "+" character handling as specified in RFC6068
|
|
1592 $url = rawurldecode($url);
|
|
1593 $mailto = rawurldecode($mailto);
|
|
1594 $addresses = rcube_mime::decode_address_list($mailto, null, true);
|
|
1595 $mailto = array();
|
|
1596
|
|
1597 // do sanity checks on recipients
|
|
1598 foreach ($addresses as $idx => $addr) {
|
|
1599 if (rcube_utils::check_email($addr['mailto'], false)) {
|
|
1600 $addresses[$idx] = $addr['mailto'];
|
|
1601 $mailto[] = $addr['string'];
|
|
1602 }
|
|
1603 else {
|
|
1604 unset($addresses[$idx]);
|
|
1605 }
|
|
1606 }
|
|
1607
|
|
1608 if (!empty($addresses)) {
|
|
1609 $attrib['href'] = 'mailto:' . implode(',', $addresses);
|
|
1610 $attrib['onclick'] = sprintf(
|
|
1611 "return %s.command('compose','%s',this)",
|
|
1612 rcmail_output::JS_OBJECT_NAME,
|
|
1613 rcube::JQ(implode(',', $mailto) . ($url ? "?$url" : '')));
|
|
1614 }
|
|
1615 else {
|
|
1616 $attrib['href'] = '#NOP';
|
|
1617 $attrib['onclick'] = '';
|
|
1618 }
|
|
1619 }
|
|
1620 else if (empty($attrib['href']) && !isset($attrib['name'])) {
|
|
1621 $attrib['href'] = './#NOP';
|
|
1622 $attrib['onclick'] = 'return false';
|
|
1623 }
|
|
1624 else if (!empty($attrib['href']) && $attrib['href'][0] != '#') {
|
|
1625 $attrib['target'] = '_blank';
|
|
1626 }
|
|
1627
|
|
1628 // Better security by adding rel="noreferrer" (#1484686)
|
|
1629 if (($tag == 'a' || $tag == 'area') && $attrib['href'] && $attrib['href'][0] != '#') {
|
|
1630 $attrib['rel'] = 'noreferrer';
|
|
1631 }
|
|
1632
|
|
1633 // allowed attributes for a|link|area tags
|
|
1634 $allow = array('href','name','target','onclick','id','class','style','title',
|
|
1635 'rel','type','media','alt','coords','nohref','hreflang','shape');
|
|
1636
|
|
1637 return html::tag($tag, $attrib, $content, $allow);
|
|
1638 }
|
|
1639
|
|
1640 /**
|
|
1641 * Decode address string and re-format it as HTML links
|
|
1642 */
|
|
1643 function rcmail_address_string($input, $max=null, $linked=false, $addicon=null, $default_charset=null, $title=null)
|
|
1644 {
|
|
1645 global $RCMAIL, $PRINT_MODE;
|
|
1646
|
|
1647 $a_parts = rcube_mime::decode_address_list($input, null, true, $default_charset);
|
|
1648
|
|
1649 if (!count($a_parts)) {
|
|
1650 return $input;
|
|
1651 }
|
|
1652
|
|
1653 $c = count($a_parts);
|
|
1654 $j = 0;
|
|
1655 $out = '';
|
|
1656 $allvalues = array();
|
|
1657 $show_email = $RCMAIL->config->get('message_show_email');
|
|
1658
|
|
1659 if ($addicon && !isset($_SESSION['writeable_abook'])) {
|
|
1660 $_SESSION['writeable_abook'] = $RCMAIL->get_address_sources(true) ? true : false;
|
|
1661 }
|
|
1662
|
|
1663 foreach ($a_parts as $part) {
|
|
1664 $j++;
|
|
1665
|
|
1666 $name = $part['name'];
|
|
1667 $mailto = $part['mailto'];
|
|
1668 $string = $part['string'];
|
|
1669 $valid = rcube_utils::check_email($mailto, false);
|
|
1670
|
|
1671 // phishing email prevention (#1488981), e.g. "valid@email.addr <phishing@email.addr>"
|
|
1672 if (!$show_email && $valid && $name && $name != $mailto && strpos($name, '@')) {
|
|
1673 $name = '';
|
|
1674 }
|
|
1675
|
|
1676 // IDNA ASCII to Unicode
|
|
1677 if ($name == $mailto)
|
|
1678 $name = rcube_utils::idn_to_utf8($name);
|
|
1679 if ($string == $mailto)
|
|
1680 $string = rcube_utils::idn_to_utf8($string);
|
|
1681 $mailto = rcube_utils::idn_to_utf8($mailto);
|
|
1682
|
|
1683 if ($PRINT_MODE) {
|
|
1684 $address = sprintf('%s <%s>', rcube::Q($name), rcube::Q($mailto));
|
|
1685 }
|
|
1686 else if ($valid) {
|
|
1687 if ($linked) {
|
|
1688 $attrs = array(
|
|
1689 'href' => 'mailto:' . $mailto,
|
|
1690 'class' => 'rcmContactAddress',
|
|
1691 'onclick' => sprintf("return %s.command('compose','%s',this)",
|
|
1692 rcmail_output::JS_OBJECT_NAME, rcube::JQ(format_email_recipient($mailto, $name))),
|
|
1693 );
|
|
1694
|
|
1695 if ($show_email && $name && $mailto) {
|
|
1696 $content = rcube::Q($name ? sprintf('%s <%s>', $name, $mailto) : $mailto);
|
|
1697 }
|
|
1698 else {
|
|
1699 $content = rcube::Q($name ?: $mailto);
|
|
1700 $attrs['title'] = $mailto;
|
|
1701 }
|
|
1702
|
|
1703 $address = html::a($attrs, $content);
|
|
1704 }
|
|
1705 else {
|
|
1706 $address = html::span(array('title' => $mailto, 'class' => "rcmContactAddress"),
|
|
1707 rcube::Q($name ?: $mailto));
|
|
1708 }
|
|
1709
|
|
1710 if ($addicon && $_SESSION['writeable_abook']) {
|
|
1711 $address .= html::a(array(
|
|
1712 'href' => "#add",
|
|
1713 'title' => $RCMAIL->gettext('addtoaddressbook'),
|
|
1714 'class' => 'rcmaddcontact',
|
|
1715 'onclick' => sprintf("return %s.command('add-contact','%s',this)",
|
|
1716 rcmail_output::JS_OBJECT_NAME, rcube::JQ($string)),
|
|
1717 ),
|
|
1718 html::img(array(
|
|
1719 'src' => $RCMAIL->output->abs_url($addicon, true),
|
|
1720 'alt' => "Add contact",
|
|
1721 'class' => 'noselect',
|
|
1722 )));
|
|
1723 }
|
|
1724 }
|
|
1725 else {
|
|
1726 $address = $name ? rcube::Q($name) : '';
|
|
1727 if ($mailto) {
|
|
1728 $address = trim($address . ' ' . rcube::Q($name ? sprintf('<%s>', $mailto) : $mailto));
|
|
1729 }
|
|
1730 }
|
|
1731
|
|
1732 $address = html::span('adr', $address);
|
|
1733 $allvalues[] = $address;
|
|
1734
|
|
1735 if (!$moreadrs) {
|
|
1736 $out .= ($out ? ', ' : '') . $address;
|
|
1737 }
|
|
1738
|
|
1739 if ($max && $j == $max && $c > $j) {
|
|
1740 if ($linked) {
|
|
1741 $moreadrs = $c - $j;
|
|
1742 }
|
|
1743 else {
|
|
1744 $out .= '...';
|
|
1745 break;
|
|
1746 }
|
|
1747 }
|
|
1748 }
|
|
1749
|
|
1750 if ($moreadrs) {
|
|
1751 $label = rcube::Q($RCMAIL->gettext(array('name' => 'andnmore', 'vars' => array('nr' => $moreadrs))));
|
|
1752
|
|
1753 if ($PRINT_MODE) {
|
|
1754 $out .= ' ' . html::a(array(
|
|
1755 'href' => '#more',
|
|
1756 'class' => 'morelink',
|
|
1757 'onclick' => '$(this).hide().next().show()',
|
|
1758 ), $label)
|
|
1759 . html::span(array('style' => 'display:none'), join(', ', $allvalues));
|
|
1760 }
|
|
1761 else {
|
|
1762 $out .= ' ' . html::a(array(
|
|
1763 'href' => '#more',
|
|
1764 'class' => 'morelink',
|
|
1765 'onclick' => sprintf("return %s.show_popup_dialog('%s','%s')",
|
|
1766 rcmail_output::JS_OBJECT_NAME,
|
|
1767 rcube::JQ(join(', ', $allvalues)),
|
|
1768 rcube::JQ($title))
|
|
1769 ), $label);
|
|
1770 }
|
|
1771 }
|
|
1772
|
|
1773 return $out;
|
|
1774 }
|
|
1775
|
|
1776 /**
|
|
1777 * Wrap text to a given number of characters per line
|
|
1778 * but respect the mail quotation of replies messages (>).
|
|
1779 * Finally add another quotation level by prepending the lines
|
|
1780 * with >
|
|
1781 *
|
|
1782 * @param string Text to wrap
|
|
1783 * @param int The line width
|
|
1784 * @return string The wrapped text
|
|
1785 */
|
|
1786 function rcmail_wrap_and_quote($text, $length = 72)
|
|
1787 {
|
|
1788 // Rebuild the message body with a maximum of $max chars, while keeping quoted message.
|
|
1789 $max = max(75, $length + 8);
|
|
1790 $lines = preg_split('/\r?\n/', trim($text));
|
|
1791 $out = '';
|
|
1792
|
|
1793 foreach ($lines as $line) {
|
|
1794 // don't wrap already quoted lines
|
|
1795 if ($line[0] == '>') {
|
|
1796 $line = '>' . rtrim($line);
|
|
1797 }
|
|
1798 else if (mb_strlen($line) > $max) {
|
|
1799 $newline = '';
|
|
1800
|
|
1801 foreach (explode("\n", rcube_mime::wordwrap($line, $length - 2)) as $l) {
|
|
1802 $newline .= strlen($l) ? "> $l\n" : ">\n";
|
|
1803 }
|
|
1804
|
|
1805 $line = rtrim($newline);
|
|
1806 }
|
|
1807 else {
|
|
1808 $line = '> ' . $line;
|
|
1809 }
|
|
1810
|
|
1811 // Append the line
|
|
1812 $out .= $line . "\n";
|
|
1813 }
|
|
1814
|
|
1815 return rtrim($out, "\n");
|
|
1816 }
|
|
1817
|
|
1818 function rcmail_draftinfo_encode($p)
|
|
1819 {
|
|
1820 $parts = array();
|
|
1821 foreach ($p as $key => $val) {
|
|
1822 $encode = $key == 'folder' || strpos($val, ';') !== false;
|
|
1823 $parts[] = $key . '=' . ($encode ? 'B::' . base64_encode($val) : $val);
|
|
1824 }
|
|
1825
|
|
1826 return join('; ', $parts);
|
|
1827 }
|
|
1828
|
|
1829 function rcmail_draftinfo_decode($str)
|
|
1830 {
|
|
1831 $info = array();
|
|
1832
|
|
1833 foreach (preg_split('/;\s+/', $str) as $part) {
|
|
1834 list($key, $val) = explode('=', $part, 2);
|
|
1835 if (strpos($val, 'B::') === 0) {
|
|
1836 $val = base64_decode(substr($val, 3));
|
|
1837 }
|
|
1838 else if ($key == 'folder') {
|
|
1839 $val = base64_decode($val);
|
|
1840 }
|
|
1841
|
|
1842 $info[$key] = $val;
|
|
1843 }
|
|
1844
|
|
1845 return $info;
|
|
1846 }
|
|
1847
|
|
1848 /**
|
|
1849 * Send the MDN response
|
|
1850 *
|
|
1851 * @param mixed $message Original message object (rcube_message) or UID
|
|
1852 * @param array $smtp_error SMTP error array (reference)
|
|
1853 *
|
|
1854 * @return boolean Send status
|
|
1855 */
|
|
1856 function rcmail_send_mdn($message, &$smtp_error)
|
|
1857 {
|
|
1858 global $RCMAIL;
|
|
1859
|
|
1860 if (!is_object($message) || !is_a($message, 'rcube_message')) {
|
|
1861 $message = new rcube_message($message);
|
|
1862 }
|
|
1863
|
|
1864 if ($message->headers->mdn_to && empty($message->headers->flags['MDNSENT']) &&
|
|
1865 ($RCMAIL->storage->check_permflag('MDNSENT') || $RCMAIL->storage->check_permflag('*'))
|
|
1866 ) {
|
|
1867 $identity = rcmail_identity_select($message);
|
|
1868 $sender = format_email_recipient($identity['email'], $identity['name']);
|
|
1869 $recipient = array_shift(rcube_mime::decode_address_list(
|
|
1870 $message->headers->mdn_to, 1, true, $message->headers->charset));
|
|
1871 $mailto = $recipient['mailto'];
|
|
1872
|
|
1873 $compose = new Mail_mime("\r\n");
|
|
1874
|
|
1875 $compose->setParam('text_encoding', 'quoted-printable');
|
|
1876 $compose->setParam('html_encoding', 'quoted-printable');
|
|
1877 $compose->setParam('head_encoding', 'quoted-printable');
|
|
1878 $compose->setParam('head_charset', RCUBE_CHARSET);
|
|
1879 $compose->setParam('html_charset', RCUBE_CHARSET);
|
|
1880 $compose->setParam('text_charset', RCUBE_CHARSET);
|
|
1881
|
|
1882 // compose headers array
|
|
1883 $headers = array(
|
|
1884 'Date' => $RCMAIL->user_date(),
|
|
1885 'From' => $sender,
|
|
1886 'To' => $message->headers->mdn_to,
|
|
1887 'Subject' => $RCMAIL->gettext('receiptread') . ': ' . $message->subject,
|
|
1888 'Message-ID' => $RCMAIL->gen_message_id($identity['email']),
|
|
1889 'X-Sender' => $identity['email'],
|
|
1890 'References' => trim($message->headers->references . ' ' . $message->headers->messageID),
|
|
1891 'In-Reply-To' => $message->headers->messageID,
|
|
1892 );
|
|
1893
|
|
1894 $report = "Final-Recipient: rfc822; {$identity['email']}\r\n"
|
|
1895 . "Original-Message-ID: {$message->headers->messageID}\r\n"
|
|
1896 . "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
|
|
1897
|
|
1898 if ($message->headers->to) {
|
|
1899 $report .= "Original-Recipient: {$message->headers->to}\r\n";
|
|
1900 }
|
|
1901
|
|
1902 if ($agent = $RCMAIL->config->get('useragent')) {
|
|
1903 $headers['User-Agent'] = $agent;
|
|
1904 $report .= "Reporting-UA: $agent\r\n";
|
|
1905 }
|
|
1906
|
|
1907 $to = rcube_mime::decode_mime_string($message->headers->to, $message->headers->charset);
|
|
1908 $date = $RCMAIL->format_date($message->headers->date, $RCMAIL->config->get('date_long'));
|
|
1909 $body = $RCMAIL->gettext("yourmessage") . "\r\n\r\n" .
|
|
1910 "\t" . $RCMAIL->gettext("to") . ": {$to}\r\n" .
|
|
1911 "\t" . $RCMAIL->gettext("subject") . ": {$message->subject}\r\n" .
|
|
1912 "\t" . $RCMAIL->gettext("date") . ": {$date}\r\n" .
|
|
1913 "\r\n" . $RCMAIL->gettext("receiptnote");
|
|
1914
|
|
1915 $compose->headers(array_filter($headers));
|
|
1916 $compose->setContentType('multipart/report', array('report-type'=> 'disposition-notification'));
|
|
1917 $compose->setTXTBody(rcube_mime::wordwrap($body, 75, "\r\n"));
|
|
1918 $compose->addAttachment($report, 'message/disposition-notification', 'MDNPart2.txt', false, '7bit', 'inline');
|
|
1919
|
|
1920 // SMTP options
|
|
1921 $options = array('mdn_use_from' => (bool) $RCMAIL->config->get('mdn_use_from'));
|
|
1922
|
|
1923 $sent = $RCMAIL->deliver_message($compose, $identity['email'], $mailto, $smtp_error, $body_file, $options, true);
|
|
1924
|
|
1925 if ($sent) {
|
|
1926 $RCMAIL->storage->set_flag($message->uid, 'MDNSENT');
|
|
1927 return true;
|
|
1928 }
|
|
1929 }
|
|
1930
|
|
1931 return false;
|
|
1932 }
|
|
1933
|
|
1934 /**
|
|
1935 * Detect recipient identity from specified message
|
|
1936 */
|
|
1937 function rcmail_identity_select($MESSAGE, $identities = null, $compose_mode = 'reply')
|
|
1938 {
|
|
1939 $a_recipients = array();
|
|
1940 $a_names = array();
|
|
1941
|
|
1942 if ($identities === null) {
|
|
1943 $identities = rcmail::get_instance()->user->list_identities(null, true);
|
|
1944 }
|
|
1945
|
|
1946 // extract all recipients of the reply-message
|
|
1947 if (is_object($MESSAGE->headers) && in_array($compose_mode, array('reply', 'forward'))) {
|
|
1948 $a_to = rcube_mime::decode_address_list($MESSAGE->headers->to, null, true, $MESSAGE->headers->charset);
|
|
1949 foreach ($a_to as $addr) {
|
|
1950 if (!empty($addr['mailto'])) {
|
|
1951 $a_recipients[] = strtolower($addr['mailto']);
|
|
1952 $a_names[] = $addr['name'];
|
|
1953 }
|
|
1954 }
|
|
1955
|
|
1956 if (!empty($MESSAGE->headers->cc)) {
|
|
1957 $a_cc = rcube_mime::decode_address_list($MESSAGE->headers->cc, null, true, $MESSAGE->headers->charset);
|
|
1958 foreach ($a_cc as $addr) {
|
|
1959 if (!empty($addr['mailto'])) {
|
|
1960 $a_recipients[] = strtolower($addr['mailto']);
|
|
1961 $a_names[] = $addr['name'];
|
|
1962 }
|
|
1963 }
|
|
1964 }
|
|
1965 }
|
|
1966
|
|
1967 // decode From: address
|
|
1968 $from = rcube_mime::decode_address_list($MESSAGE->headers->from, null, true, $MESSAGE->headers->charset);
|
|
1969 $from = array_shift($from);
|
|
1970 $from['mailto'] = strtolower($from['mailto']);
|
|
1971
|
|
1972 $from_idx = null;
|
|
1973 $found_idx = array('to' => null, 'from' => null);
|
|
1974 $check_from = in_array($compose_mode, array('draft', 'edit', 'reply'));
|
|
1975
|
|
1976 // Select identity
|
|
1977 foreach ($identities as $idx => $ident) {
|
|
1978 // use From: header when in edit/draft or reply-to-self
|
|
1979 if ($check_from && $from['mailto'] == strtolower($ident['email_ascii'])) {
|
|
1980 // remember first matching identity address
|
|
1981 if ($found_idx['from'] === null) {
|
|
1982 $found_idx['from'] = $idx;
|
|
1983 }
|
|
1984 // match identity name
|
|
1985 if ($from['name'] && $ident['name'] && $from['name'] == $ident['name']) {
|
|
1986 $from_idx = $idx;
|
|
1987 break;
|
|
1988 }
|
|
1989 }
|
|
1990 // use replied/forwarded message recipients
|
|
1991 else if (($found = array_search(strtolower($ident['email_ascii']), $a_recipients)) !== false) {
|
|
1992 // remember first matching identity address
|
|
1993 if ($found_idx['to'] === null) {
|
|
1994 $found_idx['to'] = $idx;
|
|
1995 }
|
|
1996 // match identity name
|
|
1997 if ($a_names[$found] && $ident['name'] && $a_names[$found] == $ident['name']) {
|
|
1998 $from_idx = $idx;
|
|
1999 break;
|
|
2000 }
|
|
2001 }
|
|
2002 }
|
|
2003
|
|
2004 // If matching by name+address didn't find any matches,
|
|
2005 // get first found identity (address) if any
|
|
2006 if ($from_idx === null) {
|
|
2007 $from_idx = $found_idx['from'] !== null ? $found_idx['from'] : $found_idx['to'];
|
|
2008 }
|
|
2009
|
|
2010 // Try Return-Path
|
|
2011 if ($from_idx === null && ($return_path = $MESSAGE->headers->others['return-path'])) {
|
|
2012 $return_path = array_map('strtolower', (array) $return_path);
|
|
2013
|
|
2014 foreach ($identities as $idx => $ident) {
|
|
2015 // Return-Path header contains an email address, but on some mailing list
|
|
2016 // it can be e.g. <pear-dev-return-55250-local=domain.tld@lists.php.net>
|
|
2017 // where local@domain.tld is the address we're looking for (#1489241)
|
|
2018 $ident1 = strtolower($ident['email_ascii']);
|
|
2019 $ident2 = str_replace('@', '=', $ident1);
|
|
2020 $ident1 = '<' . $ident1 . '>';
|
|
2021 $ident2 = '-' . $ident2 . '@';
|
|
2022
|
|
2023 foreach ($return_path as $path) {
|
|
2024 if ($path == $ident1 || stripos($path, $ident2)) {
|
|
2025 $from_idx = $idx;
|
|
2026 break 2;
|
|
2027 }
|
|
2028 }
|
|
2029 }
|
|
2030 }
|
|
2031
|
|
2032 // See identity_select plugin for example usage of this hook
|
|
2033 $plugin = rcmail::get_instance()->plugins->exec_hook('identity_select',
|
|
2034 array('message' => $MESSAGE, 'identities' => $identities, 'selected' => $from_idx));
|
|
2035
|
|
2036 $selected = $plugin['selected'];
|
|
2037
|
|
2038 // default identity is always first on the list
|
|
2039 return $identities[$selected !== null ? $selected : 0];
|
|
2040 }
|
|
2041
|
|
2042 // Fixes some content-type names
|
|
2043 function rcmail_fix_mimetype($name)
|
|
2044 {
|
|
2045 $map = array(
|
|
2046 'image/x-ms-bmp' => 'image/bmp', // #1490282
|
|
2047 );
|
|
2048
|
|
2049 $name = strtolower($name);
|
|
2050
|
|
2051 if ($alias = $map[$name]) {
|
|
2052 $name = $alias;
|
|
2053 }
|
|
2054 // Some versions of Outlook create garbage Content-Type:
|
|
2055 // application/pdf.A520491B_3BF7_494D_8855_7FAC2C6C0608
|
|
2056 else if (preg_match('/^application\/pdf.+/', $name)) {
|
|
2057 $name = 'application/pdf';
|
|
2058 }
|
|
2059 // treat image/pjpeg (image/pjpg, image/jpg) as image/jpeg (#1489097)
|
|
2060 else if (preg_match('/^image\/p?jpe?g$/', $name)) {
|
|
2061 $name = 'image/jpeg';
|
|
2062 }
|
|
2063
|
|
2064 return $name;
|
|
2065 }
|
|
2066
|
|
2067 // return attachment filename, handle empty filename case
|
|
2068 function rcmail_attachment_name($attachment, $display = false)
|
|
2069 {
|
|
2070 global $RCMAIL;
|
|
2071
|
|
2072 $filename = (string) $attachment->filename;
|
|
2073 $filename = preg_replace('/[\x00-\x1F\x7F]/', '', $filename);
|
|
2074
|
|
2075 if ($filename === '') {
|
|
2076 if ($attachment->mimetype == 'text/html') {
|
|
2077 $filename = $RCMAIL->gettext('htmlmessage');
|
|
2078 }
|
|
2079 else {
|
|
2080 $ext = (array) rcube_mime::get_mime_extensions($attachment->mimetype);
|
|
2081 $ext = array_shift($ext);
|
|
2082 $filename = $RCMAIL->gettext('messagepart') . ' ' . $attachment->mime_id;
|
|
2083 if ($ext) {
|
|
2084 $filename .= '.' . $ext;
|
|
2085 }
|
|
2086 }
|
|
2087 }
|
|
2088
|
|
2089 // Display smart names for some known mimetypes
|
|
2090 if ($display) {
|
|
2091 if (preg_match('/application\/(pgp|pkcs7)-signature/i', $attachment->mimetype)) {
|
|
2092 $filename = $RCMAIL->gettext('digitalsig');
|
|
2093 }
|
|
2094 }
|
|
2095
|
|
2096 return $filename;
|
|
2097 }
|
|
2098
|
|
2099 function rcmail_search_filter($attrib)
|
|
2100 {
|
|
2101 global $RCMAIL;
|
|
2102
|
|
2103 if (!strlen($attrib['id'])) {
|
|
2104 $attrib['id'] = 'rcmlistfilter';
|
|
2105 }
|
|
2106
|
|
2107 $attrib['onchange'] = rcmail_output::JS_OBJECT_NAME.'.filter_mailbox(this.value)';
|
|
2108
|
|
2109 // Content-Type values of messages with attachments
|
|
2110 // the same as in app.js:add_message_row()
|
|
2111 $ctypes = array('application/', 'multipart/m', 'multipart/signed', 'multipart/report');
|
|
2112
|
|
2113 // Build search string of "with attachment" filter
|
|
2114 $attachment = trim(str_repeat(' OR', count($ctypes)-1));
|
|
2115 foreach ($ctypes as $type) {
|
|
2116 $attachment .= ' HEADER Content-Type ' . rcube_imap_generic::escape($type);
|
|
2117 }
|
|
2118
|
|
2119 $select = new html_select($attrib);
|
|
2120 $select->add($RCMAIL->gettext('all'), 'ALL');
|
|
2121 $select->add($RCMAIL->gettext('unread'), 'UNSEEN');
|
|
2122 $select->add($RCMAIL->gettext('flagged'), 'FLAGGED');
|
|
2123 $select->add($RCMAIL->gettext('unanswered'), 'UNANSWERED');
|
|
2124 if (!$RCMAIL->config->get('skip_deleted')) {
|
|
2125 $select->add($RCMAIL->gettext('deleted'), 'DELETED');
|
|
2126 $select->add($RCMAIL->gettext('undeleted'), 'UNDELETED');
|
|
2127 }
|
|
2128 $select->add($RCMAIL->gettext('withattachment'), $attachment);
|
|
2129 $select->add($RCMAIL->gettext('priority').': '.$RCMAIL->gettext('highest'), 'HEADER X-PRIORITY 1');
|
|
2130 $select->add($RCMAIL->gettext('priority').': '.$RCMAIL->gettext('high'), 'HEADER X-PRIORITY 2');
|
|
2131 $select->add($RCMAIL->gettext('priority').': '.$RCMAIL->gettext('normal'), 'NOT HEADER X-PRIORITY 1 NOT HEADER X-PRIORITY 2 NOT HEADER X-PRIORITY 4 NOT HEADER X-PRIORITY 5');
|
|
2132 $select->add($RCMAIL->gettext('priority').': '.$RCMAIL->gettext('low'), 'HEADER X-PRIORITY 4');
|
|
2133 $select->add($RCMAIL->gettext('priority').': '.$RCMAIL->gettext('lowest'), 'HEADER X-PRIORITY 5');
|
|
2134
|
|
2135 $RCMAIL->output->add_gui_object('search_filter', $attrib['id']);
|
|
2136
|
|
2137 return $select->show($_REQUEST['_search'] ? $_SESSION['search_filter'] : 'ALL');
|
|
2138 }
|
|
2139
|
|
2140 function rcmail_search_interval($attrib)
|
|
2141 {
|
|
2142 global $RCMAIL;
|
|
2143
|
|
2144 if (!strlen($attrib['id'])) {
|
|
2145 $attrib['id'] = 'rcmsearchinterval';
|
|
2146 }
|
|
2147
|
|
2148 $select = new html_select($attrib);
|
|
2149 $select->add('', '');
|
|
2150
|
|
2151 foreach (array('1W', '1M', '1Y', '-1W', '-1M', '-1Y') as $value) {
|
|
2152 $select->add($RCMAIL->gettext('searchinterval' . $value), $value);
|
|
2153 }
|
|
2154
|
|
2155 $RCMAIL->output->add_gui_object('search_interval', $attrib['id']);
|
|
2156
|
|
2157 return $select->show($_REQUEST['_search'] ? $_SESSION['search_interval'] : '');
|
|
2158 }
|
|
2159
|
|
2160 function rcmail_message_error()
|
|
2161 {
|
|
2162 global $RCMAIL;
|
|
2163
|
|
2164 // Set env variables for messageerror.html template
|
|
2165 if ($RCMAIL->action == 'show') {
|
|
2166 $mbox_name = $RCMAIL->storage->get_folder();
|
|
2167
|
|
2168 $RCMAIL->output->set_env('mailbox', $mbox_name);
|
|
2169 $RCMAIL->output->set_env('uid', null);
|
|
2170 }
|
|
2171
|
|
2172 // display error message
|
|
2173 $RCMAIL->output->show_message('messageopenerror', 'error');
|
|
2174 // ... display message error page
|
|
2175 $RCMAIL->output->send('messageerror');
|
|
2176 }
|
|
2177
|
|
2178 function rcmail_message_import_form($attrib = array())
|
|
2179 {
|
|
2180 global $RCMAIL;
|
|
2181
|
|
2182 $RCMAIL->output->add_label('selectimportfile','importwait');
|
|
2183
|
|
2184 $input_attr = array(
|
|
2185 'multiple' => true,
|
|
2186 'name' => '_file[]',
|
|
2187 'accept' => ".eml, .mbox, message/rfc822, text/*",
|
|
2188 );
|
|
2189
|
|
2190 $attrib['prefix'] = html::tag('input', array('type' => 'hidden', 'name' => '_unlock', 'value' => ''))
|
|
2191 . html::tag('input', array('type' => 'hidden', 'name' => '_framed', 'value' => '1'));
|
|
2192
|
|
2193 return $RCMAIL->upload_form($attrib, 'importform', 'import-messages', $input_attr);
|
|
2194 }
|
|
2195
|
|
2196 /**
|
|
2197 * Add groups from the given address source to the address book widget
|
|
2198 */
|
|
2199 function rcmail_compose_contact_groups($abook, $source_id, $search = null, $search_mode = 0)
|
|
2200 {
|
|
2201 global $RCMAIL, $OUTPUT;
|
|
2202
|
|
2203 $jsresult = array();
|
|
2204 foreach ($abook->list_groups($search, $search_mode) as $group) {
|
|
2205 $abook->reset();
|
|
2206 $abook->set_group($group['ID']);
|
|
2207
|
|
2208 // group (distribution list) with email address(es)
|
|
2209 if ($group['email']) {
|
|
2210 foreach ((array)$group['email'] as $email) {
|
|
2211 $row_id = 'G'.$group['ID'];
|
|
2212 $jsresult[$row_id] = format_email_recipient($email, $group['name']);
|
|
2213 $OUTPUT->command('add_contact_row', $row_id, array(
|
|
2214 'contactgroup' => html::span(array('title' => $email), rcube::Q($group['name']))), 'group');
|
|
2215 }
|
|
2216 }
|
|
2217 // make virtual groups clickable to list their members
|
|
2218 else if ($group['virtual']) {
|
|
2219 $row_id = 'G'.$group['ID'];
|
|
2220 $OUTPUT->command('add_contact_row', $row_id, array(
|
|
2221 'contactgroup' => html::a(array(
|
|
2222 'href' => '#list',
|
|
2223 'rel' => $group['ID'],
|
|
2224 'title' => $RCMAIL->gettext('listgroup'),
|
|
2225 'onclick' => sprintf("return %s.command('pushgroup',{'source':'%s','id':'%s'},this,event)",
|
|
2226 rcmail_output::JS_OBJECT_NAME, $source_id, $group['ID']),
|
|
2227 ), rcube::Q($group['name']) . ' ' . html::span('action', '»'))),
|
|
2228 'group',
|
|
2229 array('ID' => $group['ID'], 'name' => $group['name'], 'virtual' => true));
|
|
2230 }
|
|
2231 // show group with count
|
|
2232 else if (($result = $abook->count()) && $result->count) {
|
|
2233 $row_id = 'E'.$group['ID'];
|
|
2234 $jsresult[$row_id] = $group['name'];
|
|
2235 $OUTPUT->command('add_contact_row', $row_id, array(
|
|
2236 'contactgroup' => rcube::Q($group['name'] . ' (' . intval($result->count) . ')')), 'group');
|
|
2237 }
|
|
2238 }
|
|
2239
|
|
2240 $abook->reset();
|
|
2241 $abook->set_group(0);
|
|
2242
|
|
2243 return $jsresult;
|
|
2244 }
|
|
2245
|
|
2246 function rcmail_save_attachment($message, $pid, $compose_id, $params = array())
|
|
2247 {
|
|
2248 global $COMPOSE;
|
|
2249
|
|
2250 $rcmail = rcmail::get_instance();
|
|
2251 $storage = $rcmail->get_storage();
|
|
2252
|
|
2253 if ($pid) {
|
|
2254 // attachment requested
|
|
2255 $part = $message->mime_parts[$pid];
|
|
2256 $size = $part->size;
|
|
2257 $mimetype = $part->ctype_primary . '/' . $part->ctype_secondary;
|
|
2258 $filename = $params['filename'] ?: rcmail_attachment_name($part);
|
|
2259 }
|
|
2260 else if (is_object($message)) {
|
|
2261 // the whole message requested
|
|
2262 $size = $message->size;
|
|
2263 $mimetype = 'message/rfc822';
|
|
2264 $filename = $params['filename'] ?: 'message_rfc822.eml';
|
|
2265 }
|
|
2266 else if (is_string($message)) {
|
|
2267 // the whole message requested
|
|
2268 $size = strlen($message);
|
|
2269 $data = $message;
|
|
2270 $mimetype = $params['mimetype'];
|
|
2271 $filename = $params['filename'];
|
|
2272 }
|
|
2273
|
|
2274 if (!isset($data)) {
|
|
2275 // don't load too big attachments into memory
|
|
2276 if (!rcube_utils::mem_check($size)) {
|
|
2277 $temp_dir = unslashify($rcmail->config->get('temp_dir'));
|
|
2278 $path = tempnam($temp_dir, 'rcmAttmnt');
|
|
2279
|
|
2280 if ($fp = fopen($path, 'w')) {
|
|
2281 if ($pid) {
|
|
2282 // part body
|
|
2283 $message->get_part_body($pid, false, 0, $fp);
|
|
2284 }
|
|
2285 else {
|
|
2286 // complete message
|
|
2287 $storage->get_raw_body($message->uid, $fp);
|
|
2288 }
|
|
2289
|
|
2290 fclose($fp);
|
|
2291 }
|
|
2292 else {
|
|
2293 return false;
|
|
2294 }
|
|
2295 }
|
|
2296 else if ($pid) {
|
|
2297 // part body
|
|
2298 $data = $message->get_part_body($pid);
|
|
2299 }
|
|
2300 else {
|
|
2301 // complete message
|
|
2302 $data = $storage->get_raw_body($message->uid);
|
|
2303 }
|
|
2304 }
|
|
2305
|
|
2306 $attachment = array(
|
|
2307 'group' => $compose_id,
|
|
2308 'name' => $filename,
|
|
2309 'mimetype' => $mimetype,
|
|
2310 'content_id' => $part ? $part->content_id : null,
|
|
2311 'data' => $data,
|
|
2312 'path' => $path,
|
|
2313 'size' => $path ? filesize($path) : strlen($data),
|
|
2314 'charset' => $part ? $part->charset : $params['charset'],
|
|
2315 );
|
|
2316
|
|
2317 $attachment = $rcmail->plugins->exec_hook('attachment_save', $attachment);
|
|
2318
|
|
2319 if ($attachment['status']) {
|
|
2320 unset($attachment['data'], $attachment['status'], $attachment['content_id'], $attachment['abort']);
|
|
2321
|
|
2322 // rcube_session::append() replaces current session data with the old values
|
|
2323 // (in rcube_session::reload()). This is a problem in 'compose' action, because before
|
|
2324 // the first append() use we set some important data in the session.
|
|
2325 // It also overwrites attachments list. Fixing reload() is not so simple if possible
|
|
2326 // as we don't really know what has been added and what removed in meantime.
|
|
2327 // So, for now we'll do not use append() on 'compose' action (#1490608).
|
|
2328
|
|
2329 if ($rcmail->action == 'compose') {
|
|
2330 $COMPOSE['attachments'][$attachment['id']] = $attachment;
|
|
2331 }
|
|
2332 else {
|
|
2333 $rcmail->session->append('compose_data_' . $compose_id . '.attachments', $attachment['id'], $attachment);
|
|
2334 }
|
|
2335
|
|
2336 return $attachment;
|
|
2337 }
|
|
2338 else if ($path) {
|
|
2339 @unlink($path);
|
|
2340 }
|
|
2341
|
|
2342 return false;
|
|
2343 }
|
|
2344
|
|
2345 // Return mimetypes supported by the browser
|
|
2346 function rcmail_supported_mimetypes()
|
|
2347 {
|
|
2348 $rcmail = rcube::get_instance();
|
|
2349
|
|
2350 // mimetypes supported by the browser (default settings)
|
|
2351 $mimetypes = (array) $rcmail->config->get('client_mimetypes');
|
|
2352
|
|
2353 // Remove unsupported types, which makes that attachment which cannot be
|
|
2354 // displayed in a browser will be downloaded directly without displaying an overlay page
|
|
2355 if (empty($_SESSION['browser_caps']['pdf']) && ($key = array_search('application/pdf', $mimetypes)) !== false) {
|
|
2356 unset($mimetypes[$key]);
|
|
2357 }
|
|
2358
|
|
2359 if (empty($_SESSION['browser_caps']['flash']) && ($key = array_search('application/x-shockwave-flash', $mimetypes)) !== false) {
|
|
2360 unset($mimetypes[$key]);
|
|
2361 }
|
|
2362
|
|
2363 foreach (array('tiff', 'webp') as $type) {
|
|
2364 if (empty($_SESSION['browser_caps'][$type]) && ($key = array_search('image/' . $type, $mimetypes)) !== false) {
|
|
2365 // can we convert it to jpeg?
|
|
2366 if (!rcube_image::is_convertable('image/' . $type)) {
|
|
2367 unset($mimetypes[$key]);
|
|
2368 }
|
|
2369 }
|
|
2370 }
|
|
2371
|
|
2372 // @TODO: support mail preview for compose attachments
|
|
2373 if ($rcmail->action != 'compose' && !in_array('message/rfc822', $mimetypes)) {
|
|
2374 $mimetypes[] = 'message/rfc822';
|
|
2375 }
|
|
2376
|
|
2377 return array_values($mimetypes);
|
|
2378 }
|