comparison program/steps/mail/show.inc @ 0:4681f974d28b

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:52:31 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4681f974d28b
1 <?php
2
3 /**
4 +-----------------------------------------------------------------------+
5 | program/steps/mail/show.inc |
6 | |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2013, 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 | Display a mail message similar as a usual mail application does |
16 | |
17 +-----------------------------------------------------------------------+
18 | Author: Thomas Bruederli <roundcube@gmail.com> |
19 +-----------------------------------------------------------------------+
20 */
21
22 $PRINT_MODE = $RCMAIL->action == 'print';
23
24 // Read browser capabilities and store them in session
25 if ($caps = rcube_utils::get_input_value('_caps', rcube_utils::INPUT_GET)) {
26 $browser_caps = array();
27 foreach (explode(',', $caps) as $cap) {
28 $cap = explode('=', $cap);
29 $browser_caps[$cap[0]] = $cap[1];
30 }
31 $_SESSION['browser_caps'] = $browser_caps;
32 }
33
34 $msg_id = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_GET);
35 $uid = preg_replace('/\.[0-9.]+$/', '', $msg_id);
36 $mbox_name = $RCMAIL->storage->get_folder();
37
38 // similar code as in program/steps/mail/get.inc
39 if ($uid) {
40 // set message format (need to be done before rcube_message construction)
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;
45 }
46 else if (isset($_SESSION['msg_formats'][$mbox_name.':'.$uid])) {
47 $RCMAIL->config->set('prefer_html', $_SESSION['msg_formats'][$mbox_name.':'.$uid]);
48 }
49
50 $MESSAGE = new rcube_message($msg_id, $mbox_name, intval($_GET['_safe']));
51
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
68 $OUTPUT->set_env('uid', $msg_id);
69 $OUTPUT->set_env('safemode', $MESSAGE->is_safe);
70 $OUTPUT->set_env('message_context', $MESSAGE->context);
71 $OUTPUT->set_env('sender', $MESSAGE->sender['string']);
72 $OUTPUT->set_env('mailbox', $mbox_name);
73 $OUTPUT->set_env('username', $RCMAIL->get_user_name());
74 $OUTPUT->set_env('permaurl', $RCMAIL->url(array('_action' => 'show', '_uid' => $msg_id, '_mbox' => $mbox_name)));
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 $OUTPUT->set_env('mimetypes', rcmail_supported_mimetypes());
83
84 // set configuration
85 $RCMAIL->set_env_config(array('delete_junk', 'flag_for_deletion', 'read_when_deleted',
86 'skip_deleted', 'display_next', 'forward_attachment'));
87
88 // set special folders
89 foreach (array('drafts', 'trash', 'junk') as $mbox) {
90 if ($folder = $RCMAIL->config->get($mbox . '_mbox')) {
91 $OUTPUT->set_env($mbox . '_mailbox', $folder);
92 }
93 }
94
95 if ($MESSAGE->has_html_part()) {
96 $prefer_html = $RCMAIL->config->get('prefer_html');
97 $OUTPUT->set_env('optional_format', $prefer_html ? 'text' : 'html');
98 }
99
100 if (!$OUTPUT->ajax_call) {
101 $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash',
102 'movingmessage', 'deletingmessage', 'markingmessage', 'replyall', 'replylist');
103 }
104
105 // check for unset disposition notification
106 if ($MESSAGE->headers->mdn_to
107 && $MESSAGE->context === null
108 && empty($MESSAGE->headers->flags['MDNSENT'])
109 && empty($MESSAGE->headers->flags['SEEN'])
110 && ($RCMAIL->storage->check_permflag('MDNSENT') || $RCMAIL->storage->check_permflag('*'))
111 && $mbox_name != $RCMAIL->config->get('drafts_mbox')
112 && $mbox_name != $RCMAIL->config->get('sent_mbox')
113 ) {
114 $mdn_cfg = intval($RCMAIL->config->get('mdn_requests'));
115
116 if ($mdn_cfg == 1 || (($mdn_cfg == 3 || $mdn_cfg == 4) && rcmail_contact_exists($MESSAGE->sender['mailto']))) {
117 // Send MDN
118 if (rcmail_send_mdn($MESSAGE, $smtp_error))
119 $OUTPUT->show_message('receiptsent', 'confirmation');
120 else if ($smtp_error)
121 $OUTPUT->show_message($smtp_error['label'], 'error', $smtp_error['vars']);
122 else
123 $OUTPUT->show_message('errorsendingreceipt', 'error');
124 }
125 else if ($mdn_cfg != 2 && $mdn_cfg != 4) {
126 // Ask user
127 $OUTPUT->add_label('mdnrequest');
128 $OUTPUT->set_env('mdn_request', true);
129 }
130 }
131
132 if (empty($MESSAGE->headers->flags['SEEN']) && $MESSAGE->context === null) {
133 $v = intval($RCMAIL->config->get('mail_read_time'));
134 if ($v > 0) {
135 $OUTPUT->set_env('mail_read_time', $v);
136 }
137 else if ($v == 0) {
138 $RCMAIL->output->command('set_unread_message', $MESSAGE->uid, $mbox_name);
139 $RCMAIL->plugins->exec_hook('message_read', array(
140 'uid' => $MESSAGE->uid,
141 'mailbox' => $mbox_name,
142 'message' => $MESSAGE,
143 ));
144
145 $set_seen_flag = true;
146 }
147 }
148 }
149
150
151 $OUTPUT->add_handlers(array(
152 'messageattachments' => 'rcmail_message_attachments',
153 'mailboxname' => 'rcmail_mailbox_name_display',
154 'messageobjects' => 'rcmail_message_objects',
155 'contactphoto' => 'rcmail_message_contactphoto',
156 ));
157
158
159 if ($RCMAIL->action == 'print' && $OUTPUT->template_exists('messageprint'))
160 $OUTPUT->send('messageprint', false);
161 else if ($RCMAIL->action == 'preview' && $OUTPUT->template_exists('messagepreview'))
162 $OUTPUT->send('messagepreview', false);
163 else
164 $OUTPUT->send('message', false);
165
166
167 // mark message as read
168 if (!empty($set_seen_flag)) {
169 if ($RCMAIL->storage->set_flag($MESSAGE->uid, 'SEEN', $mbox_name)) {
170 if ($count = rcmail_get_unseen_count($mbox_name)) {
171 rcmail_set_unseen_count($mbox_name, $count - 1);
172 }
173 }
174 }
175
176 exit;
177
178
179 function rcmail_message_attachments($attrib)
180 {
181 global $PRINT_MODE, $MESSAGE, $RCMAIL;
182
183 $out = $ol = '';
184 $attachments = array();
185
186 if (count($MESSAGE->attachments)) {
187 foreach ($MESSAGE->attachments as $attach_prop) {
188 $filename = rcmail_attachment_name($attach_prop, true);
189 $filesize = $RCMAIL->message_part_size($attach_prop);
190
191 if ($PRINT_MODE) {
192 $ol .= html::tag('li', array('id' => 'attach' . $attach_prop->mime_id),
193 rcube::Q(sprintf("%s (%s)", $filename, $filesize)));
194 }
195 else {
196 if ($attrib['maxlength'] && mb_strlen($filename) > $attrib['maxlength']) {
197 $title = $filename;
198 $filename = abbreviate_string($filename, $attrib['maxlength']);
199 }
200 else {
201 $title = '';
202 }
203
204 $size = ' ' . html::span('attachment-size', '(' . rcube::Q($filesize) . ')');
205 $mimetype = rcmail_fix_mimetype($attach_prop->mimetype);
206 $class = rcube_utils::file2class($mimetype, $filename);
207 $id = 'attach' . $attach_prop->mime_id;
208 $link = html::a(array(
209 'href' => $MESSAGE->get_part_url($attach_prop->mime_id, false),
210 'onclick' => sprintf('return %s.command(\'load-attachment\',\'%s\',this)',
211 rcmail_output::JS_OBJECT_NAME, $attach_prop->mime_id),
212 'onmouseover' => $title ? '' : 'rcube_webmail.long_subject_title_ex(this, 0)',
213 'title' => $title,
214 ), rcube::Q($filename) . $size);
215
216 $ol .= html::tag('li', array('class' => $class, 'id' => $id), $link);
217
218 $attachments[$attach_prop->mime_id] = $mimetype;
219 }
220 }
221
222 $out = html::tag('ul', $attrib, $ol, html::$common_attrib);
223
224 $RCMAIL->output->set_env('attachments', $attachments);
225 $RCMAIL->output->add_gui_object('attachments', $attrib['id']);
226 }
227
228 return $out;
229 }
230
231 function rcmail_remote_objects_msg()
232 {
233 global $MESSAGE, $RCMAIL;
234
235 $attrib['id'] = 'remote-objects-message';
236 $attrib['class'] = 'notice';
237 $attrib['style'] = 'display: none';
238
239 $msg = rcube::Q($RCMAIL->gettext('blockedimages')) . '&nbsp;';
240 $msg .= html::a(array(
241 'href' => "#loadimages",
242 'onclick' => rcmail_output::JS_OBJECT_NAME.".command('load-images')"
243 ),
244 rcube::Q($RCMAIL->gettext('showimages')));
245
246 // add link to save sender in addressbook and reload message
247 if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) {
248 $msg .= ' ' . html::a(array(
249 'href' => "#alwaysload",
250 'onclick' => rcmail_output::JS_OBJECT_NAME.".command('always-load')",
251 'style' => "white-space:nowrap"
252 ),
253 rcube::Q($RCMAIL->gettext(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
254 }
255
256 $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
257
258 return html::div($attrib, $msg);
259 }
260
261 function rcmail_message_buttons()
262 {
263 global $RCMAIL, $MESSAGE;
264
265 $delim = $RCMAIL->storage->get_hierarchy_delimiter();
266 $dbox = $RCMAIL->config->get('drafts_mbox');
267
268 // the message is not a draft
269 if ($MESSAGE->folder != $dbox && strpos($MESSAGE->folder, $dbox.$delim) !== 0) {
270 return '';
271 }
272
273 $attrib['id'] = 'message-buttons';
274 $attrib['class'] = 'notice';
275
276 $msg = rcube::Q($RCMAIL->gettext('isdraft')) . '&nbsp;';
277 $msg .= html::a(array(
278 'href' => "#edit",
279 'onclick' => rcmail_output::JS_OBJECT_NAME.".command('edit')"
280 ),
281 rcube::Q($RCMAIL->gettext('edit')));
282
283 return html::div($attrib, $msg);
284 }
285
286 function rcmail_message_objects($attrib)
287 {
288 global $RCMAIL, $MESSAGE;
289
290 if (!$attrib['id'])
291 $attrib['id'] = 'message-objects';
292
293 $content = array(
294 rcmail_message_buttons(),
295 rcmail_remote_objects_msg(),
296 );
297
298 $plugin = $RCMAIL->plugins->exec_hook('message_objects',
299 array('content' => $content, 'message' => $MESSAGE));
300
301 $content = implode("\n", $plugin['content']);
302
303 return html::div($attrib, $content);
304 }
305
306 function rcmail_contact_exists($email)
307 {
308 global $RCMAIL;
309
310 if ($email) {
311 // @TODO: search in all address books?
312 $CONTACTS = $RCMAIL->get_address_book(-1, true);
313
314 if (is_object($CONTACTS)) {
315 $existing = $CONTACTS->search('email', $email, 1, false);
316 if ($existing->count) {
317 return true;
318 }
319 }
320 }
321
322 return false;
323 }
324
325 function rcmail_message_contactphoto($attrib)
326 {
327 global $RCMAIL, $MESSAGE;
328
329 $placeholder = $attrib['placeholder'] ? $RCMAIL->output->abs_url($attrib['placeholder'], true) : null;
330 $placeholder = $RCMAIL->output->asset_url($placeholder ?: 'program/resources/blank.gif');
331
332 if ($MESSAGE->sender) {
333 $photo_img = $RCMAIL->url(array(
334 '_task' => 'addressbook',
335 '_action' => 'photo',
336 '_email' => $MESSAGE->sender['mailto'],
337 ));
338
339 $attrib['onerror'] = "this.src = '$placeholder'";
340 }
341 else {
342 $photo_img = $placeholder;
343 }
344
345 return html::img(array('src' => $photo_img, 'alt' => $RCMAIL->gettext('contactphoto')) + $attrib);
346 }