4 +-----------------------------------------------------------------------+
5 | program/steps/mail/show.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005-2008, 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 2115 2008-12-04 10:21:34Z 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 // set message charset as default
29 if (!empty($MESSAGE->headers->charset))
30 $IMAP->set_charset($MESSAGE->headers->charset);
32 // go back to list if message not found (wrong UID)
33 if (empty($MESSAGE->headers)) {
34 $OUTPUT->show_message('messageopenerror', 'error');
35 if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
36 $OUTPUT->send('messagepreview');
38 rcmail_overwrite_action('');
43 $mbox_name = $IMAP->get_mailbox_name();
46 $show_images = $RCMAIL->config->get('show_images');
48 && !empty($show_images)
49 && $MESSAGE->has_html_part())
51 switch($show_images) {
52 case '1': // known senders only
53 $CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
54 if ($CONTACTS->search('email', $MESSAGE->sender['mailto'], true, false)->count) {
55 $MESSAGE->set_safe(true);
59 $MESSAGE->set_safe(true);
64 // calculate Etag for this request
65 $etag = md5($MESSAGE->uid.$mbox_name.session_id()
66 .intval($MESSAGE->headers->mdn_sent)
67 .intval($MESSAGE->is_safe)
68 .(!empty($MESSAGE->attachments) ? intval($CONFIG['inline_images']) : '')
69 .intval($PRINT_MODE));
71 // allow caching, unless remote images are present
72 if ((bool)$MESSAGE->is_safe)
73 send_nocacheing_headers();
74 else if (empty($CONFIG['devel_mode']))
75 send_modified_header($_SESSION['login_time'], $etag, !$MESSAGE->headers->seen);
77 $OUTPUT->set_pagetitle($MESSAGE->subject);
79 // give message uid to the client
80 $OUTPUT->set_env('uid', $MESSAGE->uid);
82 $OUTPUT->set_env('safemode', $MESSAGE->is_safe);
83 $OUTPUT->set_env('sender', $MESSAGE->sender['string']);
84 $OUTPUT->set_env('permaurl', rcmail_url('show', array('_uid' => $MESSAGE->uid, '_mbox' => $mbox_name)));
85 $OUTPUT->set_env('mailbox', $mbox_name);
86 if ($CONFIG['trash_mbox'])
87 $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']);
88 if (!$OUTPUT->ajax_call)
89 $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash', 'movingmessage');
91 // check for unset disposition notification
92 if ($MESSAGE->headers->mdn_to &&
93 !$MESSAGE->headers->mdn_sent && !$MESSAGE->headers->seen &&
94 $IMAP->check_permflag('MDNSENT') &&
95 $mbox_name != $CONFIG['drafts_mbox'] &&
96 $mbox_name != $CONFIG['sent_mbox'])
98 if (intval($CONFIG['mdn_requests']) === 1)
100 if (rcmail_send_mdn($MESSAGE->uid))
101 $OUTPUT->show_message('receiptsent', 'confirmation');
103 $OUTPUT->show_message('errorsendingreceipt', 'error');
105 else if (empty($CONFIG['mdn_requests']))
107 $OUTPUT->add_label('mdnrequest');
108 $OUTPUT->set_env('mdn_request', true);
112 // get previous, first, next and last message UID
113 if ($RCMAIL->action != 'preview' && $RCMAIL->action != 'print')
115 $next = $prev = $first = $last = -1;
117 if ((!($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] == 'DESC') &&
118 $IMAP->get_capability('sort')) || !empty($_REQUEST['_search']))
120 // Only if we use custom sorting
121 $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
123 $MESSAGE->index = array_search($IMAP->get_id($MESSAGE->uid), $a_msg_index);
125 $prev = isset($a_msg_index[$MESSAGE->index-1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index-1]) : -1 ;
126 $first = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[0]) : -1;
127 $next = isset($a_msg_index[$MESSAGE->index+1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index+1]) : -1 ;
128 $last = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[count($a_msg_index)-1]) : -1;
132 // this assumes that we are sorted by date_DESC
133 $cnt = $IMAP->messagecount();
134 $seq = $IMAP->get_id($MESSAGE->uid);
135 $MESSAGE->index = $cnt - $seq;
137 $prev = $IMAP->get_uid($seq + 1);
138 $first = $IMAP->get_uid($cnt);
139 $next = $IMAP->get_uid($seq - 1);
140 $last = $IMAP->get_uid(1);
144 $OUTPUT->set_env('prev_uid', $prev);
146 $OUTPUT->set_env('first_uid', $first);
148 $OUTPUT->set_env('next_uid', $next);
150 $OUTPUT->set_env('last_uid', $last);
153 // mark message as read
154 if (!$MESSAGE->headers->seen)
155 $IMAP->set_flag($MESSAGE->uid, 'SEEN');
160 function rcmail_message_attachments($attrib)
162 global $PRINT_MODE, $MESSAGE;
166 if (sizeof($MESSAGE->attachments)) {
167 foreach ($MESSAGE->attachments as $attach_prop) {
169 $ol .= html::tag('li', null, sprintf("%s (%s)", Q($attach_prop->filename), Q(show_bytes($attach_prop->size))));
172 if (rc_strlen($attach_prop->filename) > 50) {
173 $filename = abbreviate_string($attach_prop->filename, 50);
174 $title = $attach_prop->filename;
177 $filename = $attach_prop->filename;
181 $ol .= html::tag('li', null,
183 'href' => $MESSAGE->get_part_url($attach_prop->mime_id),
184 'onclick' => sprintf(
185 'return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)',
187 $attach_prop->mime_id,
188 $attach_prop->mimetype),
189 'title' => Q($title),
195 $out = html::tag('ul', $attrib, $ol, html::$common_attrib);
203 function rcmail_remote_objects_msg($attrib)
205 global $MESSAGE, $RCMAIL;
208 $attrib['id'] = 'rcmremoteobjmsg';
210 $msg = Q(rcube_label('blockedimages')) . ' ';
211 $msg .= html::a(array('href' => "#loadimages", 'onclick' => JS_OBJECT_NAME.".command('load-images')"), Q(rcube_label('showimages')));
213 // add link to save sender in addressbook and reload message
214 if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) {
215 $msg .= ' ' . html::a(array('href' => "#alwaysload", 'onclick' => JS_OBJECT_NAME.".command('always-load')", 'style' => "white-space:nowrap"),
216 Q(rcube_label(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
219 $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
220 return html::div($attrib, $msg);
224 $OUTPUT->add_handlers(array(
225 'messageattachments' => 'rcmail_message_attachments',
226 'mailboxname' => 'rcmail_mailbox_name_display',
227 'blockedobjects' => 'rcmail_remote_objects_msg'));
230 if ($RCMAIL->action=='print' && $OUTPUT->template_exists('printmessage'))
231 $OUTPUT->send('printmessage');
232 else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
233 $OUTPUT->send('messagepreview');
235 $OUTPUT->send('message');