]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/show.inc
Imported Upstream version 0.1
[roundcube.git] / program / steps / mail / show.inc
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: show.inc 1046 2008-02-11 23:07:44Z thomasb $
19
20 */
21
22 require_once('Mail/mimeDecode.php');
23 require_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
28 if ($_GET['_uid'])
29   {
30   $MESSAGE = array('UID' => get_input_value('_uid', RCUBE_INPUT_GET));
31   $MESSAGE['headers'] = $IMAP->get_headers($MESSAGE['UID']);
32   
33   // go back to list if message not found (wrong UID)
34   if (!$MESSAGE['headers'])
35     {
36     $OUTPUT->show_message('messageopenerror', 'error');
37     if ($_action=='preview' && template_exists('messagepreview'))
38         parse_template('messagepreview');
39     else
40       {
41       $_action = 'list';
42       return;
43       }
44     }
45     
46   // check if safe flag is set
47   if ($MESSAGE['is_safe'] = intval($_GET['_safe']))
48     $_SESSION['safe_messages'][$MESSAGE['UID']] = true;
49   else if ($_SESSION['safe_messages'][$MESSAGE['UID']])
50     $MESSAGE['is_safe'] = 1;
51
52   // calculate Etag for this request
53   $etag = md5($MESSAGE['UID'].$IMAP->get_mailbox_name().session_id().intval($MESSAGE['headers']->mdn_sent).intval($MESSAGE['is_safe']).intval($PRINT_MODE));
54
55   // allow caching, unless remote images are present
56   if ((bool)$MESSAGE['is_safe'])
57     send_nocacheing_headers();
58   else if (empty($CONFIG['devel_mode']))
59     send_modified_header($_SESSION['login_time'], $etag);
60
61   $MESSAGE['subject'] = rcube_imap::decode_mime_string($MESSAGE['headers']->subject, $MESSAGE['headers']->charset);
62   $OUTPUT->set_pagetitle($MESSAGE['subject']);
63   
64   if ($MESSAGE['structure'] = $IMAP->get_structure($MESSAGE['UID']))
65     list($MESSAGE['parts'], $MESSAGE['attachments']) = rcmail_parse_message(
66       $MESSAGE['structure'],
67       array('safe' => $MESSAGE['is_safe'],
68             'prefer_html' => $CONFIG['prefer_html'],
69             'get_url' => $GET_URL.'&_part=%s')
70       );
71   else
72     $MESSAGE['body'] = $IMAP->get_body($MESSAGE['UID']);
73
74
75   // mark message as read
76   if (!$MESSAGE['headers']->seen && $_action != 'preview')
77     $IMAP->set_flag($MESSAGE['UID'], 'SEEN');
78
79   // give message uid to the client
80   $OUTPUT->set_env('uid', $MESSAGE['UID']);
81   $OUTPUT->set_env('safemode', $MESSAGE['is_safe']);
82   
83   // check for unset disposition notification
84   if ($MESSAGE['headers']->mdn_to && !$MESSAGE['headers']->mdn_sent && $IMAP->get_mailbox_name() != $CONFIG['drafts_mbox'])
85   {
86     if (intval($CONFIG['mdn_requests']) === 1)
87     {
88       if (rcmail_send_mdn($MESSAGE['UID']))
89         $OUTPUT->show_message('receiptsent', 'confirmation');
90     }
91     else if (empty($CONFIG['mdn_requests']))
92     {
93       rcube_add_label('mdnrequest');
94       $OUTPUT->set_env('mdn_request', true);
95     }
96   }
97
98
99   $next = $prev = $first = $last = -1;
100   // get previous, first, next and last message UID
101   if ((!($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] == 'DESC') &&
102       $IMAP->get_capability('sort')) || !empty($_REQUEST['_search']))
103     {
104     // Only if we use custom sorting
105     $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
106  
107     $MESSAGE['index'] = array_search((string)$MESSAGE['UID'], $a_msg_index, TRUE);
108     $prev = isset($a_msg_index[$MESSAGE['index']-1]) ? $a_msg_index[$MESSAGE['index']-1] : -1 ;
109     $first = count($a_msg_index)>0 ? $a_msg_index[0] : -1;
110     $next = isset($a_msg_index[$MESSAGE['index']+1]) ? $a_msg_index[$MESSAGE['index']+1] : -1 ;
111     $last = count($a_msg_index)>0 ? $a_msg_index[count($a_msg_index)-1] : -1;
112     }
113   else
114     {
115     // this assumes that we are sorted by date_DESC
116     $seq = $IMAP->get_id($MESSAGE['UID']);
117     $prev = $IMAP->get_uid($seq + 1);
118     $first = $IMAP->get_uid($IMAP->messagecount());
119     $next = $IMAP->get_uid($seq - 1);
120     $last = $IMAP->get_uid(1);
121     $MESSAGE['index'] = $IMAP->messagecount() - $seq;
122     }
123   
124   if ($prev > 0)
125     $OUTPUT->set_env('prev_uid', $prev);
126   if ($first >0)
127     $OUTPUT->set_env('first_uid', $first);
128   if ($next > 0)
129     $OUTPUT->set_env('next_uid', $next);
130   if ($last >0)
131     $OUTPUT->set_env('last_uid', $last);
132   }
133
134
135
136 function rcmail_message_attachments($attrib)
137   {
138   global $CONFIG, $OUTPUT, $PRINT_MODE, $MESSAGE, $GET_URL;
139
140   if (sizeof($MESSAGE['attachments']))
141     {
142     // allow the following attributes to be added to the <ul> tag
143     $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
144     $out = '<ul' . $attrib_str . ">\n";
145
146     foreach ($MESSAGE['attachments'] as $attach_prop)
147       {
148       if ($PRINT_MODE)
149         $out .= sprintf('<li>%s (%s)</li>'."\n",
150                         $attach_prop->filename,
151                         show_bytes($attach_prop->size));
152       else
153         $out .= sprintf('<li><a href="%s&amp;_part=%s" onclick="return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)">%s</a></li>'."\n",
154                         htmlspecialchars($GET_URL),
155                         $attach_prop->mime_id,
156                         JS_OBJECT_NAME,
157                         $attach_prop->mime_id,
158                         $attach_prop->mimetype,
159                         $attach_prop->filename);
160       }
161
162     $out .= "</ul>";
163     return $out;
164     }  
165   }
166
167
168
169 function rcmail_remote_objects_msg($attrib)
170   {
171   global $CONFIG, $OUTPUT;
172   
173   if (!$attrib['id'])
174     $attrib['id'] = 'rcmremoteobjmsg';
175
176   // allow the following attributes to be added to the <div> tag
177   $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
178   $out = '<div' . $attrib_str . ">";
179   
180   $out .= sprintf('%s&nbsp;<a href="#loadimages" onclick="%s.command(\'load-images\')">%s</a>',
181                   Q(rcube_label('blockedimages')),
182                   JS_OBJECT_NAME,
183                   Q(rcube_label('showimages')));
184   
185   $out .= '</div>';
186   
187   $OUTPUT->add_gui_object('remoteobjectsmsg', $attrib['id']);
188   return $out;
189   }
190
191
192 $OUTPUT->add_handlers(array(
193   'messageattachments' => 'rcmail_message_attachments',
194   'blockedobjects' => 'rcmail_remote_objects_msg'));
195
196
197 if ($_action=='print' && template_exists('printmessage'))
198   parse_template('printmessage');
199 else if ($_action=='preview' && template_exists('messagepreview'))
200     parse_template('messagepreview');
201 else
202   parse_template('message');
203 ?>