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

Last change on this file since 388 was 388, checked in by thomasb, 7 years ago

Introducing preview pane and conditional skin tags

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.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, 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
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  $MESSAGE['structure'] = $IMAP->get_structure($MESSAGE['UID']);
33 
34  // go back to list if message not found (wrong UID)
35  if (!$MESSAGE['headers'] || !$MESSAGE['structure'])
36    {
37    show_message('messageopenerror', 'error');
38    if ($_action=='preview' && template_exists('messagepreview'))
39        parse_template('messagepreview');
40    else
41      {
42      $_action = 'list';
43      return;
44      }
45    }
46
47  $MESSAGE['subject'] = $IMAP->decode_header($MESSAGE['headers']->subject);
48 
49  if ($MESSAGE['structure'])
50    list($MESSAGE['parts'], $MESSAGE['attachments']) = rcmail_parse_message(
51      $MESSAGE['structure'],
52      array('safe' => (bool)$_GET['_safe'],
53            'prefer_html' => $CONFIG['prefer_html'],
54            'get_url' => $GET_URL.'&_part=%s')
55      );
56  else
57    $MESSAGE['body'] = $IMAP->get_body($MESSAGE['UID']);
58
59
60  // mark message as read
61  if (!$MESSAGE['headers']->seen)
62    $IMAP->set_flag($_GET['_uid'], 'SEEN');
63
64  // give message uid to the client
65  $javascript = sprintf("%s.set_env('uid', '%s');\n", $JS_OBJECT_NAME, $MESSAGE['UID']);
66  $javascript .= sprintf("%s.set_env('safemode', '%b');", $JS_OBJECT_NAME, $_GET['_safe']);
67
68  $next = $prev = -1;
69  // get previous, first, next and last message UID
70  if (!($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] == 'DESC') &&
71      $IMAP->get_capability('sort'))
72    {
73    // Only if we use custom sorting
74    $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
75 
76    $MESSAGE['index'] = array_search((string)$MESSAGE['UID'], $a_msg_index, TRUE);
77    $prev = isset($a_msg_index[$MESSAGE['index']-1]) ? $a_msg_index[$MESSAGE['index']-1] : -1 ;
78    $first = count($a_msg_index)>0 ? $a_msg_index[0] : -1;
79    $next = isset($a_msg_index[$MESSAGE['index']+1]) ? $a_msg_index[$MESSAGE['index']+1] : -1 ;
80    $last = count($a_msg_index)>0 ? $a_msg_index[count($a_msg_index)-1] : -1;
81    }
82  else
83    {
84    // this assumes that we are sorted by date_DESC
85    $seq = $IMAP->get_id($MESSAGE['UID']);
86    $prev = $IMAP->get_uid($seq + 1);
87    $first = $IMAP->get_uid($IMAP->messagecount());
88    $next = $IMAP->get_uid($seq - 1);
89    $last = $IMAP->get_uid(1);
90    $MESSAGE['index'] = $IMAP->messagecount() - $seq;
91    }
92 
93  if ($prev > 0)
94    $javascript .= sprintf("\n%s.set_env('prev_uid', '%s');", $JS_OBJECT_NAME, $prev);
95  if ($first >0)
96    $javascript .= sprintf("\n%s.set_env('first_uid', '%s');", $JS_OBJECT_NAME, $first);
97  if ($next > 0)
98    $javascript .= sprintf("\n%s.set_env('next_uid', '%s');", $JS_OBJECT_NAME, $next);
99  if ($last >0)
100    $javascript .= sprintf("\n%s.set_env('last_uid', '%s');", $JS_OBJECT_NAME, $last);
101
102  $OUTPUT->add_script($javascript);
103  }
104
105
106
107function rcmail_message_attachments($attrib)
108  {
109  global $CONFIG, $OUTPUT, $PRINT_MODE, $MESSAGE, $GET_URL, $JS_OBJECT_NAME;
110
111  if (sizeof($MESSAGE['attachments']))
112    {
113    // allow the following attributes to be added to the <ul> tag
114    $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
115    $out = '<ul' . $attrib_str . ">\n";
116
117    foreach ($MESSAGE['attachments'] as $attach_prop)
118      {
119      if ($PRINT_MODE)
120        $out .= sprintf('<li>%s (%s)</li>'."\n",
121                        $attach_prop->filename,
122                        show_bytes($attach_prop->size));
123      else
124        $out .= sprintf('<li><a href="%s&amp;_part=%s" onclick="return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)">%s</a></li>'."\n",
125                        htmlspecialchars($GET_URL),
126                        $attach_prop->mime_id,
127                        $JS_OBJECT_NAME,
128                        $attach_prop->mime_id,
129                        $attach_prop->mimetype,
130                        $attach_prop->filename);
131      }
132
133    $out .= "</ul>";
134    return $out;
135    } 
136  }
137
138
139
140function rcmail_remote_objects_msg($attrib)
141  {
142  global $CONFIG, $OUTPUT, $JS_OBJECT_NAME;
143 
144  if (!$attrib['id'])
145    $attrib['id'] = 'rcmremoteobjmsg';
146
147  // allow the following attributes to be added to the <div> tag
148  $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
149  $out = '<div' . $attrib_str . ">";
150 
151  $out .= rep_specialchars_output(sprintf('%s&nbsp;<a href="#loadimages" onclick="%s.command(\'load-images\')" title="%s">%s</a>',
152                                  rcube_label('blockedimages'),
153                                  $JS_OBJECT_NAME,
154                                  rcube_label('showimages'),
155                                  rcube_label('showimages')));
156 
157  $out .= '</div>';
158 
159  $OUTPUT->add_script(sprintf("%s.gui_object('remoteobjectsmsg', '%s');", $JS_OBJECT_NAME, $attrib['id']));
160  return $out;
161  }
162
163
164if ($_action=='print' && template_exists('printmessage'))
165  parse_template('printmessage');
166else if ($_action=='preview' && template_exists('messagepreview'))
167    parse_template('messagepreview');
168else
169  parse_template('message');
170?>
Note: See TracBrowser for help on using the repository browser.