4 +-----------------------------------------------------------------------+
5 | program/steps/mail/show.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2009, Roundcube Dev. - Switzerland |
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 4294 2010-12-01 09:52:23Z 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 send_nocacheing_headers();
35 $mbox_name = $IMAP->get_mailbox_name();
38 rcmail_check_safe($MESSAGE);
40 // set message charset as default
41 if (!empty($MESSAGE->headers->charset))
42 $IMAP->set_charset($MESSAGE->headers->charset);
44 $OUTPUT->set_pagetitle(abbreviate_string($MESSAGE->subject, 128, '...', true));
46 // give message uid to the client
47 $OUTPUT->set_env('uid', $MESSAGE->uid);
49 $OUTPUT->set_env('safemode', $MESSAGE->is_safe);
50 $OUTPUT->set_env('sender', $MESSAGE->sender['string']);
51 $OUTPUT->set_env('permaurl', rcmail_url('show', array('_uid' => $MESSAGE->uid, '_mbox' => $mbox_name)));
52 $OUTPUT->set_env('delimiter', $IMAP->get_hierarchy_delimiter());
53 $OUTPUT->set_env('mailbox', $mbox_name);
55 if ($CONFIG['trash_mbox'])
56 $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']);
57 if ($CONFIG['flag_for_deletion'])
58 $OUTPUT->set_env('flag_for_deletion', true);
59 if ($CONFIG['read_when_deleted'])
60 $OUTPUT->set_env('read_when_deleted', true);
61 if ($CONFIG['skip_deleted'])
62 $OUTPUT->set_env('skip_deleted', true);
63 if ($CONFIG['display_next'])
64 $OUTPUT->set_env('display_next', true);
65 if ($MESSAGE->headers->others['list-post'])
66 $OUTPUT->set_env('list_post', true);
68 if (!$OUTPUT->ajax_call)
69 $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash',
70 'movingmessage', 'deletingmessage');
72 // check for unset disposition notification
73 if ($MESSAGE->headers->mdn_to &&
74 !$MESSAGE->headers->mdn_sent && !$MESSAGE->headers->seen &&
75 ($IMAP->check_permflag('MDNSENT') || $IMAP->check_permflag('*')) &&
76 $mbox_name != $CONFIG['drafts_mbox'] &&
77 $mbox_name != $CONFIG['sent_mbox'])
79 $mdn_cfg = intval($CONFIG['mdn_requests']);
81 if ($mdn_cfg == 1 || (($mdn_cfg == 3 || $mdn_cfg == 4) && rcmail_contact_exists($MESSAGE->sender['mailto']))) {
83 if (rcmail_send_mdn($MESSAGE, $smtp_error))
84 $OUTPUT->show_message('receiptsent', 'confirmation');
86 $OUTPUT->show_message($smtp_error['label'], 'error', $smtp_error['vars']);
88 $OUTPUT->show_message('errorsendingreceipt', 'error');
90 else if ($mdn_cfg != 2 && $mdn_cfg != 4) {
92 $OUTPUT->add_label('mdnrequest');
93 $OUTPUT->set_env('mdn_request', true);
97 if (!$MESSAGE->headers->seen && ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0)))
98 $RCMAIL->plugins->exec_hook('message_read', array('uid' => $MESSAGE->uid,
99 'mailbox' => $mbox_name, 'message' => $MESSAGE));
104 function rcmail_message_attachments($attrib)
106 global $PRINT_MODE, $MESSAGE;
110 if (sizeof($MESSAGE->attachments)) {
111 foreach ($MESSAGE->attachments as $attach_prop) {
113 $ol .= html::tag('li', null, sprintf("%s (%s)", Q($attach_prop->filename), Q(show_bytes($attach_prop->size))));
116 if (mb_strlen($attach_prop->filename) > 50) {
117 $filename = abbreviate_string($attach_prop->filename, 50);
118 $title = $attach_prop->filename;
121 $filename = $attach_prop->filename;
125 $ol .= html::tag('li', null,
127 'href' => $MESSAGE->get_part_url($attach_prop->mime_id),
128 'onclick' => sprintf(
129 'return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)',
131 $attach_prop->mime_id,
132 rcmail_fix_mimetype($attach_prop->mimetype)),
133 'title' => Q($title),
139 $out = html::tag('ul', $attrib, $ol, html::$common_attrib);
145 function rcmail_remote_objects_msg($attrib)
147 global $MESSAGE, $RCMAIL;
150 $attrib['id'] = 'rcmremoteobjmsg';
152 $msg = Q(rcube_label('blockedimages')) . ' ';
153 $msg .= html::a(array('href' => "#loadimages", 'onclick' => JS_OBJECT_NAME.".command('load-images')"), Q(rcube_label('showimages')));
155 // add link to save sender in addressbook and reload message
156 if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) {
157 $msg .= ' ' . html::a(array('href' => "#alwaysload", 'onclick' => JS_OBJECT_NAME.".command('always-load')", 'style' => "white-space:nowrap"),
158 Q(rcube_label(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
161 $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
162 return html::div($attrib, $msg);
165 function rcmail_contact_exists($email)
170 // @TODO: search in all address books?
171 $CONTACTS = $RCMAIL->get_address_book(null, true);
172 $existing = $CONTACTS->search('email', $email, true, false);
173 if ($existing->count)
181 $OUTPUT->add_handlers(array(
182 'messageattachments' => 'rcmail_message_attachments',
183 'mailboxname' => 'rcmail_mailbox_name_display',
184 'blockedobjects' => 'rcmail_remote_objects_msg'));
187 if ($RCMAIL->action=='print' && $OUTPUT->template_exists('messageprint'))
188 $OUTPUT->send('messageprint', false);
189 else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
190 $OUTPUT->send('messagepreview', false);
192 $OUTPUT->send('message', false);
195 // mark message as read
196 if ($MESSAGE && $MESSAGE->headers && !$MESSAGE->headers->seen &&
197 ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0)))
199 if ($IMAP->set_flag($MESSAGE->uid, 'SEEN')) {
200 if ($count = rcmail_get_unseen_count($mbox_name)) {
201 rcmail_set_unseen_count($mbox_name, $count - 1);