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

Last change on this file since 3780 was 3780, checked in by alec, 3 years ago
  • removed PHP closing tag
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.9 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, 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 ($uid = get_input_value('_uid', RCUBE_INPUT_GET)) {
26  $MESSAGE = new rcube_message($uid);
27
28  // if message not found (wrong UID)...
29  if (empty($MESSAGE->headers)) {
30    rcmail_message_error($uid);
31  }
32
33  send_nocacheing_headers();
34
35  $mbox_name = $IMAP->get_mailbox_name();
36
37  // show images?
38  rcmail_check_safe($MESSAGE);
39
40  // set message charset as default
41  if (!empty($MESSAGE->headers->charset))
42    $IMAP->set_charset($MESSAGE->headers->charset);
43
44  $OUTPUT->set_pagetitle($MESSAGE->subject);
45
46  // give message uid to the client
47  $OUTPUT->set_env('uid', $MESSAGE->uid);
48  // set environement
49  $OUTPUT->set_env('safemode', $MESSAGE->is_safe);
50  $OUTPUT->set_env('sender', $MESSAGE->sender['string']);
51  $OUTPUT->set_env('permaurl', rcmail_url('show', array('_uid' => $MESSAGE->uid, '_mbox' => $mbox_name)));
52  $OUTPUT->set_env('mailbox', $mbox_name);
53
54  if ($CONFIG['trash_mbox'])
55    $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']);
56  if ($CONFIG['flag_for_deletion'])
57    $OUTPUT->set_env('flag_for_deletion', true);
58  if ($CONFIG['read_when_deleted'])
59    $OUTPUT->set_env('read_when_deleted', true);
60  if ($CONFIG['skip_deleted'])
61    $OUTPUT->set_env('skip_deleted', true);
62  if ($CONFIG['display_next'])
63    $OUTPUT->set_env('display_next', true);
64
65  if (!$OUTPUT->ajax_call)
66    $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash', 'movingmessage');
67
68  // check for unset disposition notification
69  if ($MESSAGE->headers->mdn_to &&
70      !$MESSAGE->headers->mdn_sent && !$MESSAGE->headers->seen &&
71      ($IMAP->check_permflag('MDNSENT') || $IMAP->check_permflag('*')) &&
72      $mbox_name != $CONFIG['drafts_mbox'] &&
73      $mbox_name != $CONFIG['sent_mbox'])
74  {
75    if (intval($CONFIG['mdn_requests']) === 1)
76    {
77      if (rcmail_send_mdn($MESSAGE->uid, $smtp_error))
78        $OUTPUT->show_message('receiptsent', 'confirmation');
79      else if ($smtp_error)
80        $OUTPUT->show_message($smtp_error['label'], 'error', $smtp_error['vars']);
81      else     
82        $OUTPUT->show_message('errorsendingreceipt', 'error');
83    }
84    else if (empty($CONFIG['mdn_requests']))
85    {
86      $OUTPUT->add_label('mdnrequest');
87      $OUTPUT->set_env('mdn_request', true);
88    }
89  }
90
91  // get previous, first, next and last message UID
92  if ($RCMAIL->action != 'preview' && $RCMAIL->action != 'print')
93    {
94    $next = $prev = $first = $last = -1;
95
96    if ($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] != 'DESC'
97        && empty($_REQUEST['_search']) && !$CONFIG['skip_deleted'] && !$IMAP->threading)
98      {
99      // this assumes that we are sorted by date_DESC
100      $cnt = $IMAP->messagecount();
101      $seq = $IMAP->get_id($MESSAGE->uid);
102      $MESSAGE->index = $cnt - $seq;
103
104      $prev = $IMAP->get_uid($seq + 1);
105      $first = $IMAP->get_uid($cnt);
106      $next = $IMAP->get_uid($seq - 1);
107      $last = $IMAP->get_uid(1);
108      }
109    else
110      {
111      // Only if we use custom sorting
112      $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
113
114      $MESSAGE->index = array_search($IMAP->get_id($MESSAGE->uid), $a_msg_index);
115
116      $count = count($a_msg_index);
117      $prev = isset($a_msg_index[$MESSAGE->index-1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index-1]) : -1;
118      $first = $count > 1 ? $IMAP->get_uid($a_msg_index[0]) : -1;
119      $next = isset($a_msg_index[$MESSAGE->index+1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index+1]) : -1;
120      $last = $count > 1 ? $IMAP->get_uid($a_msg_index[$count-1]) : -1;
121      }
122
123    if ($prev > 0)
124      $OUTPUT->set_env('prev_uid', $prev);
125    if ($first > 0)
126      $OUTPUT->set_env('first_uid', $first);
127    if ($next > 0)
128      $OUTPUT->set_env('next_uid', $next);
129    if ($last > 0)
130      $OUTPUT->set_env('last_uid', $last);
131
132    // Don't need a real messages count value
133    $OUTPUT->set_env('messagecount', 1);
134    }
135
136  if (!$MESSAGE->headers->seen && ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0)))
137    $RCMAIL->plugins->exec_hook('message_read', array('uid' => $MESSAGE->uid,
138      'mailbox' => $mbox_name, 'message' => $MESSAGE));
139}
140
141
142
143function rcmail_message_attachments($attrib)
144{
145  global $PRINT_MODE, $MESSAGE;
146 
147  $out = $ol = '';
148
149  if (sizeof($MESSAGE->attachments)) {
150    foreach ($MESSAGE->attachments as $attach_prop) {
151      if ($PRINT_MODE) {
152        $ol .= html::tag('li', null, sprintf("%s (%s)", Q($attach_prop->filename), Q(show_bytes($attach_prop->size))));
153      }
154      else {
155        if (mb_strlen($attach_prop->filename) > 50) {
156          $filename = abbreviate_string($attach_prop->filename, 50);
157          $title = $attach_prop->filename;
158      }
159      else {
160        $filename = $attach_prop->filename;
161        $title = '';
162      }
163
164        $ol .= html::tag('li', null,
165          html::a(array(
166            'href' => $MESSAGE->get_part_url($attach_prop->mime_id),
167            'onclick' => sprintf(
168              'return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)',
169              JS_OBJECT_NAME,
170              $attach_prop->mime_id,
171              $attach_prop->mimetype),
172              'title' => Q($title),
173            ),
174            Q($filename)));
175      }
176    }
177
178    $out = html::tag('ul', $attrib, $ol, html::$common_attrib);
179  }
180 
181  return $out;
182}
183
184
185
186function rcmail_remote_objects_msg($attrib)
187{
188  global $MESSAGE, $RCMAIL;
189 
190  if (!$attrib['id'])
191    $attrib['id'] = 'rcmremoteobjmsg';
192 
193  $msg = Q(rcube_label('blockedimages')) . '&nbsp;';
194  $msg .= html::a(array('href' => "#loadimages", 'onclick' => JS_OBJECT_NAME.".command('load-images')"), Q(rcube_label('showimages')));
195 
196  // add link to save sender in addressbook and reload message
197  if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) {
198    $msg .= ' ' . html::a(array('href' => "#alwaysload", 'onclick' => JS_OBJECT_NAME.".command('always-load')", 'style' => "white-space:nowrap"),
199      Q(rcube_label(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
200  }
201 
202  $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
203  return html::div($attrib, $msg);
204}
205
206
207$OUTPUT->add_handlers(array(
208  'messageattachments' => 'rcmail_message_attachments',
209  'mailboxname' => 'rcmail_mailbox_name_display',
210  'blockedobjects' => 'rcmail_remote_objects_msg'));
211
212
213if ($RCMAIL->action=='print' && $OUTPUT->template_exists('printmessage'))
214  $OUTPUT->send('printmessage', false);
215else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
216  $OUTPUT->send('messagepreview', false);
217else
218  $OUTPUT->send('message', false);
219
220
221// mark message as read
222if ($MESSAGE && $MESSAGE->headers && !$MESSAGE->headers->seen &&
223  ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0)))
224{
225  if ($IMAP->set_flag($MESSAGE->uid, 'SEEN') && $_SESSION['unseen_count'][$mbox_name])
226    $_SESSION['unseen_count'][$mbox_name] -= 1;
227}
228
229exit;
230
231
Note: See TracBrowser for help on using the repository browser.