Aleksander Machniak
2016-04-02 6f2c007d1be866e47bf6a9f8e6900fe6ec2a6901
commit | author | age
4e17e6 1 <?php
T 2
a95874 3 /**
4e17e6 4  +-----------------------------------------------------------------------+
T 5  | program/steps/mail/show.inc                                           |
6  |                                                                       |
e019f2 7  | This file is part of the Roundcube Webmail client                     |
f5d2ee 8  | Copyright (C) 2005-2013, The Roundcube Dev Team                       |
7fe381 9  |                                                                       |
T 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.                     |
4e17e6 13  |                                                                       |
T 14  | PURPOSE:                                                              |
15  |   Display a mail message similar as a usual mail application does     |
16  |                                                                       |
17  +-----------------------------------------------------------------------+
18  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
19  +-----------------------------------------------------------------------+
20 */
21
6f2c00 22 $PRINT_MODE = $RCMAIL->action == 'print';
4e17e6 23
e349a8 24 // Read browser capabilities and store them in session
6b2b2e 25 if ($caps = rcube_utils::get_input_value('_caps', rcube_utils::INPUT_GET)) {
f5d2ee 26     $browser_caps = array();
AM 27     foreach (explode(',', $caps) as $cap) {
28         $cap = explode('=', $cap);
29         $browser_caps[$cap[0]] = $cap[1];
30     }
31     $_SESSION['browser_caps'] = $browser_caps;
e349a8 32 }
AM 33
6b2b2e 34 $uid       = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_GET);
a02c77 35 $mbox_name = $RCMAIL->storage->get_folder();
AM 36
4e17e6 37 // similar code as in program/steps/mail/get.inc
a02c77 38 if ($uid) {
f5d2ee 39     // set message format (need to be done before rcube_message construction)
AM 40     if (!empty($_GET['_format'])) {
41         $prefer_html = $_GET['_format'] == 'html';
42         $RCMAIL->config->set('prefer_html', $prefer_html);
43         $_SESSION['msg_formats'][$mbox_name.':'.$uid] = $prefer_html;
19cc5b 44     }
f5d2ee 45     else if (isset($_SESSION['msg_formats'][$mbox_name.':'.$uid])) {
AM 46         $RCMAIL->config->set('prefer_html', $_SESSION['msg_formats'][$mbox_name.':'.$uid]);
0ea884 47     }
4e17e6 48
63e793 49     $MESSAGE = new rcube_message($uid, $mbox_name, intval($_GET['_safe']));
f5d2ee 50
AM 51     // if message not found (wrong UID)...
52     if (empty($MESSAGE->headers)) {
53         rcmail_message_error($uid);
54     }
55
56     // show images?
57     rcmail_check_safe($MESSAGE);
58
59     // set message charset as default
60     if (!empty($MESSAGE->headers->charset)) {
61         $RCMAIL->storage->set_charset($MESSAGE->headers->charset);
62     }
63
64     $OUTPUT->set_pagetitle(abbreviate_string($MESSAGE->subject, 128, '...', true));
65
66     // set message environment
67     $OUTPUT->set_env('uid', $MESSAGE->uid);
68     $OUTPUT->set_env('safemode', $MESSAGE->is_safe);
69     $OUTPUT->set_env('sender', $MESSAGE->sender['string']);
70     $OUTPUT->set_env('mailbox', $mbox_name);
d56091 71     $OUTPUT->set_env('username', $RCMAIL->get_user_name());
f5d2ee 72     $OUTPUT->set_env('permaurl', $RCMAIL->url(array('_action' => 'show', '_uid' => $MESSAGE->uid, '_mbox' => $mbox_name)));
AM 73
74     if ($MESSAGE->headers->get('list-post', false)) {
75         $OUTPUT->set_env('list_post', true);
76     }
77
78     // set environment
79     $OUTPUT->set_env('delimiter', $RCMAIL->storage->get_hierarchy_delimiter());
80
81     // set configuration
82     $RCMAIL->set_env_config(array('delete_junk', 'flag_for_deletion', 'read_when_deleted',
d47833 83         'skip_deleted', 'display_next', 'forward_attachment'));
f5d2ee 84
AM 85     // set special folders
86     foreach (array('drafts', 'trash', 'junk') as $mbox) {
87         if ($folder = $RCMAIL->config->get($mbox . '_mbox')) {
88             $OUTPUT->set_env($mbox . '_mailbox', $folder);
89         }
90     }
91
92     // mimetypes supported by the browser (default settings)
93     $mimetypes = (array)$RCMAIL->config->get('client_mimetypes');
94
95     // Remove unsupported types, which makes that attachment which cannot be
96     // displayed in a browser will be downloaded directly without displaying an overlay page
97     if (empty($_SESSION['browser_caps']['pdf']) && ($key = array_search('application/pdf', $mimetypes)) !== false) {
98         unset($mimetypes[$key]);
99     }
100     if (empty($_SESSION['browser_caps']['flash']) && ($key = array_search('application/x-shockwave-flash', $mimetypes)) !== false) {
101         unset($mimetypes[$key]);
102     }
103     if (empty($_SESSION['browser_caps']['tif']) && ($key = array_search('image/tiff', $mimetypes)) !== false) {
104         // we can convert tiff to jpeg
8968f9 105         if (!rcube_image::is_convertable('image/tiff')) {
f5d2ee 106             unset($mimetypes[$key]);
AM 107         }
108     }
109
110     $OUTPUT->set_env('mimetypes', array_values($mimetypes));
111
112     if ($MESSAGE->has_html_part()) {
113         $prefer_html = $RCMAIL->config->get('prefer_html');
114         $OUTPUT->set_env('optional_format', $prefer_html ? 'text' : 'html');
115     }
116
117     if (!$OUTPUT->ajax_call) {
118         $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash',
119             'movingmessage', 'deletingmessage', 'markingmessage', 'replyall', 'replylist');
120     }
121
122     // check for unset disposition notification
123     if ($MESSAGE->headers->mdn_to
124         && empty($MESSAGE->headers->flags['MDNSENT'])
125         && empty($MESSAGE->headers->flags['SEEN'])
126         && ($RCMAIL->storage->check_permflag('MDNSENT') || $RCMAIL->storage->check_permflag('*'))
127         && $mbox_name != $RCMAIL->config->get('drafts_mbox')
128         && $mbox_name != $RCMAIL->config->get('sent_mbox')
129     ) {
130         $mdn_cfg = intval($RCMAIL->config->get('mdn_requests'));
131
132         if ($mdn_cfg == 1 || (($mdn_cfg == 3 || $mdn_cfg ==  4) && rcmail_contact_exists($MESSAGE->sender['mailto']))) {
133             // Send MDN
134             if (rcmail_send_mdn($MESSAGE, $smtp_error))
135                 $OUTPUT->show_message('receiptsent', 'confirmation');
136             else if ($smtp_error)
137                 $OUTPUT->show_message($smtp_error['label'], 'error', $smtp_error['vars']);
138             else
139                 $OUTPUT->show_message('errorsendingreceipt', 'error');
140         }
141         else if ($mdn_cfg != 2 && $mdn_cfg != 4) {
142             // Ask user
143             $OUTPUT->add_label('mdnrequest');
144             $OUTPUT->set_env('mdn_request', true);
145         }
146     }
147
148     if (empty($MESSAGE->headers->flags['SEEN'])
149         && ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($RCMAIL->config->get('preview_pane_mark_read')) == 0))
150     ) {
d28dae 151         $RCMAIL->output->command('set_unread_message', $MESSAGE->uid, $mbox_name);
f5d2ee 152         $RCMAIL->plugins->exec_hook('message_read', array(
AM 153             'uid'     => $MESSAGE->uid,
154             'mailbox' => $mbox_name,
155             'message' => $MESSAGE,
156         ));
d28dae 157
AM 158         $set_seen_flag = true;
f5d2ee 159     }
cc97ea 160 }
f5d2ee 161
AM 162
163 $OUTPUT->add_handlers(array(
164     'messageattachments' => 'rcmail_message_attachments',
165     'mailboxname'        => 'rcmail_mailbox_name_display',
166     'messageobjects'     => 'rcmail_message_objects',
167     'contactphoto'       => 'rcmail_message_contactphoto',
168 ));
169
170
171 if ($RCMAIL->action == 'print' && $OUTPUT->template_exists('messageprint'))
172     $OUTPUT->send('messageprint', false);
173 else if ($RCMAIL->action == 'preview' && $OUTPUT->template_exists('messagepreview'))
174     $OUTPUT->send('messagepreview', false);
175 else
176     $OUTPUT->send('message', false);
177
178
179 // mark message as read
d28dae 180 if (!empty($set_seen_flag)) {
cc6c7e 181     if ($RCMAIL->storage->set_flag($MESSAGE->uid, 'SEEN', $mbox_name)) {
f5d2ee 182         if ($count = rcmail_get_unseen_count($mbox_name)) {
AM 183             rcmail_set_unseen_count($mbox_name, $count - 1);
184         }
185     }
186 }
187
1aa0c8 188 // Save preview_pane preference, if not set yet (#1490362)
AM 189 if ($RCMAIL->action == 'preview' && !$RCMAIL->config->get('preview_pane')) {
190     $RCMAIL->user->save_prefs(array('preview_pane' => true));
191 }
4e17e6 192
1aa0c8 193 exit;
4e17e6 194
T 195
196 function rcmail_message_attachments($attrib)
8fa58e 197 {
f5d2ee 198     global $PRINT_MODE, $MESSAGE, $RCMAIL;
83ba22 199
f5d2ee 200     $out = $ol = '';
AM 201     $attachments = array();
4e17e6 202
f5d2ee 203     if (sizeof($MESSAGE->attachments)) {
AM 204         foreach ($MESSAGE->attachments as $attach_prop) {
205             $filename = rcmail_attachment_name($attach_prop, true);
1881a8 206             $filesize = $RCMAIL->message_part_size($attach_prop);
203ee4 207
f5d2ee 208             if ($PRINT_MODE) {
1881a8 209                 $ol .= html::tag('li', null, rcube::Q(sprintf("%s (%s)", $filename, $filesize)));
f5d2ee 210             }
AM 211             else {
212                 if ($attrib['maxlength'] && mb_strlen($filename) > $attrib['maxlength']) {
213                     $title    = $filename;
214                     $filename = abbreviate_string($filename, $attrib['maxlength']);
215                 }
216                 else {
217                     $title = '';
218                 }
219
b2992d 220                 if ($attach_prop->size) {
1881a8 221                     $size = ' ' . html::span('attachment-size', '(' . rcube::Q($filesize) . ')');
b2992d 222                 }
TB 223
f5d2ee 224                 $mimetype = rcmail_fix_mimetype($attach_prop->mimetype);
AM 225                 $class    = rcube_utils::file2class($mimetype, $filename);
226                 $id       = 'attach' . $attach_prop->mime_id;
227                 $link     = html::a(array(
228                     'href'        => $MESSAGE->get_part_url($attach_prop->mime_id, false),
229                     'onclick'     => sprintf('return %s.command(\'load-attachment\',\'%s\',this)',
230                         rcmail_output::JS_OBJECT_NAME, $attach_prop->mime_id),
231                     'onmouseover' => $title ? '' : 'rcube_webmail.long_subject_title_ex(this, 0)',
232                     'title'       => rcube::Q($title),
b2992d 233                     ), rcube::Q($filename) . $size);
f5d2ee 234
AM 235                 $ol .= html::tag('li', array('class' => $class, 'id' => $id), $link);
236
237                 $attachments[$attach_prop->mime_id] = $mimetype;
238             }
0c2596 239         }
A 240
f5d2ee 241         $out = html::tag('ul', $attrib, $ol, html::$common_attrib);
bc2c43 242
f5d2ee 243         $RCMAIL->output->set_env('attachments', $attachments);
d56091 244         $RCMAIL->output->add_gui_object('attachments', $attrib['id']);
8fa58e 245     }
4e17e6 246
f5d2ee 247     return $out;
8fa58e 248 }
4e17e6 249
46cdbf 250 function rcmail_remote_objects_msg()
62e43d 251 {
f5d2ee 252     global $MESSAGE, $RCMAIL;
83ba22 253
f5d2ee 254     $attrib['id']    = 'remote-objects-message';
AM 255     $attrib['class'] = 'notice';
256     $attrib['style'] = 'display: none';
83ba22 257
f5d2ee 258     $msg = rcube::Q($RCMAIL->gettext('blockedimages')) . '&nbsp;';
AM 259     $msg .= html::a(array(
260             'href'    => "#loadimages",
261             'onclick' => rcmail_output::JS_OBJECT_NAME.".command('load-images')"
262         ),
263         rcube::Q($RCMAIL->gettext('showimages')));
83ba22 264
f5d2ee 265     // add link to save sender in addressbook and reload message
AM 266     if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) {
267         $msg .= ' ' . html::a(array(
268                 'href'    => "#alwaysload",
269                 'onclick' => rcmail_output::JS_OBJECT_NAME.".command('always-load')",
270                 'style'   => "white-space:nowrap"
271             ),
272             rcube::Q($RCMAIL->gettext(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
273     }
83ba22 274
f5d2ee 275     $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
AM 276
277     return html::div($attrib, $msg);
46cdbf 278 }
A 279
280 function rcmail_message_buttons()
281 {
cd4e50 282     global $RCMAIL, $MESSAGE;
46cdbf 283
f5d2ee 284     $delim = $RCMAIL->storage->get_hierarchy_delimiter();
AM 285     $dbox  = $RCMAIL->config->get('drafts_mbox');
46cdbf 286
f5d2ee 287     // the message is not a draft
cd4e50 288     if ($MESSAGE->folder != $dbox && strpos($MESSAGE->folder, $dbox.$delim) !== 0) {
f5d2ee 289         return '';
AM 290     }
46cdbf 291
f5d2ee 292     $attrib['id']    = 'message-buttons';
AM 293     $attrib['class'] = 'notice';
46cdbf 294
f5d2ee 295     $msg = rcube::Q($RCMAIL->gettext('isdraft')) . '&nbsp;';
AM 296     $msg .= html::a(array(
297             'href'    => "#edit",
298             'onclick' => rcmail_output::JS_OBJECT_NAME.".command('edit')"
299         ),
300         rcube::Q($RCMAIL->gettext('edit')));
46cdbf 301
f5d2ee 302     return html::div($attrib, $msg);
46cdbf 303 }
A 304
305 function rcmail_message_objects($attrib)
306 {
f5d2ee 307     global $RCMAIL, $MESSAGE;
46cdbf 308
f5d2ee 309     if (!$attrib['id'])
AM 310         $attrib['id'] = 'message-objects';
46cdbf 311
f5d2ee 312     $content = array(
AM 313         rcmail_message_buttons(),
314         rcmail_remote_objects_msg(),
315     );
46cdbf 316
f5d2ee 317     $plugin = $RCMAIL->plugins->exec_hook('message_objects',
AM 318         array('content' => $content, 'message' => $MESSAGE));
46cdbf 319
f5d2ee 320     $content = implode("\n", $plugin['content']);
46cdbf 321
f5d2ee 322     return html::div($attrib, $content);
a99968 323 }
A 324
325 function rcmail_contact_exists($email)
326 {
f5d2ee 327     global $RCMAIL;
a99968 328
f5d2ee 329     if ($email) {
AM 330         // @TODO: search in all address books?
331         $CONTACTS = $RCMAIL->get_address_book(-1, true);
ae80b5 332
f5d2ee 333         if (is_object($CONTACTS)) {
8716fc 334             $existing = $CONTACTS->search('email', $email, 1, false);
f5d2ee 335             if ($existing->count) {
AM 336                 return true;
337             }
338         }
ae80b5 339     }
a99968 340
f5d2ee 341     return false;
62e43d 342 }
4e17e6 343
384948 344 function rcmail_message_contactphoto($attrib)
TB 345 {
f5d2ee 346     global $RCMAIL, $MESSAGE;
384948 347
681ba6 348     $placeholder = $attrib['placeholder'] ? $RCMAIL->output->abs_url($attrib['placeholder'], true) : null;
827159 349     $placeholder = $RCMAIL->output->asset_url($placeholder ?: 'program/resources/blank.gif');
384948 350
f5d2ee 351     if ($MESSAGE->sender) {
AM 352         $photo_img = $RCMAIL->url(array(
353             '_task'   => 'addressbook',
354             '_action' => 'photo',
355             '_email'  => $MESSAGE->sender['mailto'],
356         ));
fcb7d4 357
681ba6 358         $attrib['onerror'] = "this.src = '$placeholder'";
b46edc 359     }
f5d2ee 360     else {
681ba6 361         $photo_img = $placeholder;
f5d2ee 362     }
AM 363
7fafb4 364     return html::img(array('src' => $photo_img, 'alt' => $RCMAIL->gettext('contactphoto')) + $attrib);
c64277 365 }