]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/show.inc
Imported Upstream version 0.3
[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 2822 2009-07-31 09:07:54Z 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   if ($CONFIG['trash_mbox'])
78     $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']);
79   if (!$OUTPUT->ajax_call)
80     $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash', 'movingmessage');
81         
82   // check for unset disposition notification
83   if ($MESSAGE->headers->mdn_to &&
84       !$MESSAGE->headers->mdn_sent && !$MESSAGE->headers->seen &&
85       ($IMAP->check_permflag('MDNSENT') || $IMAP->check_permflag('*')) &&
86       $mbox_name != $CONFIG['drafts_mbox'] &&
87       $mbox_name != $CONFIG['sent_mbox'])
88   {
89     if (intval($CONFIG['mdn_requests']) === 1)
90     {
91       if (rcmail_send_mdn($MESSAGE->uid, $smtp_error))
92         $OUTPUT->show_message('receiptsent', 'confirmation');
93       else if ($smtp_error)
94         $OUTPUT->show_message($smtp_error['label'], 'error', $smtp_error['vars']);
95       else      
96         $OUTPUT->show_message('errorsendingreceipt', 'error');
97     }
98     else if (empty($CONFIG['mdn_requests']))
99     {
100       $OUTPUT->add_label('mdnrequest');
101       $OUTPUT->set_env('mdn_request', true);
102     }
103   }
104
105   // get previous, first, next and last message UID
106   if ($RCMAIL->action != 'preview' && $RCMAIL->action != 'print')
107     {
108     $next = $prev = $first = $last = -1;
109
110     if ($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] != 'DESC'
111         && empty($_REQUEST['_search']) && !$IMAP->skip_deleted)
112       {
113       // this assumes that we are sorted by date_DESC
114       $cnt = $IMAP->messagecount();
115       $seq = $IMAP->get_id($MESSAGE->uid);
116       $MESSAGE->index = $cnt - $seq;
117
118       $prev = $IMAP->get_uid($seq + 1);
119       $first = $IMAP->get_uid($cnt);
120       $next = $IMAP->get_uid($seq - 1);
121       $last = $IMAP->get_uid(1);
122       }
123     else 
124       {
125       // Only if we use custom sorting
126       $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
127
128       $MESSAGE->index = array_search($IMAP->get_id($MESSAGE->uid), $a_msg_index);
129
130       $prev = isset($a_msg_index[$MESSAGE->index-1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index-1]) : -1 ;
131       $first = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[0]) : -1;
132       $next = isset($a_msg_index[$MESSAGE->index+1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index+1]) : -1 ;
133       $last = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[count($a_msg_index)-1]) : -1;
134       }
135
136     if ($prev > 0)
137       $OUTPUT->set_env('prev_uid', $prev);
138     if ($first > 0)
139       $OUTPUT->set_env('first_uid', $first);
140     if ($next > 0)
141       $OUTPUT->set_env('next_uid', $next);
142     if ($last > 0)
143       $OUTPUT->set_env('last_uid', $last);
144     }
145
146   if ($CONFIG['display_next'])
147     $OUTPUT->set_env('display_next', true);
148
149   if (!$MESSAGE->headers->seen)
150     $RCMAIL->plugins->exec_hook('message_read', array('uid' => $MESSAGE->uid,
151       'mailbox' => $IMAP->mailbox, 'message' => $MESSAGE));
152 }
153
154
155
156 function rcmail_message_attachments($attrib)
157 {
158   global $PRINT_MODE, $MESSAGE;
159   
160   $out = $ol = '';
161
162   if (sizeof($MESSAGE->attachments)) {
163     foreach ($MESSAGE->attachments as $attach_prop) {
164       if ($PRINT_MODE) {
165         $ol .= html::tag('li', null, sprintf("%s (%s)", Q($attach_prop->filename), Q(show_bytes($attach_prop->size))));
166       }
167       else {
168         if (mb_strlen($attach_prop->filename) > 50) {
169           $filename = abbreviate_string($attach_prop->filename, 50);
170           $title = $attach_prop->filename;
171       }
172       else {
173         $filename = $attach_prop->filename;
174         $title = '';
175       }
176
177         $ol .= html::tag('li', null,
178           html::a(array(
179             'href' => $MESSAGE->get_part_url($attach_prop->mime_id),
180             'onclick' => sprintf(
181               'return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)',
182               JS_OBJECT_NAME,
183               $attach_prop->mime_id,
184               $attach_prop->mimetype),
185               'title' => Q($title),
186             ),
187             Q($filename)));
188       }
189     }
190
191     $out = html::tag('ul', $attrib, $ol, html::$common_attrib);
192   } 
193   
194   return $out;
195 }
196
197
198
199 function rcmail_remote_objects_msg($attrib)
200 {
201   global $MESSAGE, $RCMAIL;
202   
203   if (!$attrib['id'])
204     $attrib['id'] = 'rcmremoteobjmsg';
205   
206   $msg = Q(rcube_label('blockedimages')) . '&nbsp;';
207   $msg .= html::a(array('href' => "#loadimages", 'onclick' => JS_OBJECT_NAME.".command('load-images')"), Q(rcube_label('showimages')));
208   
209   // add link to save sender in addressbook and reload message
210   if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) {
211     $msg .= ' ' . html::a(array('href' => "#alwaysload", 'onclick' => JS_OBJECT_NAME.".command('always-load')", 'style' => "white-space:nowrap"),
212       Q(rcube_label(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
213   }
214   
215   $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
216   return html::div($attrib, $msg);
217 }
218
219
220 $OUTPUT->add_handlers(array(
221   'messageattachments' => 'rcmail_message_attachments',
222   'mailboxname' => 'rcmail_mailbox_name_display',
223   'blockedobjects' => 'rcmail_remote_objects_msg'));
224
225
226 if ($RCMAIL->action=='print' && $OUTPUT->template_exists('printmessage'))
227   $OUTPUT->send('printmessage', false);
228 else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
229   $OUTPUT->send('messagepreview', false);
230 else
231   $OUTPUT->send('message', false);
232
233
234 // mark message as read
235 if ($MESSAGE && $MESSAGE->headers && !$MESSAGE->headers->seen)
236   $IMAP->set_flag($MESSAGE->uid, 'SEEN');
237
238 exit;
239
240 ?>