| 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-2009, The Roundcube Dev Team | |
|---|
| 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 ($uid = get_input_value('_uid', RCUBE_INPUT_GET)) { |
|---|
| 26 | $MESSAGE = new rcube_message($uid); |
|---|
| 27 | |
|---|
| 28 | // if message not found (wrong UID)... |
|---|
| 29 | if (empty($MESSAGE->headers)) { |
|---|
| 30 | rcmail_message_error($uid); |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | $mbox_name = $RCMAIL->storage->get_folder(); |
|---|
| 34 | |
|---|
| 35 | // show images? |
|---|
| 36 | rcmail_check_safe($MESSAGE); |
|---|
| 37 | |
|---|
| 38 | // set message charset as default |
|---|
| 39 | if (!empty($MESSAGE->headers->charset)) |
|---|
| 40 | $RCMAIL->storage->set_charset($MESSAGE->headers->charset); |
|---|
| 41 | |
|---|
| 42 | $OUTPUT->set_pagetitle(abbreviate_string($MESSAGE->subject, 128, '...', true)); |
|---|
| 43 | |
|---|
| 44 | // give message uid to the client |
|---|
| 45 | $OUTPUT->set_env('uid', $MESSAGE->uid); |
|---|
| 46 | // set environement |
|---|
| 47 | $OUTPUT->set_env('safemode', $MESSAGE->is_safe); |
|---|
| 48 | $OUTPUT->set_env('sender', $MESSAGE->sender['string']); |
|---|
| 49 | $OUTPUT->set_env('permaurl', rcmail_url('show', array('_uid' => $MESSAGE->uid, '_mbox' => $mbox_name))); |
|---|
| 50 | $OUTPUT->set_env('delimiter', $RCMAIL->storage->get_hierarchy_delimiter()); |
|---|
| 51 | $OUTPUT->set_env('mailbox', $mbox_name); |
|---|
| 52 | |
|---|
| 53 | // mimetypes supported by the browser (default settings) |
|---|
| 54 | $mimetypes = $RCMAIL->config->get('client_mimetypes', 'text/plain,text/html,text/xml,image/jpeg,image/gif,image/png,application/x-javascript,application/pdf,application/x-shockwave-flash'); |
|---|
| 55 | $OUTPUT->set_env('mimetypes', is_string($mimetypes) ? explode(',', $mimetypes) : (array)$mimetypes); |
|---|
| 56 | |
|---|
| 57 | if ($CONFIG['trash_mbox']) |
|---|
| 58 | $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']); |
|---|
| 59 | if ($CONFIG['flag_for_deletion']) |
|---|
| 60 | $OUTPUT->set_env('flag_for_deletion', true); |
|---|
| 61 | if ($CONFIG['read_when_deleted']) |
|---|
| 62 | $OUTPUT->set_env('read_when_deleted', true); |
|---|
| 63 | if ($CONFIG['skip_deleted']) |
|---|
| 64 | $OUTPUT->set_env('skip_deleted', true); |
|---|
| 65 | if ($CONFIG['display_next']) |
|---|
| 66 | $OUTPUT->set_env('display_next', true); |
|---|
| 67 | if ($MESSAGE->headers->others['list-post']) |
|---|
| 68 | $OUTPUT->set_env('list_post', true); |
|---|
| 69 | if ($CONFIG['forward_attachment']) |
|---|
| 70 | $OUTPUT->set_env('forward_attachment', true); |
|---|
| 71 | |
|---|
| 72 | if (!$OUTPUT->ajax_call) |
|---|
| 73 | $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash', |
|---|
| 74 | 'movingmessage', 'deletingmessage'); |
|---|
| 75 | |
|---|
| 76 | // check for unset disposition notification |
|---|
| 77 | if ($MESSAGE->headers->mdn_to |
|---|
| 78 | && empty($MESSAGE->headers->flags['MDNSENT']) |
|---|
| 79 | && empty($MESSAGE->headers->flags['SEEN']) |
|---|
| 80 | && ($RCMAIL->storage->check_permflag('MDNSENT') || $RCMAIL->storage->check_permflag('*')) |
|---|
| 81 | && $mbox_name != $CONFIG['drafts_mbox'] |
|---|
| 82 | && $mbox_name != $CONFIG['sent_mbox'] |
|---|
| 83 | ) { |
|---|
| 84 | $mdn_cfg = intval($CONFIG['mdn_requests']); |
|---|
| 85 | |
|---|
| 86 | if ($mdn_cfg == 1 || (($mdn_cfg == 3 || $mdn_cfg == 4) && rcmail_contact_exists($MESSAGE->sender['mailto']))) { |
|---|
| 87 | // Send MDN |
|---|
| 88 | if (rcmail_send_mdn($MESSAGE, $smtp_error)) |
|---|
| 89 | $OUTPUT->show_message('receiptsent', 'confirmation'); |
|---|
| 90 | else if ($smtp_error) |
|---|
| 91 | $OUTPUT->show_message($smtp_error['label'], 'error', $smtp_error['vars']); |
|---|
| 92 | else |
|---|
| 93 | $OUTPUT->show_message('errorsendingreceipt', 'error'); |
|---|
| 94 | } |
|---|
| 95 | else if ($mdn_cfg != 2 && $mdn_cfg != 4) { |
|---|
| 96 | // Ask user |
|---|
| 97 | $OUTPUT->add_label('mdnrequest'); |
|---|
| 98 | $OUTPUT->set_env('mdn_request', true); |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | if (empty($MESSAGE->headers->flags['SEEN']) |
|---|
| 103 | && ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0)) |
|---|
| 104 | ) { |
|---|
| 105 | $RCMAIL->plugins->exec_hook('message_read', array('uid' => $MESSAGE->uid, |
|---|
| 106 | 'mailbox' => $mbox_name, 'message' => $MESSAGE)); |
|---|
| 107 | } |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | function rcmail_message_attachments($attrib) |
|---|
| 113 | { |
|---|
| 114 | global $PRINT_MODE, $MESSAGE; |
|---|
| 115 | |
|---|
| 116 | $out = $ol = ''; |
|---|
| 117 | |
|---|
| 118 | if (sizeof($MESSAGE->attachments)) { |
|---|
| 119 | foreach ($MESSAGE->attachments as $attach_prop) { |
|---|
| 120 | if ($PRINT_MODE) { |
|---|
| 121 | $ol .= html::tag('li', null, sprintf("%s (%s)", Q($attach_prop->filename), Q(show_bytes($attach_prop->size)))); |
|---|
| 122 | } |
|---|
| 123 | else { |
|---|
| 124 | if (mb_strlen($attach_prop->filename) > 50) { |
|---|
| 125 | $filename = abbreviate_string($attach_prop->filename, 50); |
|---|
| 126 | $title = $attach_prop->filename; |
|---|
| 127 | } |
|---|
| 128 | else { |
|---|
| 129 | $filename = $attach_prop->filename; |
|---|
| 130 | $title = ''; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | $ol .= html::tag('li', rcmail_filetype2classname($attach_prop->mimetype, $attach_prop->filename), |
|---|
| 134 | html::a(array( |
|---|
| 135 | 'href' => $MESSAGE->get_part_url($attach_prop->mime_id, false), |
|---|
| 136 | 'onclick' => sprintf( |
|---|
| 137 | 'return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)', |
|---|
| 138 | JS_OBJECT_NAME, |
|---|
| 139 | $attach_prop->mime_id, |
|---|
| 140 | rcmail_fix_mimetype($attach_prop->mimetype)), |
|---|
| 141 | 'title' => Q($title), |
|---|
| 142 | ), |
|---|
| 143 | Q($filename))); |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | $out = html::tag('ul', $attrib, $ol, html::$common_attrib); |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | return $out; |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | function rcmail_remote_objects_msg() |
|---|
| 154 | { |
|---|
| 155 | global $MESSAGE, $RCMAIL; |
|---|
| 156 | |
|---|
| 157 | $attrib['id'] = 'remote-objects-message'; |
|---|
| 158 | $attrib['class'] = 'notice'; |
|---|
| 159 | $attrib['style'] = 'display: none'; |
|---|
| 160 | |
|---|
| 161 | $msg = Q(rcube_label('blockedimages')) . ' '; |
|---|
| 162 | $msg .= html::a(array('href' => "#loadimages", 'onclick' => JS_OBJECT_NAME.".command('load-images')"), Q(rcube_label('showimages'))); |
|---|
| 163 | |
|---|
| 164 | // add link to save sender in addressbook and reload message |
|---|
| 165 | if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) { |
|---|
| 166 | $msg .= ' ' . html::a(array('href' => "#alwaysload", 'onclick' => JS_OBJECT_NAME.".command('always-load')", 'style' => "white-space:nowrap"), |
|---|
| 167 | Q(rcube_label(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto']))))); |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']); |
|---|
| 171 | return html::div($attrib, $msg); |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | function rcmail_message_buttons() |
|---|
| 175 | { |
|---|
| 176 | global $MESSAGE, $RCMAIL, $CONFIG; |
|---|
| 177 | |
|---|
| 178 | $mbox = $RCMAIL->storage->get_folder(); |
|---|
| 179 | $delim = $RCMAIL->storage->get_hierarchy_delimiter(); |
|---|
| 180 | $dbox = $CONFIG['drafts_mbox']; |
|---|
| 181 | |
|---|
| 182 | // the message is not a draft |
|---|
| 183 | if ($mbox != $dbox && strpos($mbox, $dbox.$delim) !== 0) { |
|---|
| 184 | return ''; |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | $attrib['id'] = 'message-buttons'; |
|---|
| 188 | $attrib['class'] = 'notice'; |
|---|
| 189 | |
|---|
| 190 | $msg = Q(rcube_label('isdraft')) . ' '; |
|---|
| 191 | $msg .= html::a(array('href' => "#edit", 'onclick' => JS_OBJECT_NAME.".command('edit')"), Q(rcube_label('edit'))); |
|---|
| 192 | |
|---|
| 193 | return html::div($attrib, $msg); |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | function rcmail_message_objects($attrib) |
|---|
| 197 | { |
|---|
| 198 | global $RCMAIL, $MESSAGE; |
|---|
| 199 | |
|---|
| 200 | if (!$attrib['id']) |
|---|
| 201 | $attrib['id'] = 'message-objects'; |
|---|
| 202 | |
|---|
| 203 | $content = array( |
|---|
| 204 | rcmail_message_buttons(), |
|---|
| 205 | rcmail_remote_objects_msg(), |
|---|
| 206 | ); |
|---|
| 207 | |
|---|
| 208 | $plugin = $RCMAIL->plugins->exec_hook('message_objects', |
|---|
| 209 | array('content' => $content, 'message' => $MESSAGE)); |
|---|
| 210 | |
|---|
| 211 | $content = implode("\n", $plugin['content']); |
|---|
| 212 | |
|---|
| 213 | return html::div($attrib, $content); |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | function rcmail_contact_exists($email) |
|---|
| 217 | { |
|---|
| 218 | global $RCMAIL; |
|---|
| 219 | |
|---|
| 220 | if ($email) { |
|---|
| 221 | // @TODO: search in all address books? |
|---|
| 222 | $CONTACTS = $RCMAIL->get_address_book(null, true); |
|---|
| 223 | $existing = $CONTACTS->search('email', $email, true, false); |
|---|
| 224 | if ($existing->count) |
|---|
| 225 | return true; |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | return false; |
|---|
| 229 | } |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | $OUTPUT->add_handlers(array( |
|---|
| 233 | 'messageattachments' => 'rcmail_message_attachments', |
|---|
| 234 | 'mailboxname' => 'rcmail_mailbox_name_display', |
|---|
| 235 | 'messageobjects' => 'rcmail_message_objects', |
|---|
| 236 | )); |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | if ($RCMAIL->action=='print' && $OUTPUT->template_exists('messageprint')) |
|---|
| 240 | $OUTPUT->send('messageprint', false); |
|---|
| 241 | else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview')) |
|---|
| 242 | $OUTPUT->send('messagepreview', false); |
|---|
| 243 | else |
|---|
| 244 | $OUTPUT->send('message', false); |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | // mark message as read |
|---|
| 248 | if ($MESSAGE && $MESSAGE->headers && empty($MESSAGE->headers->flags['SEEN']) && |
|---|
| 249 | ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0))) |
|---|
| 250 | { |
|---|
| 251 | if ($RCMAIL->storage->set_flag($MESSAGE->uid, 'SEEN')) { |
|---|
| 252 | if ($count = rcmail_get_unseen_count($mbox_name)) { |
|---|
| 253 | rcmail_set_unseen_count($mbox_name, $count - 1); |
|---|
| 254 | } |
|---|
| 255 | } |
|---|
| 256 | } |
|---|
| 257 | |
|---|
| 258 | exit; |
|---|
| 259 | |
|---|