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