4 +-----------------------------------------------------------------------+
5 | program/steps/mail/show.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2009, The Roundcube Dev Team |
9 | Licensed under the GNU GPL |
12 | Display a mail message similar as a usual mail application does |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: show.inc 5801 2012-01-19 07:32:08Z alec $
22 $PRINT_MODE = $RCMAIL->action=='print' ? TRUE : FALSE;
24 // similar code as in program/steps/mail/get.inc
25 if ($uid = get_input_value('_uid', RCUBE_INPUT_GET)) {
26 $MESSAGE = new rcube_message($uid);
28 // if message not found (wrong UID)...
29 if (empty($MESSAGE->headers)) {
30 rcmail_message_error($uid);
33 $mbox_name = $IMAP->get_mailbox_name();
36 rcmail_check_safe($MESSAGE);
38 // set message charset as default
39 if (!empty($MESSAGE->headers->charset))
40 $IMAP->set_charset($MESSAGE->headers->charset);
42 $OUTPUT->set_pagetitle(abbreviate_string($MESSAGE->subject, 128, '...', true));
44 // give message uid to the client
45 $OUTPUT->set_env('uid', $MESSAGE->uid);
47 $OUTPUT->set_env('safemode', $MESSAGE->is_safe);
48 $OUTPUT->set_env('sender', $MESSAGE->sender['string']);
49 $OUTPUT->set_env('permaurl', rcmail_url('show', array('_uid' => $MESSAGE->uid, '_mbox' => $mbox_name)));
50 $OUTPUT->set_env('delimiter', $IMAP->get_hierarchy_delimiter());
51 $OUTPUT->set_env('mailbox', $mbox_name);
52 if ($CONFIG['drafts_mbox']) {
53 $OUTPUT->set_env('drafts_mailbox', $CONFIG['drafts_mbox']);
56 // mimetypes supported by the browser (default settings)
57 $mimetypes = $RCMAIL->config->get('client_mimetypes', 'text/plain,text/html,text/xml,image/jpeg,image/gif,image/png,application/x-javascript,application/pdf,application/x-shockwave-flash');
58 $OUTPUT->set_env('mimetypes', is_string($mimetypes) ? explode(',', $mimetypes) : (array)$mimetypes);
60 if ($CONFIG['trash_mbox'])
61 $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']);
62 if ($CONFIG['flag_for_deletion'])
63 $OUTPUT->set_env('flag_for_deletion', true);
64 if ($CONFIG['read_when_deleted'])
65 $OUTPUT->set_env('read_when_deleted', true);
66 if ($CONFIG['skip_deleted'])
67 $OUTPUT->set_env('skip_deleted', true);
68 if ($CONFIG['display_next'])
69 $OUTPUT->set_env('display_next', true);
70 if ($MESSAGE->headers->others['list-post'])
71 $OUTPUT->set_env('list_post', true);
72 if ($CONFIG['forward_attachment'])
73 $OUTPUT->set_env('forward_attachment', true);
75 if (!$OUTPUT->ajax_call)
76 $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash',
77 'movingmessage', 'deletingmessage');
79 // check for unset disposition notification
80 if ($MESSAGE->headers->mdn_to
81 && empty($MESSAGE->headers->flags['MDNSENT'])
82 && empty($MESSAGE->headers->flags['SEEN'])
83 && ($IMAP->check_permflag('MDNSENT') || $IMAP->check_permflag('*'))
84 && $mbox_name != $CONFIG['drafts_mbox']
85 && $mbox_name != $CONFIG['sent_mbox']
87 $mdn_cfg = intval($CONFIG['mdn_requests']);
89 if ($mdn_cfg == 1 || (($mdn_cfg == 3 || $mdn_cfg == 4) && rcmail_contact_exists($MESSAGE->sender['mailto']))) {
91 if (rcmail_send_mdn($MESSAGE, $smtp_error))
92 $OUTPUT->show_message('receiptsent', 'confirmation');
94 $OUTPUT->show_message($smtp_error['label'], 'error', $smtp_error['vars']);
96 $OUTPUT->show_message('errorsendingreceipt', 'error');
98 else if ($mdn_cfg != 2 && $mdn_cfg != 4) {
100 $OUTPUT->add_label('mdnrequest');
101 $OUTPUT->set_env('mdn_request', true);
105 if (empty($MESSAGE->headers->flags['SEEN'])
106 && ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0))
108 $RCMAIL->plugins->exec_hook('message_read', array('uid' => $MESSAGE->uid,
109 'mailbox' => $mbox_name, 'message' => $MESSAGE));
115 function rcmail_message_attachments($attrib)
117 global $PRINT_MODE, $MESSAGE;
121 if (sizeof($MESSAGE->attachments)) {
122 foreach ($MESSAGE->attachments as $attach_prop) {
124 $ol .= html::tag('li', null, sprintf("%s (%s)", Q($attach_prop->filename), Q(show_bytes($attach_prop->size))));
127 if (mb_strlen($attach_prop->filename) > 50) {
128 $filename = abbreviate_string($attach_prop->filename, 50);
129 $title = $attach_prop->filename;
132 $filename = $attach_prop->filename;
136 $ol .= html::tag('li', null,
138 'href' => $MESSAGE->get_part_url($attach_prop->mime_id, false),
139 'onclick' => sprintf(
140 'return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)',
142 $attach_prop->mime_id,
143 rcmail_fix_mimetype($attach_prop->mimetype)),
144 'title' => Q($title),
150 $out = html::tag('ul', $attrib, $ol, html::$common_attrib);
156 function rcmail_remote_objects_msg()
158 global $MESSAGE, $RCMAIL;
160 $attrib['id'] = 'remote-objects-message';
161 $attrib['class'] = 'notice';
162 $attrib['style'] = 'display: none';
164 $msg = Q(rcube_label('blockedimages')) . ' ';
165 $msg .= html::a(array('href' => "#loadimages", 'onclick' => JS_OBJECT_NAME.".command('load-images')"), Q(rcube_label('showimages')));
167 // add link to save sender in addressbook and reload message
168 if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) {
169 $msg .= ' ' . html::a(array('href' => "#alwaysload", 'onclick' => JS_OBJECT_NAME.".command('always-load')", 'style' => "white-space:nowrap"),
170 Q(rcube_label(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
173 $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
174 return html::div($attrib, $msg);
177 function rcmail_message_buttons()
179 global $MESSAGE, $RCMAIL, $CONFIG;
181 $mbox = $RCMAIL->imap->get_mailbox_name();
182 $delim = $RCMAIL->imap->get_hierarchy_delimiter();
183 $dbox = $CONFIG['drafts_mbox'];
185 // the message is not a draft
186 if ($mbox != $dbox && strpos($mbox, $dbox.$delim) !== 0) {
190 $attrib['id'] = 'message-buttons';
191 $attrib['class'] = 'notice';
193 $msg = Q(rcube_label('isdraft')) . ' ';
194 $msg .= html::a(array('href' => "#edit", 'onclick' => JS_OBJECT_NAME.".command('edit')"), Q(rcube_label('edit')));
196 return html::div($attrib, $msg);
199 function rcmail_message_objects($attrib)
201 global $RCMAIL, $MESSAGE;
204 $attrib['id'] = 'message-objects';
207 rcmail_message_buttons(),
208 rcmail_remote_objects_msg(),
211 $plugin = $RCMAIL->plugins->exec_hook('message_objects',
212 array('content' => $content, 'message' => $MESSAGE));
214 $content = implode("\n", $plugin['content']);
216 return html::div($attrib, $content);
219 function rcmail_contact_exists($email)
224 // @TODO: search in all address books?
225 $CONTACTS = $RCMAIL->get_address_book(null, true);
226 $existing = $CONTACTS->search('email', $email, true, false);
227 if ($existing->count)
235 $OUTPUT->add_handlers(array(
236 'messageattachments' => 'rcmail_message_attachments',
237 'mailboxname' => 'rcmail_mailbox_name_display',
238 'messageobjects' => 'rcmail_message_objects',
242 if ($RCMAIL->action=='print' && $OUTPUT->template_exists('messageprint'))
243 $OUTPUT->send('messageprint', false);
244 else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
245 $OUTPUT->send('messagepreview', false);
247 $OUTPUT->send('message', false);
250 // mark message as read
251 if ($MESSAGE && $MESSAGE->headers && empty($MESSAGE->headers->flags['SEEN']) &&
252 ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0)))
254 if ($IMAP->set_flag($MESSAGE->uid, 'SEEN')) {
255 if ($count = rcmail_get_unseen_count($mbox_name)) {
256 rcmail_set_unseen_count($mbox_name, $count - 1);