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