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 2933 2009-09-08 08:04:17Z alec $
22 $PRINT_MODE = $RCMAIL->action=='print' ? TRUE : FALSE;
24 // similar code as in program/steps/mail/get.inc
26 $MESSAGE = new rcube_message(get_input_value('_uid', RCUBE_INPUT_GET));
28 // if message not found (wrong UID)...
29 if (empty($MESSAGE->headers)) {
30 $OUTPUT->show_message('messageopenerror', 'error');
31 // ... display error or preview page
32 if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messageerror'))
33 $OUTPUT->send('messageerror');
34 else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
35 $OUTPUT->send('messagepreview');
36 // ... go back to the list
38 rcmail_overwrite_action('');
43 $mbox_name = $IMAP->get_mailbox_name();
46 rcmail_check_safe($MESSAGE);
48 // calculate Etag for this request
49 $etag = md5($MESSAGE->uid.$mbox_name.session_id()
50 .intval($MESSAGE->headers->mdn_sent)
51 .intval($MESSAGE->is_safe)
52 .(!empty($MESSAGE->attachments) ? intval($CONFIG['inline_images']) : '')
54 .$_SESSION['sort_col'].$_SESSION['sort_order']
55 .$IMAP->messagecount($mbox_name, 'ALL', true)
58 // allow caching, unless remote images are present
59 if ((bool)$MESSAGE->is_safe)
60 send_nocacheing_headers();
61 else if (empty($CONFIG['devel_mode']))
62 send_modified_header($_SESSION['login_time'], $etag, !$MESSAGE->headers->seen);
64 // set message charset as default
65 if (!empty($MESSAGE->headers->charset))
66 $IMAP->set_charset($MESSAGE->headers->charset);
68 $OUTPUT->set_pagetitle($MESSAGE->subject);
70 // give message uid to the client
71 $OUTPUT->set_env('uid', $MESSAGE->uid);
73 $OUTPUT->set_env('safemode', $MESSAGE->is_safe);
74 $OUTPUT->set_env('sender', $MESSAGE->sender['string']);
75 $OUTPUT->set_env('permaurl', rcmail_url('show', array('_uid' => $MESSAGE->uid, '_mbox' => $mbox_name)));
76 $OUTPUT->set_env('mailbox', $mbox_name);
78 if ($CONFIG['trash_mbox'])
79 $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']);
80 if ($CONFIG['flag_for_deletion'])
81 $OUTPUT->set_env('flag_for_deletion', true);
82 if ($CONFIG['read_when_deleted'])
83 $OUTPUT->set_env('read_when_deleted', true);
84 if ($CONFIG['skip_deleted'])
85 $OUTPUT->set_env('skip_deleted', true);
86 if ($CONFIG['display_next'])
87 $OUTPUT->set_env('display_next', true);
89 if (!$OUTPUT->ajax_call)
90 $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash', 'movingmessage');
92 // check for unset disposition notification
93 if ($MESSAGE->headers->mdn_to &&
94 !$MESSAGE->headers->mdn_sent && !$MESSAGE->headers->seen &&
95 ($IMAP->check_permflag('MDNSENT') || $IMAP->check_permflag('*')) &&
96 $mbox_name != $CONFIG['drafts_mbox'] &&
97 $mbox_name != $CONFIG['sent_mbox'])
99 if (intval($CONFIG['mdn_requests']) === 1)
101 if (rcmail_send_mdn($MESSAGE->uid, $smtp_error))
102 $OUTPUT->show_message('receiptsent', 'confirmation');
103 else if ($smtp_error)
104 $OUTPUT->show_message($smtp_error['label'], 'error', $smtp_error['vars']);
106 $OUTPUT->show_message('errorsendingreceipt', 'error');
108 else if (empty($CONFIG['mdn_requests']))
110 $OUTPUT->add_label('mdnrequest');
111 $OUTPUT->set_env('mdn_request', true);
115 // get previous, first, next and last message UID
116 if ($RCMAIL->action != 'preview' && $RCMAIL->action != 'print')
118 $next = $prev = $first = $last = -1;
120 if ($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] != 'DESC'
121 && empty($_REQUEST['_search']) && !$IMAP->skip_deleted)
123 // this assumes that we are sorted by date_DESC
124 $cnt = $IMAP->messagecount();
125 $seq = $IMAP->get_id($MESSAGE->uid);
126 $MESSAGE->index = $cnt - $seq;
128 $prev = $IMAP->get_uid($seq + 1);
129 $first = $IMAP->get_uid($cnt);
130 $next = $IMAP->get_uid($seq - 1);
131 $last = $IMAP->get_uid(1);
135 // Only if we use custom sorting
136 $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
138 $MESSAGE->index = array_search($IMAP->get_id($MESSAGE->uid), $a_msg_index);
140 $prev = isset($a_msg_index[$MESSAGE->index-1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index-1]) : -1 ;
141 $first = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[0]) : -1;
142 $next = isset($a_msg_index[$MESSAGE->index+1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index+1]) : -1 ;
143 $last = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[count($a_msg_index)-1]) : -1;
147 $OUTPUT->set_env('prev_uid', $prev);
149 $OUTPUT->set_env('first_uid', $first);
151 $OUTPUT->set_env('next_uid', $next);
153 $OUTPUT->set_env('last_uid', $last);
156 if (!$MESSAGE->headers->seen)
157 $RCMAIL->plugins->exec_hook('message_read', array('uid' => $MESSAGE->uid,
158 'mailbox' => $IMAP->mailbox, 'message' => $MESSAGE));
163 function rcmail_message_attachments($attrib)
165 global $PRINT_MODE, $MESSAGE;
169 if (sizeof($MESSAGE->attachments)) {
170 foreach ($MESSAGE->attachments as $attach_prop) {
172 $ol .= html::tag('li', null, sprintf("%s (%s)", Q($attach_prop->filename), Q(show_bytes($attach_prop->size))));
175 if (mb_strlen($attach_prop->filename) > 50) {
176 $filename = abbreviate_string($attach_prop->filename, 50);
177 $title = $attach_prop->filename;
180 $filename = $attach_prop->filename;
184 $ol .= html::tag('li', null,
186 'href' => $MESSAGE->get_part_url($attach_prop->mime_id),
187 'onclick' => sprintf(
188 'return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)',
190 $attach_prop->mime_id,
191 $attach_prop->mimetype),
192 'title' => Q($title),
198 $out = html::tag('ul', $attrib, $ol, html::$common_attrib);
206 function rcmail_remote_objects_msg($attrib)
208 global $MESSAGE, $RCMAIL;
211 $attrib['id'] = 'rcmremoteobjmsg';
213 $msg = Q(rcube_label('blockedimages')) . ' ';
214 $msg .= html::a(array('href' => "#loadimages", 'onclick' => JS_OBJECT_NAME.".command('load-images')"), Q(rcube_label('showimages')));
216 // add link to save sender in addressbook and reload message
217 if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) {
218 $msg .= ' ' . html::a(array('href' => "#alwaysload", 'onclick' => JS_OBJECT_NAME.".command('always-load')", 'style' => "white-space:nowrap"),
219 Q(rcube_label(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
222 $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
223 return html::div($attrib, $msg);
227 $OUTPUT->add_handlers(array(
228 'messageattachments' => 'rcmail_message_attachments',
229 'mailboxname' => 'rcmail_mailbox_name_display',
230 'blockedobjects' => 'rcmail_remote_objects_msg'));
233 if ($RCMAIL->action=='print' && $OUTPUT->template_exists('printmessage'))
234 $OUTPUT->send('printmessage', false);
235 else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
236 $OUTPUT->send('messagepreview', false);
238 $OUTPUT->send('message', false);
241 // mark message as read
242 if ($MESSAGE && $MESSAGE->headers && !$MESSAGE->headers->seen)
243 $IMAP->set_flag($MESSAGE->uid, 'SEEN');