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

Last change on this file since 374 was 374, checked in by robin, 7 years ago

Add first and last buttons.

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