| [4e17e6c] | 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | +-----------------------------------------------------------------------+ |
|---|
| 5 | | program/steps/mail/show.inc | |
|---|
| 6 | | | |
|---|
| [e019f2d] | 7 | | This file is part of the Roundcube Webmail client | |
|---|
| [f5e7b353] | 8 | | Copyright (C) 2005-2009, The Roundcube Dev Team | |
|---|
| [30233b8] | 9 | | Licensed under the GNU GPL | |
|---|
| [4e17e6c] | 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 | |
|---|
| [197601e] | 22 | $PRINT_MODE = $RCMAIL->action=='print' ? TRUE : FALSE; |
|---|
| [4e17e6c] | 23 | |
|---|
| 24 | // similar code as in program/steps/mail/get.inc |
|---|
| [64e3e80] | 25 | if ($uid = get_input_value('_uid', RCUBE_INPUT_GET)) { |
|---|
| 26 | $MESSAGE = new rcube_message($uid); |
|---|
| [c9ca6ad] | 27 | |
|---|
| [65e8dff] | 28 | // if message not found (wrong UID)... |
|---|
| [8fa58e7] | 29 | if (empty($MESSAGE->headers)) { |
|---|
| [64e3e80] | 30 | rcmail_message_error($uid); |
|---|
| [8fa58e7] | 31 | } |
|---|
| [eab71fd] | 32 | |
|---|
| [c321a955] | 33 | $mbox_name = $RCMAIL->storage->get_folder(); |
|---|
| [64e3e80] | 34 | |
|---|
| [2a41355] | 35 | // show images? |
|---|
| [ec603f7] | 36 | rcmail_check_safe($MESSAGE); |
|---|
| [712b30d] | 37 | |
|---|
| [3536577] | 38 | // set message charset as default |
|---|
| 39 | if (!empty($MESSAGE->headers->charset)) |
|---|
| [c321a955] | 40 | $RCMAIL->storage->set_charset($MESSAGE->headers->charset); |
|---|
| [3536577] | 41 | |
|---|
| [0911fac] | 42 | $OUTPUT->set_pagetitle(abbreviate_string($MESSAGE->subject, 128, '...', true)); |
|---|
| [64e3e80] | 43 | |
|---|
| [4e17e6c] | 44 | // give message uid to the client |
|---|
| [8fa58e7] | 45 | $OUTPUT->set_env('uid', $MESSAGE->uid); |
|---|
| [112c9133] | 46 | // set environement |
|---|
| [8fa58e7] | 47 | $OUTPUT->set_env('safemode', $MESSAGE->is_safe); |
|---|
| [62e43d2] | 48 | $OUTPUT->set_env('sender', $MESSAGE->sender['string']); |
|---|
| [a25d396] | 49 | $OUTPUT->set_env('permaurl', rcmail_url('show', array('_uid' => $MESSAGE->uid, '_mbox' => $mbox_name))); |
|---|
| [c321a955] | 50 | $OUTPUT->set_env('delimiter', $RCMAIL->storage->get_hierarchy_delimiter()); |
|---|
| [2cc1cac] | 51 | $OUTPUT->set_env('mailbox', $mbox_name); |
|---|
| [11ea2ac] | 52 | |
|---|
| [f7b58af] | 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 | |
|---|
| [112c9133] | 57 | if ($CONFIG['trash_mbox']) |
|---|
| 58 | $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']); |
|---|
| [11ea2ac] | 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); |
|---|
| [e25a357] | 67 | if ($MESSAGE->headers->others['list-post']) |
|---|
| 68 | $OUTPUT->set_env('list_post', true); |
|---|
| [40a1860] | 69 | if ($CONFIG['forward_attachment']) |
|---|
| [a509bb6] | 70 | $OUTPUT->set_env('forward_attachment', true); |
|---|
| [11ea2ac] | 71 | |
|---|
| [112c9133] | 72 | if (!$OUTPUT->ajax_call) |
|---|
| [c50d887] | 73 | $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash', |
|---|
| 74 | 'movingmessage', 'deletingmessage'); |
|---|
| [172e334] | 75 | |
|---|
| [ed54070] | 76 | // check for unset disposition notification |
|---|
| [609d392] | 77 | if ($MESSAGE->headers->mdn_to |
|---|
| 78 | && empty($MESSAGE->headers->flags['MDNSENT']) |
|---|
| 79 | && empty($MESSAGE->headers->flags['SEEN']) |
|---|
| [c321a955] | 80 | && ($RCMAIL->storage->check_permflag('MDNSENT') || $RCMAIL->storage->check_permflag('*')) |
|---|
| [609d392] | 81 | && $mbox_name != $CONFIG['drafts_mbox'] |
|---|
| 82 | && $mbox_name != $CONFIG['sent_mbox'] |
|---|
| 83 | ) { |
|---|
| [a999682] | 84 | $mdn_cfg = intval($CONFIG['mdn_requests']); |
|---|
| 85 | |
|---|
| [6c6bb09] | 86 | if ($mdn_cfg == 1 || (($mdn_cfg == 3 || $mdn_cfg == 4) && rcmail_contact_exists($MESSAGE->sender['mailto']))) { |
|---|
| [a999682] | 87 | // Send MDN |
|---|
| 88 | if (rcmail_send_mdn($MESSAGE, $smtp_error)) |
|---|
| [0ea88409] | 89 | $OUTPUT->show_message('receiptsent', 'confirmation'); |
|---|
| [ca90a9c] | 90 | else if ($smtp_error) |
|---|
| 91 | $OUTPUT->show_message($smtp_error['label'], 'error', $smtp_error['vars']); |
|---|
| [6c6bb09] | 92 | else |
|---|
| [86d43ef] | 93 | $OUTPUT->show_message('errorsendingreceipt', 'error'); |
|---|
| [0ea88409] | 94 | } |
|---|
| [6c6bb09] | 95 | else if ($mdn_cfg != 2 && $mdn_cfg != 4) { |
|---|
| [a999682] | 96 | // Ask user |
|---|
| [112c9133] | 97 | $OUTPUT->add_label('mdnrequest'); |
|---|
| [0ea88409] | 98 | $OUTPUT->set_env('mdn_request', true); |
|---|
| 99 | } |
|---|
| [fba1f5a] | 100 | } |
|---|
| [4e17e6c] | 101 | |
|---|
| [609d392] | 102 | if (empty($MESSAGE->headers->flags['SEEN']) |
|---|
| 103 | && ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0)) |
|---|
| 104 | ) { |
|---|
| [3536577] | 105 | $RCMAIL->plugins->exec_hook('message_read', array('uid' => $MESSAGE->uid, |
|---|
| [f52c936f] | 106 | 'mailbox' => $mbox_name, 'message' => $MESSAGE)); |
|---|
| [609d392] | 107 | } |
|---|
| [cc97ea0] | 108 | } |
|---|
| [4e17e6c] | 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | function rcmail_message_attachments($attrib) |
|---|
| [8fa58e7] | 113 | { |
|---|
| 114 | global $PRINT_MODE, $MESSAGE; |
|---|
| [83ba22c] | 115 | |
|---|
| [8fa58e7] | 116 | $out = $ol = ''; |
|---|
| [4e17e6c] | 117 | |
|---|
| [8fa58e7] | 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 { |
|---|
| [ee258ce] | 124 | if (mb_strlen($attach_prop->filename) > 50) { |
|---|
| [203ee44] | 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 | |
|---|
| [f94e442] | 133 | $ol .= html::tag('li', rcmail_filetype2classname($attach_prop->mimetype, $attach_prop->filename), |
|---|
| [8fa58e7] | 134 | html::a(array( |
|---|
| [57486f6] | 135 | 'href' => $MESSAGE->get_part_url($attach_prop->mime_id, false), |
|---|
| [8fa58e7] | 136 | 'onclick' => sprintf( |
|---|
| 137 | 'return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)', |
|---|
| 138 | JS_OBJECT_NAME, |
|---|
| 139 | $attach_prop->mime_id, |
|---|
| [e0bd705] | 140 | rcmail_fix_mimetype($attach_prop->mimetype)), |
|---|
| [203ee44] | 141 | 'title' => Q($title), |
|---|
| [8fa58e7] | 142 | ), |
|---|
| [30694e4] | 143 | Q($filename))); |
|---|
| [4e17e6c] | 144 | } |
|---|
| [8fa58e7] | 145 | } |
|---|
| [4e17e6c] | 146 | |
|---|
| [8fa58e7] | 147 | $out = html::tag('ul', $attrib, $ol, html::$common_attrib); |
|---|
| [83ba22c] | 148 | } |
|---|
| 149 | |
|---|
| [8fa58e7] | 150 | return $out; |
|---|
| 151 | } |
|---|
| [4e17e6c] | 152 | |
|---|
| [46cdbf0] | 153 | function rcmail_remote_objects_msg() |
|---|
| [62e43d2] | 154 | { |
|---|
| 155 | global $MESSAGE, $RCMAIL; |
|---|
| [83ba22c] | 156 | |
|---|
| [46cdbf0] | 157 | $attrib['id'] = 'remote-objects-message'; |
|---|
| 158 | $attrib['class'] = 'notice'; |
|---|
| 159 | $attrib['style'] = 'display: none'; |
|---|
| [83ba22c] | 160 | |
|---|
| [62e43d2] | 161 | $msg = Q(rcube_label('blockedimages')) . ' '; |
|---|
| 162 | $msg .= html::a(array('href' => "#loadimages", 'onclick' => JS_OBJECT_NAME.".command('load-images')"), Q(rcube_label('showimages'))); |
|---|
| [83ba22c] | 163 | |
|---|
| [62e43d2] | 164 | // add link to save sender in addressbook and reload message |
|---|
| [2a41355] | 165 | if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) { |
|---|
| [62e43d2] | 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']))))); |
|---|
| [4e17e6c] | 168 | } |
|---|
| [83ba22c] | 169 | |
|---|
| [62e43d2] | 170 | $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']); |
|---|
| 171 | return html::div($attrib, $msg); |
|---|
| 172 | } |
|---|
| [4e17e6c] | 173 | |
|---|
| [46cdbf0] | 174 | function rcmail_message_buttons() |
|---|
| 175 | { |
|---|
| 176 | global $MESSAGE, $RCMAIL, $CONFIG; |
|---|
| 177 | |
|---|
| [c321a955] | 178 | $mbox = $RCMAIL->storage->get_folder(); |
|---|
| 179 | $delim = $RCMAIL->storage->get_hierarchy_delimiter(); |
|---|
| [46cdbf0] | 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 | |
|---|
| [a999682] | 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 | |
|---|
| [4e17e6c] | 231 | |
|---|
| [f115416] | 232 | $OUTPUT->add_handlers(array( |
|---|
| 233 | 'messageattachments' => 'rcmail_message_attachments', |
|---|
| [ac5d15d] | 234 | 'mailboxname' => 'rcmail_mailbox_name_display', |
|---|
| [46cdbf0] | 235 | 'messageobjects' => 'rcmail_message_objects', |
|---|
| 236 | )); |
|---|
| [f115416] | 237 | |
|---|
| 238 | |
|---|
| [83ba22c] | 239 | if ($RCMAIL->action=='print' && $OUTPUT->template_exists('messageprint')) |
|---|
| 240 | $OUTPUT->send('messageprint', false); |
|---|
| [e58df3a] | 241 | else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview')) |
|---|
| [3536577] | 242 | $OUTPUT->send('messagepreview', false); |
|---|
| [4e17e6c] | 243 | else |
|---|
| [3536577] | 244 | $OUTPUT->send('message', false); |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | // mark message as read |
|---|
| [609d392] | 248 | if ($MESSAGE && $MESSAGE->headers && empty($MESSAGE->headers->flags['SEEN']) && |
|---|
| [c642779] | 249 | ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0))) |
|---|
| 250 | { |
|---|
| [c321a955] | 251 | if ($RCMAIL->storage->set_flag($MESSAGE->uid, 'SEEN')) { |
|---|
| [b46edc0f] | 252 | if ($count = rcmail_get_unseen_count($mbox_name)) { |
|---|
| 253 | rcmail_set_unseen_count($mbox_name, $count - 1); |
|---|
| 254 | } |
|---|
| 255 | } |
|---|
| [c642779] | 256 | } |
|---|
| [3536577] | 257 | |
|---|
| 258 | exit; |
|---|
| 259 | |
|---|