| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | +-----------------------------------------------------------------------+ |
|---|
| 5 | | program/steps/mail/show.inc | |
|---|
| 6 | | | |
|---|
| 7 | | This file is part of the RoundCube Webmail client | |
|---|
| 8 | | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland | |
|---|
| 9 | | Licensed under the GNU GPL | |
|---|
| 10 | | | |
|---|
| 11 | | PURPOSE: | |
|---|
| 12 | | Display a mail message similar as a usual mail application does | |
|---|
| 13 | | | |
|---|
| 14 | +-----------------------------------------------------------------------+ |
|---|
| 15 | | Author: Thomas Bruederli <roundcube@gmail.com> | |
|---|
| 16 | +-----------------------------------------------------------------------+ |
|---|
| 17 | |
|---|
| 18 | $Id$ |
|---|
| 19 | |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | $PRINT_MODE = $RCMAIL->action=='print' ? TRUE : FALSE; |
|---|
| 23 | |
|---|
| 24 | // similar code as in program/steps/mail/get.inc |
|---|
| 25 | if ($_GET['_uid']) { |
|---|
| 26 | $MESSAGE = new rcube_message(get_input_value('_uid', RCUBE_INPUT_GET)); |
|---|
| 27 | |
|---|
| 28 | // set message charset as default |
|---|
| 29 | if (!empty($MESSAGE->headers->charset)) |
|---|
| 30 | $IMAP->set_charset($MESSAGE->headers->charset); |
|---|
| 31 | |
|---|
| 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' && template_exists('messagepreview')) |
|---|
| 36 | $OUTPUT->send('messagepreview'); |
|---|
| 37 | else { |
|---|
| 38 | $RCMAIL->action = 'list'; |
|---|
| 39 | return; |
|---|
| 40 | } |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | $mbox_name = $IMAP->get_mailbox_name(); |
|---|
| 44 | |
|---|
| 45 | // calculate Etag for this request |
|---|
| 46 | $etag = md5($MESSAGE->uid.$mbox_name.session_id().intval($MESSAGE->headers->mdn_sent).intval($MESSAGE->is_safe).intval($PRINT_MODE)); |
|---|
| 47 | |
|---|
| 48 | // check known senders to display images |
|---|
| 49 | if (!$MESSAGE->is_safe |
|---|
| 50 | && !$_SESSION['safe_messages'][$MESSAGE->uid] |
|---|
| 51 | && !isset($_GET['_safe']) |
|---|
| 52 | && $RCMAIL->config->get('addrbook_show_images') |
|---|
| 53 | && $MESSAGE->has_html_part()) |
|---|
| 54 | { |
|---|
| 55 | $CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']); |
|---|
| 56 | $senders = $IMAP->decode_address_list($MESSAGE->headers->from); |
|---|
| 57 | |
|---|
| 58 | foreach ($senders as $sender) |
|---|
| 59 | if ($sender['mailto'] && $CONTACTS->search('email', $sender['mailto'], true, false)->count) |
|---|
| 60 | { |
|---|
| 61 | $MESSAGE->set_safe(); |
|---|
| 62 | break; |
|---|
| 63 | } |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | // allow caching, unless remote images are present |
|---|
| 67 | if ((bool)$MESSAGE->is_safe) |
|---|
| 68 | send_nocacheing_headers(); |
|---|
| 69 | else if (empty($CONFIG['devel_mode'])) |
|---|
| 70 | send_modified_header($_SESSION['login_time'], $etag, !$MESSAGE->headers->seen); |
|---|
| 71 | |
|---|
| 72 | $OUTPUT->set_pagetitle($MESSAGE->subject); |
|---|
| 73 | |
|---|
| 74 | // mark message as read |
|---|
| 75 | if (!$MESSAGE->headers->seen) |
|---|
| 76 | { |
|---|
| 77 | $marked = $IMAP->set_flag($MESSAGE->uid, 'SEEN'); |
|---|
| 78 | if($RCMAIL->action == 'preview' && $marked != -1) |
|---|
| 79 | { |
|---|
| 80 | $OUTPUT->command('set_unread_count_from_preview', $mbox_name, $IMAP->messagecount($mbox_name, 'UNSEEN'), ($mbox_name == 'INBOX')); |
|---|
| 81 | $OUTPUT->command('mark_as_read_from_preview', $MESSAGE->uid); |
|---|
| 82 | } |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | // give message uid to the client |
|---|
| 86 | $OUTPUT->set_env('uid', $MESSAGE->uid); |
|---|
| 87 | $OUTPUT->set_env('safemode', $MESSAGE->is_safe); |
|---|
| 88 | |
|---|
| 89 | // check for unset disposition notification |
|---|
| 90 | if ($MESSAGE->headers->mdn_to && !$MESSAGE->headers->mdn_sent && |
|---|
| 91 | $mbox_name != $CONFIG['drafts_mbox'] && $mbox_name != $CONFIG['sent_mbox']) |
|---|
| 92 | { |
|---|
| 93 | if (intval($CONFIG['mdn_requests']) === 1) |
|---|
| 94 | { |
|---|
| 95 | if (rcmail_send_mdn($MESSAGE->uid)) |
|---|
| 96 | $OUTPUT->show_message('receiptsent', 'confirmation'); |
|---|
| 97 | } |
|---|
| 98 | else if (empty($CONFIG['mdn_requests'])) |
|---|
| 99 | { |
|---|
| 100 | rcube_add_label('mdnrequest'); |
|---|
| 101 | $OUTPUT->set_env('mdn_request', true); |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | $next = $prev = $first = $last = -1; |
|---|
| 107 | // get previous, first, next and last message UID |
|---|
| 108 | if ((!($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] == 'DESC') && |
|---|
| 109 | $IMAP->get_capability('sort')) || !empty($_REQUEST['_search'])) |
|---|
| 110 | { |
|---|
| 111 | // Only if we use custom sorting |
|---|
| 112 | $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']); |
|---|
| 113 | |
|---|
| 114 | $MESSAGE->index = array_search((string)$MESSAGE->uid, $a_msg_index, TRUE); |
|---|
| 115 | $prev = isset($a_msg_index[$MESSAGE->index-1]) ? $a_msg_index[$MESSAGE->index-1] : -1 ; |
|---|
| 116 | $first = count($a_msg_index)>0 ? $a_msg_index[0] : -1; |
|---|
| 117 | $next = isset($a_msg_index[$MESSAGE->index+1]) ? $a_msg_index[$MESSAGE->index+1] : -1 ; |
|---|
| 118 | $last = count($a_msg_index)>0 ? $a_msg_index[count($a_msg_index)-1] : -1; |
|---|
| 119 | } |
|---|
| 120 | else |
|---|
| 121 | { |
|---|
| 122 | // this assumes that we are sorted by date_DESC |
|---|
| 123 | $seq = $IMAP->get_id($MESSAGE->uid); |
|---|
| 124 | $prev = $IMAP->get_uid($seq + 1); |
|---|
| 125 | $first = $IMAP->get_uid($IMAP->messagecount()); |
|---|
| 126 | $next = $IMAP->get_uid($seq - 1); |
|---|
| 127 | $last = $IMAP->get_uid(1); |
|---|
| 128 | $MESSAGE->index = $IMAP->messagecount() - $seq; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | if ($prev > 0) |
|---|
| 132 | $OUTPUT->set_env('prev_uid', $prev); |
|---|
| 133 | if ($first >0) |
|---|
| 134 | $OUTPUT->set_env('first_uid', $first); |
|---|
| 135 | if ($next > 0) |
|---|
| 136 | $OUTPUT->set_env('next_uid', $next); |
|---|
| 137 | if ($last >0) |
|---|
| 138 | $OUTPUT->set_env('last_uid', $last); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | function rcmail_message_attachments($attrib) |
|---|
| 144 | { |
|---|
| 145 | global $PRINT_MODE, $MESSAGE; |
|---|
| 146 | |
|---|
| 147 | $out = $ol = ''; |
|---|
| 148 | |
|---|
| 149 | if (sizeof($MESSAGE->attachments)) { |
|---|
| 150 | foreach ($MESSAGE->attachments as $attach_prop) { |
|---|
| 151 | if ($PRINT_MODE) { |
|---|
| 152 | $ol .= html::tag('li', null, sprintf("%s (%s)", Q($attach_prop->filename), Q(show_bytes($attach_prop->size)))); |
|---|
| 153 | } |
|---|
| 154 | else { |
|---|
| 155 | $ol .= html::tag('li', null, |
|---|
| 156 | html::a(array( |
|---|
| 157 | 'href' => $MESSAGE->get_part_url($attach_prop->mime_id), |
|---|
| 158 | 'onclick' => sprintf( |
|---|
| 159 | 'return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)', |
|---|
| 160 | JS_OBJECT_NAME, |
|---|
| 161 | $attach_prop->mime_id, |
|---|
| 162 | $attach_prop->mimetype), |
|---|
| 163 | ), |
|---|
| 164 | Q($attach_prop->filename))); |
|---|
| 165 | } |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | $out = html::tag('ul', $attrib, $ol, html::$common_attrib); |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | return $out; |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | function rcmail_remote_objects_msg($attrib) |
|---|
| 177 | { |
|---|
| 178 | global $CONFIG, $OUTPUT; |
|---|
| 179 | |
|---|
| 180 | if (!$attrib['id']) |
|---|
| 181 | $attrib['id'] = 'rcmremoteobjmsg'; |
|---|
| 182 | |
|---|
| 183 | // allow the following attributes to be added to the <div> tag |
|---|
| 184 | $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id')); |
|---|
| 185 | $out = '<div' . $attrib_str . ">"; |
|---|
| 186 | |
|---|
| 187 | $out .= sprintf('%s <a href="#loadimages" onclick="%s.command(\'load-images\')">%s</a>', |
|---|
| 188 | Q(rcube_label('blockedimages')), |
|---|
| 189 | JS_OBJECT_NAME, |
|---|
| 190 | Q(rcube_label('showimages'))); |
|---|
| 191 | |
|---|
| 192 | $out .= '</div>'; |
|---|
| 193 | |
|---|
| 194 | $OUTPUT->add_gui_object('remoteobjectsmsg', $attrib['id']); |
|---|
| 195 | return $out; |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | $OUTPUT->add_handlers(array( |
|---|
| 200 | 'messageattachments' => 'rcmail_message_attachments', |
|---|
| 201 | 'blockedobjects' => 'rcmail_remote_objects_msg')); |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | if ($RCMAIL->action=='print' && template_exists('printmessage')) |
|---|
| 205 | $OUTPUT->send('printmessage'); |
|---|
| 206 | else if ($RCMAIL->action=='preview' && template_exists('messagepreview')) |
|---|
| 207 | $OUTPUT->send('messagepreview'); |
|---|
| 208 | else |
|---|
| 209 | $OUTPUT->send('message'); |
|---|
| 210 | ?> |
|---|