source: github/program/steps/mail/show.inc @ 17b5fb7

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since 17b5fb7 was 17b5fb7, checked in by thomascube <thomas@…>, 5 years ago

Add configurable default charset for message decoding

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