source: github/program/steps/mail/show.inc @ 19cc5b9

HEADdev-browser-capabilitiespdo
Last change on this file since 19cc5b9 was 19cc5b9, checked in by Aleksander Machniak <alec@…>, 12 months ago

Display Tiff as Jpeg in browsers without Tiff support (#1488452)

  • Property mode set to 100644
File size: 10.2 KB
Line 
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 |                                                                       |
10 | Licensed under the GNU General Public License version 3 or            |
11 | any later version with exceptions for skins & plugins.                |
12 | See the README file for a full license statement.                     |
13 |                                                                       |
14 | PURPOSE:                                                              |
15 |   Display a mail message similar as a usual mail application does     |
16 |                                                                       |
17 +-----------------------------------------------------------------------+
18 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
19 +-----------------------------------------------------------------------+
20*/
21
22$PRINT_MODE = $RCMAIL->action=='print' ? TRUE : FALSE;
23
24// Read browser capabilities and store them in session
25if ($caps = get_input_value('_caps', RCUBE_INPUT_GET)) {
26  $browser_caps = array();
27  foreach (explode(',', $caps) as $cap) {
28    $cap = explode('=', $cap);
29    $browser_caps[$cap[0]] = $cap[1];
30  }
31  $_SESSION['browser_caps'] = $browser_caps;
32}
33
34// similar code as in program/steps/mail/get.inc
35if ($uid = get_input_value('_uid', RCUBE_INPUT_GET)) {
36  $MESSAGE = new rcube_message($uid);
37
38  // if message not found (wrong UID)...
39  if (empty($MESSAGE->headers)) {
40    rcmail_message_error($uid);
41  }
42
43  $mbox_name = $RCMAIL->storage->get_folder();
44
45  // show images?
46  rcmail_check_safe($MESSAGE);
47
48  // set message charset as default
49  if (!empty($MESSAGE->headers->charset))
50    $RCMAIL->storage->set_charset($MESSAGE->headers->charset);
51
52  $OUTPUT->set_pagetitle(abbreviate_string($MESSAGE->subject, 128, '...', true));
53
54  // give message uid to the client
55  $OUTPUT->set_env('uid', $MESSAGE->uid);
56  // set environement
57  $OUTPUT->set_env('safemode', $MESSAGE->is_safe);
58  $OUTPUT->set_env('sender', $MESSAGE->sender['string']);
59  $OUTPUT->set_env('permaurl', rcmail_url('show', array('_uid' => $MESSAGE->uid, '_mbox' => $mbox_name)));
60  $OUTPUT->set_env('delimiter', $RCMAIL->storage->get_hierarchy_delimiter());
61  $OUTPUT->set_env('mailbox', $mbox_name);
62
63  // mimetypes supported by the browser (default settings)
64  $mimetypes = $RCMAIL->config->get('client_mimetypes', 'text/plain,text/html,text/xml,image/jpeg,image/gif,image/png,image/bmp,image/tiff,application/x-javascript,application/pdf,application/x-shockwave-flash');
65  $mimetypes = is_string($mimetypes) ? explode(',', $mimetypes) : (array)$mimetypes;
66
67  // Remove unsupported types, which makes that attachment which cannot be
68  // displayed in a browser will be downloaded directly without displaying an overlay page
69  if (empty($_SESSION['browser_caps']['pdf']) && ($key = array_search('application/pdf', $mimetypes)) !== false) {
70    unset($mimetypes[$key]);
71  }
72  if (empty($_SESSION['browser_caps']['flash']) && ($key = array_search('application/x-shockwave-flash', $mimetypes)) !== false) {
73    unset($mimetypes[$key]);
74  }
75  if (empty($_SESSION['browser_caps']['tif']) && ($key = array_search('image/tiff', $mimetypes)) !== false) {
76    // we can convert tiff to jpeg
77    if (!$RCMAIL->config->get('im_convert_path')) {
78      unset($mimetypes[$key]);
79    }
80  }
81
82  $OUTPUT->set_env('mimetypes', $mimetypes);
83
84  if ($CONFIG['drafts_mbox'])
85    $OUTPUT->set_env('drafts_mailbox', $CONFIG['drafts_mbox']);
86  if ($CONFIG['trash_mbox'])
87    $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']);
88  if ($CONFIG['junk_mbox'])
89    $OUTPUT->set_env('junk_mailbox', $CONFIG['junk_mbox']);
90  if ($CONFIG['delete_junk'])
91    $OUTPUT->set_env('delete_junk', true);
92  if ($CONFIG['flag_for_deletion'])
93    $OUTPUT->set_env('flag_for_deletion', true);
94  if ($CONFIG['read_when_deleted'])
95    $OUTPUT->set_env('read_when_deleted', true);
96  if ($CONFIG['skip_deleted'])
97    $OUTPUT->set_env('skip_deleted', true);
98  if ($CONFIG['display_next'])
99    $OUTPUT->set_env('display_next', true);
100  if ($MESSAGE->headers->others['list-post'])
101    $OUTPUT->set_env('list_post', true);
102  if ($CONFIG['forward_attachment'])
103    $OUTPUT->set_env('forward_attachment', true);
104
105  if (!$OUTPUT->ajax_call)
106    $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash',
107      'movingmessage', 'deletingmessage');
108
109  // check for unset disposition notification
110  if ($MESSAGE->headers->mdn_to
111      && empty($MESSAGE->headers->flags['MDNSENT'])
112      && empty($MESSAGE->headers->flags['SEEN'])
113      && ($RCMAIL->storage->check_permflag('MDNSENT') || $RCMAIL->storage->check_permflag('*'))
114      && $mbox_name != $CONFIG['drafts_mbox']
115      && $mbox_name != $CONFIG['sent_mbox']
116  ) {
117    $mdn_cfg = intval($CONFIG['mdn_requests']);
118
119    if ($mdn_cfg == 1 || (($mdn_cfg == 3 || $mdn_cfg ==  4) && rcmail_contact_exists($MESSAGE->sender['mailto']))) {
120      // Send MDN
121      if (rcmail_send_mdn($MESSAGE, $smtp_error))
122        $OUTPUT->show_message('receiptsent', 'confirmation');
123      else if ($smtp_error)
124        $OUTPUT->show_message($smtp_error['label'], 'error', $smtp_error['vars']);
125      else
126        $OUTPUT->show_message('errorsendingreceipt', 'error');
127    }
128    else if ($mdn_cfg != 2 && $mdn_cfg != 4) {
129      // Ask user
130      $OUTPUT->add_label('mdnrequest');
131      $OUTPUT->set_env('mdn_request', true);
132    }
133  }
134
135  if (empty($MESSAGE->headers->flags['SEEN'])
136    && ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0))
137  ) {
138    $RCMAIL->plugins->exec_hook('message_read', array('uid' => $MESSAGE->uid,
139      'mailbox' => $mbox_name, 'message' => $MESSAGE));
140  }
141}
142
143
144
145function rcmail_message_attachments($attrib)
146{
147  global $PRINT_MODE, $MESSAGE;
148
149  $out = $ol = '';
150
151  if (sizeof($MESSAGE->attachments)) {
152    foreach ($MESSAGE->attachments as $attach_prop) {
153      $filename = $attach_prop->filename;
154      if (empty($filename) && $attach_prop->mimetype == 'text/html') {
155        $filename = rcube_label('htmlmessage');
156      }
157
158      if ($PRINT_MODE) {
159        $ol .= html::tag('li', null, sprintf("%s (%s)", Q($filename), Q(show_bytes($attach_prop->size))));
160      }
161      else {
162        if (mb_strlen($filename) > 50) {
163          $filename = abbreviate_string($filename, 50);
164          $title = $filename;
165        }
166        else {
167          $title = '';
168        }
169
170        $ol .= html::tag('li', rcmail_filetype2classname($attach_prop->mimetype, $filename),
171          html::a(array(
172            'href' => $MESSAGE->get_part_url($attach_prop->mime_id, false),
173            'onclick' => sprintf(
174              'return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)',
175              JS_OBJECT_NAME,
176              $attach_prop->mime_id,
177              rcmail_fix_mimetype($attach_prop->mimetype)),
178              'title' => Q($title),
179            ),
180            Q($filename)));
181      }
182    }
183
184    $out = html::tag('ul', $attrib, $ol, html::$common_attrib);
185  }
186
187  return $out;
188}
189
190function rcmail_remote_objects_msg()
191{
192  global $MESSAGE, $RCMAIL;
193
194  $attrib['id']    = 'remote-objects-message';
195  $attrib['class'] = 'notice';
196  $attrib['style'] = 'display: none';
197
198  $msg = Q(rcube_label('blockedimages')) . '&nbsp;';
199  $msg .= html::a(array('href' => "#loadimages", 'onclick' => JS_OBJECT_NAME.".command('load-images')"), Q(rcube_label('showimages')));
200
201  // add link to save sender in addressbook and reload message
202  if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) {
203    $msg .= ' ' . html::a(array('href' => "#alwaysload", 'onclick' => JS_OBJECT_NAME.".command('always-load')", 'style' => "white-space:nowrap"),
204      Q(rcube_label(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
205  }
206
207  $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
208  return html::div($attrib, $msg);
209}
210
211function rcmail_message_buttons()
212{
213  global $MESSAGE, $RCMAIL, $CONFIG;
214
215  $mbox  = $RCMAIL->storage->get_folder();
216  $delim = $RCMAIL->storage->get_hierarchy_delimiter();
217  $dbox  = $CONFIG['drafts_mbox'];
218
219  // the message is not a draft
220  if ($mbox != $dbox && strpos($mbox, $dbox.$delim) !== 0) {
221    return '';
222  }
223
224  $attrib['id']    = 'message-buttons';
225  $attrib['class'] = 'notice';
226
227  $msg = Q(rcube_label('isdraft')) . '&nbsp;';
228  $msg .= html::a(array('href' => "#edit", 'onclick' => JS_OBJECT_NAME.".command('edit')"), Q(rcube_label('edit')));
229
230  return html::div($attrib, $msg);
231}
232
233function rcmail_message_objects($attrib)
234{
235  global $RCMAIL, $MESSAGE;
236
237  if (!$attrib['id'])
238    $attrib['id'] = 'message-objects';
239
240  $content = array(
241    rcmail_message_buttons(),
242    rcmail_remote_objects_msg(),
243  );
244
245  $plugin = $RCMAIL->plugins->exec_hook('message_objects',
246    array('content' => $content, 'message' => $MESSAGE));
247
248  $content = implode("\n", $plugin['content']);
249
250  return html::div($attrib, $content);
251}
252
253function rcmail_contact_exists($email)
254{
255  global $RCMAIL;
256
257  if ($email) {
258    // @TODO: search in all address books?
259    $CONTACTS = $RCMAIL->get_address_book(null, true);
260    $existing = $CONTACTS->search('email', $email, true, false);
261    if ($existing->count)
262      return true;
263  }
264
265  return false;
266}
267
268
269$OUTPUT->add_handlers(array(
270  'messageattachments' => 'rcmail_message_attachments',
271  'mailboxname' => 'rcmail_mailbox_name_display',
272  'messageobjects' => 'rcmail_message_objects',
273));
274
275
276if ($RCMAIL->action=='print' && $OUTPUT->template_exists('messageprint'))
277  $OUTPUT->send('messageprint', false);
278else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
279  $OUTPUT->send('messagepreview', false);
280else
281  $OUTPUT->send('message', false);
282
283
284// mark message as read
285if ($MESSAGE && $MESSAGE->headers && empty($MESSAGE->headers->flags['SEEN']) &&
286  ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0)))
287{
288  if ($RCMAIL->storage->set_flag($MESSAGE->uid, 'SEEN')) {
289    if ($count = rcmail_get_unseen_count($mbox_name)) {
290      rcmail_set_unseen_count($mbox_name, $count - 1);
291    }
292  }
293}
294
295exit;
296
Note: See TracBrowser for help on using the repository browser.