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

Last change on this file since 942 was 942, checked in by thomasb, 6 years ago

Regard mdn flag in etag for caching

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 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-2007, 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
22require_once('Mail/mimeDecode.php');
23
24$PRINT_MODE = $_action=='print' ? TRUE : FALSE;
25
26// similar code as in program/steps/mail/get.inc
27if ($_GET['_uid'])
28  {
29  $MESSAGE = array('UID' => get_input_value('_uid', RCUBE_INPUT_GET));
30  $MESSAGE['headers'] = $IMAP->get_headers($MESSAGE['UID']);
31 
32  // go back to list if message not found (wrong UID)
33  if (!$MESSAGE['headers'])
34    {
35    $OUTPUT->show_message('messageopenerror', 'error');
36    if ($_action=='preview' && template_exists('messagepreview'))
37        parse_template('messagepreview');
38    else
39      {
40      $_action = 'list';
41      return;
42      }
43    }
44
45  // calculate Etag for this request
46  $etag = md5($MESSAGE['UID'].$IMAP->get_mailbox_name().session_id().intval($MESSAGE['headers']->mdn_sent).intval($PRINT_MODE));
47
48  // allow caching, unless remote images are present
49  if ((bool)get_input_value('_safe', RCUBE_INPUT_GET))
50    send_nocacheing_headers();
51  else if (empty($CONFIG['devel_mode']))
52    send_modified_header($_SESSION['login_time'], $etag);
53
54  $MESSAGE['subject'] = rcube_imap::decode_mime_string($MESSAGE['headers']->subject, $MESSAGE['headers']->charset);
55  $OUTPUT->set_pagetitle($MESSAGE['subject']);
56 
57  if ($MESSAGE['structure'] = $IMAP->get_structure($MESSAGE['UID']))
58    list($MESSAGE['parts'], $MESSAGE['attachments']) = rcmail_parse_message(
59      $MESSAGE['structure'],
60      array('safe' => intval($_GET['_safe']),
61            'prefer_html' => $CONFIG['prefer_html'],
62            'get_url' => $GET_URL.'&_part=%s')
63      );
64  else
65    $MESSAGE['body'] = $IMAP->get_body($MESSAGE['UID']);
66
67
68  // mark message as read
69  if (!$MESSAGE['headers']->seen && $_action != 'preview')
70    $IMAP->set_flag($MESSAGE['UID'], 'SEEN');
71
72  // give message uid to the client
73  $OUTPUT->set_env('uid', $MESSAGE['UID']);
74  $OUTPUT->set_env('safemode', intval($_GET['_safe']));
75 
76  // check for unset disposition notification
77  if ($MESSAGE['headers']->mdn_to && !$MESSAGE['headers']->mdn_sent)
78  {
79    rcube_add_label('mdnrequest');
80    $OUTPUT->set_env('mdn_request', true);
81  }
82
83  $next = $prev = -1;
84  // get previous, first, next and last message UID
85  if (!($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] == 'DESC') &&
86      $IMAP->get_capability('sort'))
87    {
88    // Only if we use custom sorting
89    $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
90 
91    $MESSAGE['index'] = array_search((string)$MESSAGE['UID'], $a_msg_index, TRUE);
92    $prev = isset($a_msg_index[$MESSAGE['index']-1]) ? $a_msg_index[$MESSAGE['index']-1] : -1 ;
93    $first = count($a_msg_index)>0 ? $a_msg_index[0] : -1;
94    $next = isset($a_msg_index[$MESSAGE['index']+1]) ? $a_msg_index[$MESSAGE['index']+1] : -1 ;
95    $last = count($a_msg_index)>0 ? $a_msg_index[count($a_msg_index)-1] : -1;
96    }
97  else
98    {
99    // this assumes that we are sorted by date_DESC
100    $seq = $IMAP->get_id($MESSAGE['UID']);
101    $prev = $IMAP->get_uid($seq + 1);
102    $first = $IMAP->get_uid($IMAP->messagecount());
103    $next = $IMAP->get_uid($seq - 1);
104    $last = $IMAP->get_uid(1);
105    $MESSAGE['index'] = $IMAP->messagecount() - $seq;
106    }
107 
108  if ($prev > 0)
109    $OUTPUT->set_env('prev_uid', $prev);
110  if ($first >0)
111    $OUTPUT->set_env('first_uid', $first);
112  if ($next > 0)
113    $OUTPUT->set_env('next_uid', $next);
114  if ($last >0)
115    $OUTPUT->set_env('last_uid', $last);
116  }
117
118
119
120function rcmail_message_attachments($attrib)
121  {
122  global $CONFIG, $OUTPUT, $PRINT_MODE, $MESSAGE, $GET_URL;
123
124  if (sizeof($MESSAGE['attachments']))
125    {
126    // allow the following attributes to be added to the <ul> tag
127    $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
128    $out = '<ul' . $attrib_str . ">\n";
129
130    foreach ($MESSAGE['attachments'] as $attach_prop)
131      {
132      if ($PRINT_MODE)
133        $out .= sprintf('<li>%s (%s)</li>'."\n",
134                        $attach_prop->filename,
135                        show_bytes($attach_prop->size));
136      else
137        $out .= sprintf('<li><a href="%s&amp;_part=%s" onclick="return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)">%s</a></li>'."\n",
138                        htmlspecialchars($GET_URL),
139                        $attach_prop->mime_id,
140                        JS_OBJECT_NAME,
141                        $attach_prop->mime_id,
142                        $attach_prop->mimetype,
143                        $attach_prop->filename);
144      }
145
146    $out .= "</ul>";
147    return $out;
148    } 
149  }
150
151
152
153function rcmail_remote_objects_msg($attrib)
154  {
155  global $CONFIG, $OUTPUT;
156 
157  if (!$attrib['id'])
158    $attrib['id'] = 'rcmremoteobjmsg';
159
160  // allow the following attributes to be added to the <div> tag
161  $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
162  $out = '<div' . $attrib_str . ">";
163 
164  $out .= sprintf('%s&nbsp;<a href="#loadimages" onclick="%s.command(\'load-images\')">%s</a>',
165                  Q(rcube_label('blockedimages')),
166                  JS_OBJECT_NAME,
167                  Q(rcube_label('showimages')));
168 
169  $out .= '</div>';
170 
171  $OUTPUT->add_gui_object('remoteobjectsmsg', $attrib['id']);
172  return $out;
173  }
174
175
176$OUTPUT->add_handlers(array(
177  'messageattachments' => 'rcmail_message_attachments',
178  'blockedobjects' => 'rcmail_remote_objects_msg'));
179
180
181if ($_action=='print' && template_exists('printmessage'))
182  parse_template('printmessage');
183else if ($_action=='preview' && template_exists('messagepreview'))
184    parse_template('messagepreview');
185else
186  parse_template('message');
187?>
Note: See TracBrowser for help on using the repository browser.