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 1046 2008-02-11 23:07:44Z thomasb $
22 require_once('Mail/mimeDecode.php');
23 require_once('lib/rc_mail_mime.inc');
25 $PRINT_MODE = $_action=='print' ? TRUE : FALSE;
27 // similar code as in program/steps/mail/get.inc
30 $MESSAGE = array('UID' => get_input_value('_uid', RCUBE_INPUT_GET));
31 $MESSAGE['headers'] = $IMAP->get_headers($MESSAGE['UID']);
33 // go back to list if message not found (wrong UID)
34 if (!$MESSAGE['headers'])
36 $OUTPUT->show_message('messageopenerror', 'error');
37 if ($_action=='preview' && template_exists('messagepreview'))
38 parse_template('messagepreview');
46 // check if safe flag is set
47 if ($MESSAGE['is_safe'] = intval($_GET['_safe']))
48 $_SESSION['safe_messages'][$MESSAGE['UID']] = true;
49 else if ($_SESSION['safe_messages'][$MESSAGE['UID']])
50 $MESSAGE['is_safe'] = 1;
52 // calculate Etag for this request
53 $etag = md5($MESSAGE['UID'].$IMAP->get_mailbox_name().session_id().intval($MESSAGE['headers']->mdn_sent).intval($MESSAGE['is_safe']).intval($PRINT_MODE));
55 // allow caching, unless remote images are present
56 if ((bool)$MESSAGE['is_safe'])
57 send_nocacheing_headers();
58 else if (empty($CONFIG['devel_mode']))
59 send_modified_header($_SESSION['login_time'], $etag);
61 $MESSAGE['subject'] = rcube_imap::decode_mime_string($MESSAGE['headers']->subject, $MESSAGE['headers']->charset);
62 $OUTPUT->set_pagetitle($MESSAGE['subject']);
64 if ($MESSAGE['structure'] = $IMAP->get_structure($MESSAGE['UID']))
65 list($MESSAGE['parts'], $MESSAGE['attachments']) = rcmail_parse_message(
66 $MESSAGE['structure'],
67 array('safe' => $MESSAGE['is_safe'],
68 'prefer_html' => $CONFIG['prefer_html'],
69 'get_url' => $GET_URL.'&_part=%s')
72 $MESSAGE['body'] = $IMAP->get_body($MESSAGE['UID']);
75 // mark message as read
76 if (!$MESSAGE['headers']->seen && $_action != 'preview')
77 $IMAP->set_flag($MESSAGE['UID'], 'SEEN');
79 // give message uid to the client
80 $OUTPUT->set_env('uid', $MESSAGE['UID']);
81 $OUTPUT->set_env('safemode', $MESSAGE['is_safe']);
83 // check for unset disposition notification
84 if ($MESSAGE['headers']->mdn_to && !$MESSAGE['headers']->mdn_sent && $IMAP->get_mailbox_name() != $CONFIG['drafts_mbox'])
86 if (intval($CONFIG['mdn_requests']) === 1)
88 if (rcmail_send_mdn($MESSAGE['UID']))
89 $OUTPUT->show_message('receiptsent', 'confirmation');
91 else if (empty($CONFIG['mdn_requests']))
93 rcube_add_label('mdnrequest');
94 $OUTPUT->set_env('mdn_request', true);
99 $next = $prev = $first = $last = -1;
100 // get previous, first, next and last message UID
101 if ((!($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] == 'DESC') &&
102 $IMAP->get_capability('sort')) || !empty($_REQUEST['_search']))
104 // Only if we use custom sorting
105 $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
107 $MESSAGE['index'] = array_search((string)$MESSAGE['UID'], $a_msg_index, TRUE);
108 $prev = isset($a_msg_index[$MESSAGE['index']-1]) ? $a_msg_index[$MESSAGE['index']-1] : -1 ;
109 $first = count($a_msg_index)>0 ? $a_msg_index[0] : -1;
110 $next = isset($a_msg_index[$MESSAGE['index']+1]) ? $a_msg_index[$MESSAGE['index']+1] : -1 ;
111 $last = count($a_msg_index)>0 ? $a_msg_index[count($a_msg_index)-1] : -1;
115 // this assumes that we are sorted by date_DESC
116 $seq = $IMAP->get_id($MESSAGE['UID']);
117 $prev = $IMAP->get_uid($seq + 1);
118 $first = $IMAP->get_uid($IMAP->messagecount());
119 $next = $IMAP->get_uid($seq - 1);
120 $last = $IMAP->get_uid(1);
121 $MESSAGE['index'] = $IMAP->messagecount() - $seq;
125 $OUTPUT->set_env('prev_uid', $prev);
127 $OUTPUT->set_env('first_uid', $first);
129 $OUTPUT->set_env('next_uid', $next);
131 $OUTPUT->set_env('last_uid', $last);
136 function rcmail_message_attachments($attrib)
138 global $CONFIG, $OUTPUT, $PRINT_MODE, $MESSAGE, $GET_URL;
140 if (sizeof($MESSAGE['attachments']))
142 // allow the following attributes to be added to the <ul> tag
143 $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
144 $out = '<ul' . $attrib_str . ">\n";
146 foreach ($MESSAGE['attachments'] as $attach_prop)
149 $out .= sprintf('<li>%s (%s)</li>'."\n",
150 $attach_prop->filename,
151 show_bytes($attach_prop->size));
153 $out .= sprintf('<li><a href="%s&_part=%s" onclick="return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)">%s</a></li>'."\n",
154 htmlspecialchars($GET_URL),
155 $attach_prop->mime_id,
157 $attach_prop->mime_id,
158 $attach_prop->mimetype,
159 $attach_prop->filename);
169 function rcmail_remote_objects_msg($attrib)
171 global $CONFIG, $OUTPUT;
174 $attrib['id'] = 'rcmremoteobjmsg';
176 // allow the following attributes to be added to the <div> tag
177 $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
178 $out = '<div' . $attrib_str . ">";
180 $out .= sprintf('%s <a href="#loadimages" onclick="%s.command(\'load-images\')">%s</a>',
181 Q(rcube_label('blockedimages')),
183 Q(rcube_label('showimages')));
187 $OUTPUT->add_gui_object('remoteobjectsmsg', $attrib['id']);
192 $OUTPUT->add_handlers(array(
193 'messageattachments' => 'rcmail_message_attachments',
194 'blockedobjects' => 'rcmail_remote_objects_msg'));
197 if ($_action=='print' && template_exists('printmessage'))
198 parse_template('printmessage');
199 else if ($_action=='preview' && template_exists('messagepreview'))
200 parse_template('messagepreview');
202 parse_template('message');