source: subversion/trunk/roundcubemail/program/steps/mail/show.inc @ 1659

Last change on this file since 1659 was 1659, checked in by thomasb, 5 years ago

Prevent from including empty template

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 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-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
25if ($_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' && $OUTPUT->template_exists('messagepreview'))
36        $OUTPUT->send('messagepreview');
37    else {
38      rcmail_overwrite_action('');
39      return;
40    }
41  }
42   
43  $mbox_name = $IMAP->get_mailbox_name();
44 
45  // check known senders to display images
46  if (!$MESSAGE->is_safe
47      && !empty($MESSAGE->sender['mailto'])
48      && $RCMAIL->config->get('addrbook_show_images')
49      && $MESSAGE->has_html_part()) {
50    $CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
51   
52    if ($CONTACTS->search('email', $MESSAGE->sender['mailto'], true, false)->count) {
53      $MESSAGE->set_safe(true);
54    }
55  }
56
57  // calculate Etag for this request
58  $etag = md5($MESSAGE->uid.$mbox_name.session_id().intval($MESSAGE->headers->mdn_sent).intval($MESSAGE->is_safe).intval($PRINT_MODE));
59
60  // allow caching, unless remote images are present
61  if ((bool)$MESSAGE->is_safe)
62    send_nocacheing_headers();
63  else if (empty($CONFIG['devel_mode']))
64    send_modified_header($_SESSION['login_time'], $etag, !$MESSAGE->headers->seen);
65
66  $OUTPUT->set_pagetitle($MESSAGE->subject);
67 
68  // mark message as read
69  if (!$MESSAGE->headers->seen)
70  {
71    $marked = $IMAP->set_flag($MESSAGE->uid, 'SEEN');
72    if($RCMAIL->action == 'preview' && $marked != -1)
73    {
74      $OUTPUT->command('set_unread_count_from_preview', $mbox_name, $IMAP->messagecount($mbox_name, 'UNSEEN'), ($mbox_name == 'INBOX'));
75      $OUTPUT->command('mark_as_read_from_preview', $MESSAGE->uid);
76    }
77  }
78
79  // give message uid to the client
80  $OUTPUT->set_env('uid', $MESSAGE->uid);
81  $OUTPUT->set_env('safemode', $MESSAGE->is_safe);
82  $OUTPUT->set_env('sender', $MESSAGE->sender['string']);
83 
84  // check for unset disposition notification
85  if ($MESSAGE->headers->mdn_to &&
86      !$MESSAGE->headers->mdn_sent &&
87      $IMAP->check_permflag('MDNSENT') &&
88      $mbox_name != $CONFIG['drafts_mbox'] &&
89      $mbox_name != $CONFIG['sent_mbox'])
90  {
91    if (intval($CONFIG['mdn_requests']) === 1)
92    {
93      if (rcmail_send_mdn($MESSAGE->uid))
94        $OUTPUT->show_message('receiptsent', 'confirmation');
95    }
96    else if (empty($CONFIG['mdn_requests']))
97    {
98      rcube_add_label('mdnrequest');
99      $OUTPUT->set_env('mdn_request', true);
100    }
101  }
102
103
104  $next = $prev = $first = $last = -1;
105  // get previous, first, next and last message UID
106  if ((!($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] == 'DESC') &&
107      $IMAP->get_capability('sort')) || !empty($_REQUEST['_search']))
108    {
109    // Only if we use custom sorting
110    $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
111 
112    $MESSAGE->index = array_search((string)$MESSAGE->uid, $a_msg_index, TRUE);
113    $prev = isset($a_msg_index[$MESSAGE->index-1]) ? $a_msg_index[$MESSAGE->index-1] : -1 ;
114    $first = count($a_msg_index)>0 ? $a_msg_index[0] : -1;
115    $next = isset($a_msg_index[$MESSAGE->index+1]) ? $a_msg_index[$MESSAGE->index+1] : -1 ;
116    $last = count($a_msg_index)>0 ? $a_msg_index[count($a_msg_index)-1] : -1;
117    }
118  else
119    {
120    // this assumes that we are sorted by date_DESC
121    $seq = $IMAP->get_id($MESSAGE->uid);
122    $prev = $IMAP->get_uid($seq + 1);
123    $first = $IMAP->get_uid($IMAP->messagecount());
124    $next = $IMAP->get_uid($seq - 1);
125    $last = $IMAP->get_uid(1);
126    $MESSAGE->index = $IMAP->messagecount() - $seq;
127    }
128 
129  if ($prev > 0)
130    $OUTPUT->set_env('prev_uid', $prev);
131  if ($first >0)
132    $OUTPUT->set_env('first_uid', $first);
133  if ($next > 0)
134    $OUTPUT->set_env('next_uid', $next);
135  if ($last >0)
136    $OUTPUT->set_env('last_uid', $last);
137  }
138
139
140
141function rcmail_message_attachments($attrib)
142{
143  global $PRINT_MODE, $MESSAGE;
144 
145  $out = $ol = '';
146
147  if (sizeof($MESSAGE->attachments)) {
148    foreach ($MESSAGE->attachments as $attach_prop) {
149      if ($PRINT_MODE) {
150        $ol .= html::tag('li', null, sprintf("%s (%s)", Q($attach_prop->filename), Q(show_bytes($attach_prop->size))));
151      }
152      else {
153        $ol .= html::tag('li', null,
154          html::a(array(
155            'href' => $MESSAGE->get_part_url($attach_prop->mime_id),
156            'onclick' => sprintf(
157              'return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)',
158              JS_OBJECT_NAME,
159              $attach_prop->mime_id,
160              $attach_prop->mimetype),
161            ),
162            Q($attach_prop->filename)));
163      }
164    }
165
166    $out = html::tag('ul', $attrib, $ol, html::$common_attrib);
167  }
168 
169  return $out;
170}
171
172
173
174function rcmail_remote_objects_msg($attrib)
175{
176  global $MESSAGE, $RCMAIL;
177 
178  if (!$attrib['id'])
179    $attrib['id'] = 'rcmremoteobjmsg';
180 
181  $msg = Q(rcube_label('blockedimages')) . '&nbsp;';
182  $msg .= html::a(array('href' => "#loadimages", 'onclick' => JS_OBJECT_NAME.".command('load-images')"), Q(rcube_label('showimages')));
183 
184  // add link to save sender in addressbook and reload message
185  if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('addrbook_show_images')) {
186    $msg .= ' ' . html::a(array('href' => "#alwaysload", 'onclick' => JS_OBJECT_NAME.".command('always-load')", 'style' => "white-space:nowrap"),
187      Q(rcube_label(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
188  }
189 
190  $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
191  return html::div($attrib, $msg);
192}
193
194
195$OUTPUT->add_handlers(array(
196  'messageattachments' => 'rcmail_message_attachments',
197  'mailboxname' => 'rcmail_mailbox_name_display',
198  'blockedobjects' => 'rcmail_remote_objects_msg'));
199
200
201if ($RCMAIL->action=='print' && $OUTPUT->template_exists('printmessage'))
202  $OUTPUT->send('printmessage');
203else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
204    $OUTPUT->send('messagepreview');
205else
206  $OUTPUT->send('message');
207?>
Note: See TracBrowser for help on using the repository browser.