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 2822 2009-07-31 09:07:54Z 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);
77 if ($CONFIG['trash_mbox'])
78 $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']);
79 if (!$OUTPUT->ajax_call)
80 $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash', 'movingmessage');
82 // check for unset disposition notification
83 if ($MESSAGE->headers->mdn_to &&
84 !$MESSAGE->headers->mdn_sent && !$MESSAGE->headers->seen &&
85 ($IMAP->check_permflag('MDNSENT') || $IMAP->check_permflag('*')) &&
86 $mbox_name != $CONFIG['drafts_mbox'] &&
87 $mbox_name != $CONFIG['sent_mbox'])
89 if (intval($CONFIG['mdn_requests']) === 1)
91 if (rcmail_send_mdn($MESSAGE->uid, $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 (empty($CONFIG['mdn_requests']))
100 $OUTPUT->add_label('mdnrequest');
101 $OUTPUT->set_env('mdn_request', true);
105 // get previous, first, next and last message UID
106 if ($RCMAIL->action != 'preview' && $RCMAIL->action != 'print')
108 $next = $prev = $first = $last = -1;
110 if ($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] != 'DESC'
111 && empty($_REQUEST['_search']) && !$IMAP->skip_deleted)
113 // this assumes that we are sorted by date_DESC
114 $cnt = $IMAP->messagecount();
115 $seq = $IMAP->get_id($MESSAGE->uid);
116 $MESSAGE->index = $cnt - $seq;
118 $prev = $IMAP->get_uid($seq + 1);
119 $first = $IMAP->get_uid($cnt);
120 $next = $IMAP->get_uid($seq - 1);
121 $last = $IMAP->get_uid(1);
125 // Only if we use custom sorting
126 $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
128 $MESSAGE->index = array_search($IMAP->get_id($MESSAGE->uid), $a_msg_index);
130 $prev = isset($a_msg_index[$MESSAGE->index-1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index-1]) : -1 ;
131 $first = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[0]) : -1;
132 $next = isset($a_msg_index[$MESSAGE->index+1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index+1]) : -1 ;
133 $last = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[count($a_msg_index)-1]) : -1;
137 $OUTPUT->set_env('prev_uid', $prev);
139 $OUTPUT->set_env('first_uid', $first);
141 $OUTPUT->set_env('next_uid', $next);
143 $OUTPUT->set_env('last_uid', $last);
146 if ($CONFIG['display_next'])
147 $OUTPUT->set_env('display_next', true);
149 if (!$MESSAGE->headers->seen)
150 $RCMAIL->plugins->exec_hook('message_read', array('uid' => $MESSAGE->uid,
151 'mailbox' => $IMAP->mailbox, 'message' => $MESSAGE));
156 function rcmail_message_attachments($attrib)
158 global $PRINT_MODE, $MESSAGE;
162 if (sizeof($MESSAGE->attachments)) {
163 foreach ($MESSAGE->attachments as $attach_prop) {
165 $ol .= html::tag('li', null, sprintf("%s (%s)", Q($attach_prop->filename), Q(show_bytes($attach_prop->size))));
168 if (mb_strlen($attach_prop->filename) > 50) {
169 $filename = abbreviate_string($attach_prop->filename, 50);
170 $title = $attach_prop->filename;
173 $filename = $attach_prop->filename;
177 $ol .= html::tag('li', null,
179 'href' => $MESSAGE->get_part_url($attach_prop->mime_id),
180 'onclick' => sprintf(
181 'return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)',
183 $attach_prop->mime_id,
184 $attach_prop->mimetype),
185 'title' => Q($title),
191 $out = html::tag('ul', $attrib, $ol, html::$common_attrib);
199 function rcmail_remote_objects_msg($attrib)
201 global $MESSAGE, $RCMAIL;
204 $attrib['id'] = 'rcmremoteobjmsg';
206 $msg = Q(rcube_label('blockedimages')) . ' ';
207 $msg .= html::a(array('href' => "#loadimages", 'onclick' => JS_OBJECT_NAME.".command('load-images')"), Q(rcube_label('showimages')));
209 // add link to save sender in addressbook and reload message
210 if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) {
211 $msg .= ' ' . html::a(array('href' => "#alwaysload", 'onclick' => JS_OBJECT_NAME.".command('always-load')", 'style' => "white-space:nowrap"),
212 Q(rcube_label(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
215 $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
216 return html::div($attrib, $msg);
220 $OUTPUT->add_handlers(array(
221 'messageattachments' => 'rcmail_message_attachments',
222 'mailboxname' => 'rcmail_mailbox_name_display',
223 'blockedobjects' => 'rcmail_remote_objects_msg'));
226 if ($RCMAIL->action=='print' && $OUTPUT->template_exists('printmessage'))
227 $OUTPUT->send('printmessage', false);
228 else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
229 $OUTPUT->send('messagepreview', false);
231 $OUTPUT->send('message', false);
234 // mark message as read
235 if ($MESSAGE && $MESSAGE->headers && !$MESSAGE->headers->seen)
236 $IMAP->set_flag($MESSAGE->uid, 'SEEN');