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', |
|
83 |
'skip_deleted', 'display_next', 'compose_extwin', 'forward_attachment')); |
|
84 |
|
|
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 |
) { |
|
151 |
$RCMAIL->plugins->exec_hook('message_read', array( |
|
152 |
'uid' => $MESSAGE->uid, |
|
153 |
'mailbox' => $mbox_name, |
|
154 |
'message' => $MESSAGE, |
|
155 |
)); |
|
156 |
} |
cc97ea
|
157 |
} |
f5d2ee
|
158 |
|
AM |
159 |
|
|
160 |
$OUTPUT->add_handlers(array( |
|
161 |
'messageattachments' => 'rcmail_message_attachments', |
|
162 |
'mailboxname' => 'rcmail_mailbox_name_display', |
|
163 |
'messageobjects' => 'rcmail_message_objects', |
|
164 |
'contactphoto' => 'rcmail_message_contactphoto', |
|
165 |
)); |
|
166 |
|
|
167 |
|
|
168 |
if ($RCMAIL->action == 'print' && $OUTPUT->template_exists('messageprint')) |
|
169 |
$OUTPUT->send('messageprint', false); |
|
170 |
else if ($RCMAIL->action == 'preview' && $OUTPUT->template_exists('messagepreview')) |
|
171 |
$OUTPUT->send('messagepreview', false); |
|
172 |
else |
|
173 |
$OUTPUT->send('message', false); |
|
174 |
|
|
175 |
|
|
176 |
// mark message as read |
|
177 |
if ($MESSAGE && $MESSAGE->headers && empty($MESSAGE->headers->flags['SEEN']) && |
|
178 |
($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($RCMAIL->config->get('preview_pane_mark_read')) == 0)) |
|
179 |
) { |
|
180 |
if ($RCMAIL->storage->set_flag($MESSAGE->uid, 'SEEN')) { |
|
181 |
if ($count = rcmail_get_unseen_count($mbox_name)) { |
|
182 |
rcmail_set_unseen_count($mbox_name, $count - 1); |
|
183 |
} |
|
184 |
} |
|
185 |
} |
|
186 |
|
|
187 |
exit; |
4e17e6
|
188 |
|
T |
189 |
|
|
190 |
|
|
191 |
function rcmail_message_attachments($attrib) |
8fa58e
|
192 |
{ |
f5d2ee
|
193 |
global $PRINT_MODE, $MESSAGE, $RCMAIL; |
83ba22
|
194 |
|
f5d2ee
|
195 |
$out = $ol = ''; |
AM |
196 |
$attachments = array(); |
4e17e6
|
197 |
|
f5d2ee
|
198 |
if (sizeof($MESSAGE->attachments)) { |
AM |
199 |
foreach ($MESSAGE->attachments as $attach_prop) { |
|
200 |
$filename = rcmail_attachment_name($attach_prop, true); |
203ee4
|
201 |
|
f5d2ee
|
202 |
if ($PRINT_MODE) { |
AM |
203 |
$size = $RCMAIL->message_part_size($attach_prop); |
|
204 |
$ol .= html::tag('li', null, rcube::Q(sprintf("%s (%s)", $filename, $size))); |
|
205 |
} |
|
206 |
else { |
|
207 |
if ($attrib['maxlength'] && mb_strlen($filename) > $attrib['maxlength']) { |
|
208 |
$title = $filename; |
|
209 |
$filename = abbreviate_string($filename, $attrib['maxlength']); |
|
210 |
} |
|
211 |
else { |
|
212 |
$title = ''; |
|
213 |
} |
|
214 |
|
|
215 |
$mimetype = rcmail_fix_mimetype($attach_prop->mimetype); |
|
216 |
$class = rcube_utils::file2class($mimetype, $filename); |
|
217 |
$id = 'attach' . $attach_prop->mime_id; |
|
218 |
$link = html::a(array( |
|
219 |
'href' => $MESSAGE->get_part_url($attach_prop->mime_id, false), |
|
220 |
'onclick' => sprintf('return %s.command(\'load-attachment\',\'%s\',this)', |
|
221 |
rcmail_output::JS_OBJECT_NAME, $attach_prop->mime_id), |
|
222 |
'onmouseover' => $title ? '' : 'rcube_webmail.long_subject_title_ex(this, 0)', |
|
223 |
'title' => rcube::Q($title), |
|
224 |
), rcube::Q($filename)); |
|
225 |
|
|
226 |
$ol .= html::tag('li', array('class' => $class, 'id' => $id), $link); |
|
227 |
|
|
228 |
$attachments[$attach_prop->mime_id] = $mimetype; |
|
229 |
} |
0c2596
|
230 |
} |
A |
231 |
|
f5d2ee
|
232 |
$out = html::tag('ul', $attrib, $ol, html::$common_attrib); |
bc2c43
|
233 |
|
f5d2ee
|
234 |
$RCMAIL->output->set_env('attachments', $attachments); |
8fa58e
|
235 |
} |
4e17e6
|
236 |
|
f5d2ee
|
237 |
return $out; |
8fa58e
|
238 |
} |
4e17e6
|
239 |
|
46cdbf
|
240 |
function rcmail_remote_objects_msg() |
62e43d
|
241 |
{ |
f5d2ee
|
242 |
global $MESSAGE, $RCMAIL; |
83ba22
|
243 |
|
f5d2ee
|
244 |
$attrib['id'] = 'remote-objects-message'; |
AM |
245 |
$attrib['class'] = 'notice'; |
|
246 |
$attrib['style'] = 'display: none'; |
83ba22
|
247 |
|
f5d2ee
|
248 |
$msg = rcube::Q($RCMAIL->gettext('blockedimages')) . ' '; |
AM |
249 |
$msg .= html::a(array( |
|
250 |
'href' => "#loadimages", |
|
251 |
'onclick' => rcmail_output::JS_OBJECT_NAME.".command('load-images')" |
|
252 |
), |
|
253 |
rcube::Q($RCMAIL->gettext('showimages'))); |
83ba22
|
254 |
|
f5d2ee
|
255 |
// add link to save sender in addressbook and reload message |
AM |
256 |
if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) { |
|
257 |
$msg .= ' ' . html::a(array( |
|
258 |
'href' => "#alwaysload", |
|
259 |
'onclick' => rcmail_output::JS_OBJECT_NAME.".command('always-load')", |
|
260 |
'style' => "white-space:nowrap" |
|
261 |
), |
|
262 |
rcube::Q($RCMAIL->gettext(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto']))))); |
|
263 |
} |
83ba22
|
264 |
|
f5d2ee
|
265 |
$RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']); |
AM |
266 |
|
|
267 |
return html::div($attrib, $msg); |
46cdbf
|
268 |
} |
A |
269 |
|
|
270 |
function rcmail_message_buttons() |
|
271 |
{ |
f5d2ee
|
272 |
global $RCMAIL; |
46cdbf
|
273 |
|
f5d2ee
|
274 |
$mbox = $RCMAIL->storage->get_folder(); |
AM |
275 |
$delim = $RCMAIL->storage->get_hierarchy_delimiter(); |
|
276 |
$dbox = $RCMAIL->config->get('drafts_mbox'); |
46cdbf
|
277 |
|
f5d2ee
|
278 |
// the message is not a draft |
AM |
279 |
if ($mbox != $dbox && strpos($mbox, $dbox.$delim) !== 0) { |
|
280 |
return ''; |
|
281 |
} |
46cdbf
|
282 |
|
f5d2ee
|
283 |
$attrib['id'] = 'message-buttons'; |
AM |
284 |
$attrib['class'] = 'notice'; |
46cdbf
|
285 |
|
f5d2ee
|
286 |
$msg = rcube::Q($RCMAIL->gettext('isdraft')) . ' '; |
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 |
'_alt' => $placeholder |
|
347 |
)); |
b46edc
|
348 |
} |
f5d2ee
|
349 |
else { |
AM |
350 |
$photo_img = $placeholder ? $placeholder : 'program/resources/blank.gif'; |
|
351 |
} |
|
352 |
|
|
353 |
return html::img(array('src' => $photo_img) + $attrib); |
c64277
|
354 |
} |