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

Last change on this file since 2009 was 2009, checked in by estadtherr, 5 years ago

added obscure ASCII encoding aliases, added more error checking to RFC2822 date parsing

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