Aleksander Machniak
2015-05-07 6ccd4c54bcc4cb77365defabe8bbe7d10b2620d4
commit | author | age
4e17e6 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
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
a02c77 22 $PRINT_MODE = $RCMAIL->action == 'print' ? TRUE : FALSE;
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
f5d2ee 49     $MESSAGE = new rcube_message($uid);
AM 50
51     // if message not found (wrong UID)...
52     if (empty($MESSAGE->headers)) {
53         rcmail_message_error($uid);
54     }
55
56
57     // show images?
58     rcmail_check_safe($MESSAGE);
59
60     // set message charset as default
61     if (!empty($MESSAGE->headers->charset)) {
62         $RCMAIL->storage->set_charset($MESSAGE->headers->charset);
63     }
64
65     $OUTPUT->set_pagetitle(abbreviate_string($MESSAGE->subject, 128, '...', true));
66
67     // set message environment
68     $OUTPUT->set_env('uid', $MESSAGE->uid);
69     $OUTPUT->set_env('safemode', $MESSAGE->is_safe);
70     $OUTPUT->set_env('sender', $MESSAGE->sender['string']);
71     $OUTPUT->set_env('mailbox', $mbox_name);
72     $OUTPUT->set_env('permaurl', $RCMAIL->url(array('_action' => 'show', '_uid' => $MESSAGE->uid, '_mbox' => $mbox_name)));
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',
39bd9b 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
105         if (!$RCMAIL->config->get('im_convert_path')) {
106             unset($mimetypes[$key]);
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     ) {
bbce9f 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         ));
bbce9f 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
bbce9f 180 if (!empty($set_seen_flag)) {
f5d2ee 181     if ($RCMAIL->storage->set_flag($MESSAGE->uid, 'SEEN')) {
AM 182         if ($count = rcmail_get_unseen_count($mbox_name)) {
183             rcmail_set_unseen_count($mbox_name, $count - 1);
184         }
185     }
186 }
187
188 exit;
4e17e6 189
T 190
191
192 function rcmail_message_attachments($attrib)
8fa58e 193 {
f5d2ee 194     global $PRINT_MODE, $MESSAGE, $RCMAIL;
83ba22 195
f5d2ee 196     $out = $ol = '';
AM 197     $attachments = array();
4e17e6 198
f5d2ee 199     if (sizeof($MESSAGE->attachments)) {
AM 200         foreach ($MESSAGE->attachments as $attach_prop) {
201             $filename = rcmail_attachment_name($attach_prop, true);
203ee4 202
f5d2ee 203             if ($PRINT_MODE) {
AM 204                 $size = $RCMAIL->message_part_size($attach_prop);
205                 $ol .= html::tag('li', null, rcube::Q(sprintf("%s (%s)", $filename, $size)));
206             }
207             else {
208                 if ($attrib['maxlength'] && mb_strlen($filename) > $attrib['maxlength']) {
209                     $title    = $filename;
210                     $filename = abbreviate_string($filename, $attrib['maxlength']);
211                 }
212                 else {
213                     $title = '';
214                 }
215
216                 $mimetype = rcmail_fix_mimetype($attach_prop->mimetype);
217                 $class    = rcube_utils::file2class($mimetype, $filename);
218                 $id       = 'attach' . $attach_prop->mime_id;
219                 $link     = html::a(array(
220                     'href'        => $MESSAGE->get_part_url($attach_prop->mime_id, false),
221                     'onclick'     => sprintf('return %s.command(\'load-attachment\',\'%s\',this)',
222                         rcmail_output::JS_OBJECT_NAME, $attach_prop->mime_id),
223                     'onmouseover' => $title ? '' : 'rcube_webmail.long_subject_title_ex(this, 0)',
224                     'title'       => rcube::Q($title),
225                     ), rcube::Q($filename));
226
227                 $ol .= html::tag('li', array('class' => $class, 'id' => $id), $link);
228
229                 $attachments[$attach_prop->mime_id] = $mimetype;
230             }
0c2596 231         }
A 232
f5d2ee 233         $out = html::tag('ul', $attrib, $ol, html::$common_attrib);
bc2c43 234
f5d2ee 235         $RCMAIL->output->set_env('attachments', $attachments);
8fa58e 236     }
4e17e6 237
f5d2ee 238     return $out;
8fa58e 239 }
4e17e6 240
46cdbf 241 function rcmail_remote_objects_msg()
62e43d 242 {
f5d2ee 243     global $MESSAGE, $RCMAIL;
83ba22 244
f5d2ee 245     $attrib['id']    = 'remote-objects-message';
AM 246     $attrib['class'] = 'notice';
247     $attrib['style'] = 'display: none';
83ba22 248
f5d2ee 249     $msg = rcube::Q($RCMAIL->gettext('blockedimages')) . '&nbsp;';
AM 250     $msg .= html::a(array(
251             'href'    => "#loadimages",
252             'onclick' => rcmail_output::JS_OBJECT_NAME.".command('load-images')"
253         ),
254         rcube::Q($RCMAIL->gettext('showimages')));
83ba22 255
f5d2ee 256     // add link to save sender in addressbook and reload message
AM 257     if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) {
258         $msg .= ' ' . html::a(array(
259                 'href'    => "#alwaysload",
260                 'onclick' => rcmail_output::JS_OBJECT_NAME.".command('always-load')",
261                 'style'   => "white-space:nowrap"
262             ),
263             rcube::Q($RCMAIL->gettext(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
264     }
83ba22 265
f5d2ee 266     $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
AM 267
268     return html::div($attrib, $msg);
46cdbf 269 }
A 270
271 function rcmail_message_buttons()
272 {
bc42d0 273     global $RCMAIL, $MESSAGE;
46cdbf 274
f5d2ee 275     $delim = $RCMAIL->storage->get_hierarchy_delimiter();
AM 276     $dbox  = $RCMAIL->config->get('drafts_mbox');
46cdbf 277
f5d2ee 278     // the message is not a draft
bc42d0 279     if ($MESSAGE->folder != $dbox && strpos($MESSAGE->folder, $dbox.$delim) !== 0) {
f5d2ee 280         return '';
AM 281     }
46cdbf 282
f5d2ee 283     $attrib['id']    = 'message-buttons';
AM 284     $attrib['class'] = 'notice';
46cdbf 285
f5d2ee 286     $msg = rcube::Q($RCMAIL->gettext('isdraft')) . '&nbsp;';
AM 287     $msg .= html::a(array(
288             'href'    => "#edit",
289             'onclick' => rcmail_output::JS_OBJECT_NAME.".command('edit')"
290         ),
291         rcube::Q($RCMAIL->gettext('edit')));
46cdbf 292
f5d2ee 293     return html::div($attrib, $msg);
46cdbf 294 }
A 295
296 function rcmail_message_objects($attrib)
297 {
f5d2ee 298     global $RCMAIL, $MESSAGE;
46cdbf 299
f5d2ee 300     if (!$attrib['id'])
AM 301         $attrib['id'] = 'message-objects';
46cdbf 302
f5d2ee 303     $content = array(
AM 304         rcmail_message_buttons(),
305         rcmail_remote_objects_msg(),
306     );
46cdbf 307
f5d2ee 308     $plugin = $RCMAIL->plugins->exec_hook('message_objects',
AM 309         array('content' => $content, 'message' => $MESSAGE));
46cdbf 310
f5d2ee 311     $content = implode("\n", $plugin['content']);
46cdbf 312
f5d2ee 313     return html::div($attrib, $content);
a99968 314 }
A 315
316 function rcmail_contact_exists($email)
317 {
f5d2ee 318     global $RCMAIL;
a99968 319
f5d2ee 320     if ($email) {
AM 321         // @TODO: search in all address books?
322         $CONTACTS = $RCMAIL->get_address_book(-1, true);
ae80b5 323
f5d2ee 324         if (is_object($CONTACTS)) {
AM 325             $existing = $CONTACTS->search('email', $email, true, false);
326             if ($existing->count) {
327                 return true;
328             }
329         }
ae80b5 330     }
a99968 331
f5d2ee 332     return false;
62e43d 333 }
4e17e6 334
384948 335 function rcmail_message_contactphoto($attrib)
TB 336 {
f5d2ee 337     global $RCMAIL, $MESSAGE;
384948 338
f5d2ee 339     $placeholder = $attrib['placeholder'] ? $RCMAIL->config->get('skin_path') . $attrib['placeholder'] : null;
384948 340
f5d2ee 341     if ($MESSAGE->sender) {
AM 342         $photo_img = $RCMAIL->url(array(
343             '_task'   => 'addressbook',
344             '_action' => 'photo',
345             '_email'  => $MESSAGE->sender['mailto'],
346         ));
1fac78 347
AM 348         $attrib['onerror'] = "this.src = '" . ($placeholder ? $placeholder : 'program/resources/blank.gif') . "'";
b46edc 349     }
f5d2ee 350     else {
AM 351         $photo_img = $placeholder ? $placeholder : 'program/resources/blank.gif';
352     }
353
354     return html::img(array('src' => $photo_img) + $attrib);
c64277 355 }