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

Last change on this file since 1285 was 1285, checked in by alec, 5 years ago

#1484972: optimization: mark as read in one action with preview, deleted redundant quota reads

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