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 1255 2008-04-05 12:49:21Z 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 // set message charset as default
34 if (!empty($MESSAGE['headers']->charset))
35 $IMAP->set_charset($MESSAGE['headers']->charset);
37 // go back to list if message not found (wrong UID)
38 if (!$MESSAGE['headers'])
40 $OUTPUT->show_message('messageopenerror', 'error');
41 if ($_action=='preview' && template_exists('messagepreview'))
42 parse_template('messagepreview');
50 // check if safe flag is set
51 if ($MESSAGE['is_safe'] = intval($_GET['_safe']))
52 $_SESSION['safe_messages'][$MESSAGE['UID']] = true;
53 else if ($_SESSION['safe_messages'][$MESSAGE['UID']])
54 $MESSAGE['is_safe'] = 1;
56 // calculate Etag for this request
57 $etag = md5($MESSAGE['UID'].$IMAP->get_mailbox_name().session_id().intval($MESSAGE['headers']->mdn_sent).intval($MESSAGE['is_safe']).intval($PRINT_MODE));
59 // allow caching, unless remote images are present
60 if ((bool)$MESSAGE['is_safe'])
61 send_nocacheing_headers();
62 else if (empty($CONFIG['devel_mode']))
63 send_modified_header($_SESSION['login_time'], $etag);
65 $MESSAGE['subject'] = rcube_imap::decode_mime_string($MESSAGE['headers']->subject, $MESSAGE['headers']->charset);
66 $OUTPUT->set_pagetitle($MESSAGE['subject']);
68 if ($MESSAGE['structure'] = $IMAP->get_structure($MESSAGE['UID']))
69 list($MESSAGE['parts'], $MESSAGE['attachments']) = rcmail_parse_message(
70 $MESSAGE['structure'],
71 array('safe' => $MESSAGE['is_safe'],
72 'prefer_html' => $CONFIG['prefer_html'],
73 'get_url' => $GET_URL.'&_part=%s')
76 $MESSAGE['body'] = $IMAP->get_body($MESSAGE['UID']);
79 // mark message as read
80 if (!$MESSAGE['headers']->seen && $_action != 'preview')
81 $IMAP->set_flag($MESSAGE['UID'], 'SEEN');
83 // give message uid to the client
84 $OUTPUT->set_env('uid', $MESSAGE['UID']);
85 $OUTPUT->set_env('safemode', $MESSAGE['is_safe']);
87 // check for unset disposition notification
88 if ($MESSAGE['headers']->mdn_to && !$MESSAGE['headers']->mdn_sent && $IMAP->get_mailbox_name() != $CONFIG['drafts_mbox'])
90 if (intval($CONFIG['mdn_requests']) === 1)
92 if (rcmail_send_mdn($MESSAGE['UID']))
93 $OUTPUT->show_message('receiptsent', 'confirmation');
95 else if (empty($CONFIG['mdn_requests']))
97 rcube_add_label('mdnrequest');
98 $OUTPUT->set_env('mdn_request', true);
103 $next = $prev = $first = $last = -1;
104 // get previous, first, next and last message UID
105 if ((!($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] == 'DESC') &&
106 $IMAP->get_capability('sort')) || !empty($_REQUEST['_search']))
108 // Only if we use custom sorting
109 $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
111 $MESSAGE['index'] = array_search((string)$MESSAGE['UID'], $a_msg_index, TRUE);
112 $prev = isset($a_msg_index[$MESSAGE['index']-1]) ? $a_msg_index[$MESSAGE['index']-1] : -1 ;
113 $first = count($a_msg_index)>0 ? $a_msg_index[0] : -1;
114 $next = isset($a_msg_index[$MESSAGE['index']+1]) ? $a_msg_index[$MESSAGE['index']+1] : -1 ;
115 $last = count($a_msg_index)>0 ? $a_msg_index[count($a_msg_index)-1] : -1;
119 // this assumes that we are sorted by date_DESC
120 $seq = $IMAP->get_id($MESSAGE['UID']);
121 $prev = $IMAP->get_uid($seq + 1);
122 $first = $IMAP->get_uid($IMAP->messagecount());
123 $next = $IMAP->get_uid($seq - 1);
124 $last = $IMAP->get_uid(1);
125 $MESSAGE['index'] = $IMAP->messagecount() - $seq;
129 $OUTPUT->set_env('prev_uid', $prev);
131 $OUTPUT->set_env('first_uid', $first);
133 $OUTPUT->set_env('next_uid', $next);
135 $OUTPUT->set_env('last_uid', $last);
140 function rcmail_message_attachments($attrib)
142 global $CONFIG, $OUTPUT, $PRINT_MODE, $MESSAGE, $GET_URL;
144 if (sizeof($MESSAGE['attachments']))
146 // allow the following attributes to be added to the <ul> tag
147 $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
148 $out = '<ul' . $attrib_str . ">\n";
150 foreach ($MESSAGE['attachments'] as $attach_prop)
153 $out .= sprintf('<li>%s (%s)</li>'."\n",
154 $attach_prop->filename,
155 show_bytes($attach_prop->size));
157 $out .= sprintf('<li><a href="%s&_part=%s" onclick="return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)">%s</a></li>'."\n",
158 htmlspecialchars($GET_URL),
159 $attach_prop->mime_id,
161 $attach_prop->mime_id,
162 $attach_prop->mimetype,
163 $attach_prop->filename);
173 function rcmail_remote_objects_msg($attrib)
175 global $CONFIG, $OUTPUT;
178 $attrib['id'] = 'rcmremoteobjmsg';
180 // allow the following attributes to be added to the <div> tag
181 $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
182 $out = '<div' . $attrib_str . ">";
184 $out .= sprintf('%s <a href="#loadimages" onclick="%s.command(\'load-images\')">%s</a>',
185 Q(rcube_label('blockedimages')),
187 Q(rcube_label('showimages')));
191 $OUTPUT->add_gui_object('remoteobjectsmsg', $attrib['id']);
196 $OUTPUT->add_handlers(array(
197 'messageattachments' => 'rcmail_message_attachments',
198 'blockedobjects' => 'rcmail_remote_objects_msg'));
201 if ($_action=='print' && template_exists('printmessage'))
202 parse_template('printmessage');
203 else if ($_action=='preview' && template_exists('messagepreview'))
204 parse_template('messagepreview');
206 parse_template('message');