]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/show.inc
Imported Upstream version 0.3.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-2009, 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 2933 2009-09-08 08:04:17Z alec $
19
20 */
21
22 $PRINT_MODE = $RCMAIL->action=='print' ? TRUE : FALSE;
23
24 // similar code as in program/steps/mail/get.inc
25 if ($_GET['_uid']) {
26   $MESSAGE = new rcube_message(get_input_value('_uid', RCUBE_INPUT_GET));
27
28   // if message not found (wrong UID)...
29   if (empty($MESSAGE->headers)) {
30     $OUTPUT->show_message('messageopenerror', 'error');
31     // ... display error or preview page
32     if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messageerror'))
33       $OUTPUT->send('messageerror');
34     else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
35       $OUTPUT->send('messagepreview');
36     // ... go back to the list
37     else {
38       rcmail_overwrite_action('');
39       return;
40     }
41   }
42
43   $mbox_name = $IMAP->get_mailbox_name();
44   
45   // show images?
46   rcmail_check_safe($MESSAGE);
47
48   // calculate Etag for this request
49   $etag = md5($MESSAGE->uid.$mbox_name.session_id()
50     .intval($MESSAGE->headers->mdn_sent)
51     .intval($MESSAGE->is_safe)
52     .(!empty($MESSAGE->attachments) ? intval($CONFIG['inline_images']) : '')
53     .intval($PRINT_MODE)
54     .$_SESSION['sort_col'].$_SESSION['sort_order']
55     .$IMAP->messagecount($mbox_name, 'ALL', true)
56     );
57
58   // allow caching, unless remote images are present
59   if ((bool)$MESSAGE->is_safe)
60     send_nocacheing_headers();
61   else if (empty($CONFIG['devel_mode']))
62     send_modified_header($_SESSION['login_time'], $etag, !$MESSAGE->headers->seen);
63
64   // set message charset as default
65   if (!empty($MESSAGE->headers->charset))
66     $IMAP->set_charset($MESSAGE->headers->charset);
67
68   $OUTPUT->set_pagetitle($MESSAGE->subject);
69   
70   // give message uid to the client
71   $OUTPUT->set_env('uid', $MESSAGE->uid);
72   // set environement
73   $OUTPUT->set_env('safemode', $MESSAGE->is_safe);
74   $OUTPUT->set_env('sender', $MESSAGE->sender['string']);
75   $OUTPUT->set_env('permaurl', rcmail_url('show', array('_uid' => $MESSAGE->uid, '_mbox' => $mbox_name)));
76   $OUTPUT->set_env('mailbox', $mbox_name);
77
78   if ($CONFIG['trash_mbox'])
79     $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']);
80   if ($CONFIG['flag_for_deletion'])
81     $OUTPUT->set_env('flag_for_deletion', true);
82   if ($CONFIG['read_when_deleted'])
83     $OUTPUT->set_env('read_when_deleted', true);
84   if ($CONFIG['skip_deleted'])
85     $OUTPUT->set_env('skip_deleted', true);
86   if ($CONFIG['display_next'])
87     $OUTPUT->set_env('display_next', true);
88
89   if (!$OUTPUT->ajax_call)
90     $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash', 'movingmessage');
91         
92   // check for unset disposition notification
93   if ($MESSAGE->headers->mdn_to &&
94       !$MESSAGE->headers->mdn_sent && !$MESSAGE->headers->seen &&
95       ($IMAP->check_permflag('MDNSENT') || $IMAP->check_permflag('*')) &&
96       $mbox_name != $CONFIG['drafts_mbox'] &&
97       $mbox_name != $CONFIG['sent_mbox'])
98   {
99     if (intval($CONFIG['mdn_requests']) === 1)
100     {
101       if (rcmail_send_mdn($MESSAGE->uid, $smtp_error))
102         $OUTPUT->show_message('receiptsent', 'confirmation');
103       else if ($smtp_error)
104         $OUTPUT->show_message($smtp_error['label'], 'error', $smtp_error['vars']);
105       else      
106         $OUTPUT->show_message('errorsendingreceipt', 'error');
107     }
108     else if (empty($CONFIG['mdn_requests']))
109     {
110       $OUTPUT->add_label('mdnrequest');
111       $OUTPUT->set_env('mdn_request', true);
112     }
113   }
114
115   // get previous, first, next and last message UID
116   if ($RCMAIL->action != 'preview' && $RCMAIL->action != 'print')
117     {
118     $next = $prev = $first = $last = -1;
119
120     if ($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] != 'DESC'
121         && empty($_REQUEST['_search']) && !$IMAP->skip_deleted)
122       {
123       // this assumes that we are sorted by date_DESC
124       $cnt = $IMAP->messagecount();
125       $seq = $IMAP->get_id($MESSAGE->uid);
126       $MESSAGE->index = $cnt - $seq;
127
128       $prev = $IMAP->get_uid($seq + 1);
129       $first = $IMAP->get_uid($cnt);
130       $next = $IMAP->get_uid($seq - 1);
131       $last = $IMAP->get_uid(1);
132       }
133     else 
134       {
135       // Only if we use custom sorting
136       $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
137
138       $MESSAGE->index = array_search($IMAP->get_id($MESSAGE->uid), $a_msg_index);
139
140       $prev = isset($a_msg_index[$MESSAGE->index-1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index-1]) : -1 ;
141       $first = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[0]) : -1;
142       $next = isset($a_msg_index[$MESSAGE->index+1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index+1]) : -1 ;
143       $last = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[count($a_msg_index)-1]) : -1;
144       }
145
146     if ($prev > 0)
147       $OUTPUT->set_env('prev_uid', $prev);
148     if ($first > 0)
149       $OUTPUT->set_env('first_uid', $first);
150     if ($next > 0)
151       $OUTPUT->set_env('next_uid', $next);
152     if ($last > 0)
153       $OUTPUT->set_env('last_uid', $last);
154     }
155
156   if (!$MESSAGE->headers->seen)
157     $RCMAIL->plugins->exec_hook('message_read', array('uid' => $MESSAGE->uid,
158       'mailbox' => $IMAP->mailbox, 'message' => $MESSAGE));
159 }
160
161
162
163 function rcmail_message_attachments($attrib)
164 {
165   global $PRINT_MODE, $MESSAGE;
166   
167   $out = $ol = '';
168
169   if (sizeof($MESSAGE->attachments)) {
170     foreach ($MESSAGE->attachments as $attach_prop) {
171       if ($PRINT_MODE) {
172         $ol .= html::tag('li', null, sprintf("%s (%s)", Q($attach_prop->filename), Q(show_bytes($attach_prop->size))));
173       }
174       else {
175         if (mb_strlen($attach_prop->filename) > 50) {
176           $filename = abbreviate_string($attach_prop->filename, 50);
177           $title = $attach_prop->filename;
178       }
179       else {
180         $filename = $attach_prop->filename;
181         $title = '';
182       }
183
184         $ol .= html::tag('li', null,
185           html::a(array(
186             'href' => $MESSAGE->get_part_url($attach_prop->mime_id),
187             'onclick' => sprintf(
188               'return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)',
189               JS_OBJECT_NAME,
190               $attach_prop->mime_id,
191               $attach_prop->mimetype),
192               'title' => Q($title),
193             ),
194             Q($filename)));
195       }
196     }
197
198     $out = html::tag('ul', $attrib, $ol, html::$common_attrib);
199   } 
200   
201   return $out;
202 }
203
204
205
206 function rcmail_remote_objects_msg($attrib)
207 {
208   global $MESSAGE, $RCMAIL;
209   
210   if (!$attrib['id'])
211     $attrib['id'] = 'rcmremoteobjmsg';
212   
213   $msg = Q(rcube_label('blockedimages')) . '&nbsp;';
214   $msg .= html::a(array('href' => "#loadimages", 'onclick' => JS_OBJECT_NAME.".command('load-images')"), Q(rcube_label('showimages')));
215   
216   // add link to save sender in addressbook and reload message
217   if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) {
218     $msg .= ' ' . html::a(array('href' => "#alwaysload", 'onclick' => JS_OBJECT_NAME.".command('always-load')", 'style' => "white-space:nowrap"),
219       Q(rcube_label(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
220   }
221   
222   $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
223   return html::div($attrib, $msg);
224 }
225
226
227 $OUTPUT->add_handlers(array(
228   'messageattachments' => 'rcmail_message_attachments',
229   'mailboxname' => 'rcmail_mailbox_name_display',
230   'blockedobjects' => 'rcmail_remote_objects_msg'));
231
232
233 if ($RCMAIL->action=='print' && $OUTPUT->template_exists('printmessage'))
234   $OUTPUT->send('printmessage', false);
235 else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
236   $OUTPUT->send('messagepreview', false);
237 else
238   $OUTPUT->send('message', false);
239
240
241 // mark message as read
242 if ($MESSAGE && $MESSAGE->headers && !$MESSAGE->headers->seen)
243   $IMAP->set_flag($MESSAGE->uid, 'SEEN');
244
245 exit;
246
247 ?>