]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/show.inc
Imported Upstream version 0.2.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 2301 2009-02-18 19:15:36Z 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   // set message charset as default
29   if (!empty($MESSAGE->headers->charset))
30     $IMAP->set_charset($MESSAGE->headers->charset);
31
32   // go back to list if message not found (wrong UID)
33   if (empty($MESSAGE->headers)) {
34     $OUTPUT->show_message('messageopenerror', 'error');
35     if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
36         $OUTPUT->send('messagepreview');
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
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, !$MESSAGE->headers->seen);
60
61   $OUTPUT->set_pagetitle($MESSAGE->subject);
62   
63   // give message uid to the client
64   $OUTPUT->set_env('uid', $MESSAGE->uid);
65   // set environement
66   $OUTPUT->set_env('safemode', $MESSAGE->is_safe);
67   $OUTPUT->set_env('sender', $MESSAGE->sender['string']);
68   $OUTPUT->set_env('permaurl', rcmail_url('show', array('_uid' => $MESSAGE->uid, '_mbox' => $mbox_name)));
69   $OUTPUT->set_env('mailbox', $mbox_name);
70   if ($CONFIG['trash_mbox'])
71     $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']);
72   if (!$OUTPUT->ajax_call)
73     $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash', 'movingmessage');
74     
75   // check for unset disposition notification
76   if ($MESSAGE->headers->mdn_to &&
77       !$MESSAGE->headers->mdn_sent && !$MESSAGE->headers->seen &&
78       ($IMAP->check_permflag('MDNSENT') || $IMAP->check_permflag('*')) &&
79       $mbox_name != $CONFIG['drafts_mbox'] &&
80       $mbox_name != $CONFIG['sent_mbox'])
81   {
82     if (intval($CONFIG['mdn_requests']) === 1)
83     {
84       if (rcmail_send_mdn($MESSAGE->uid))
85         $OUTPUT->show_message('receiptsent', 'confirmation');
86       else
87         $OUTPUT->show_message('errorsendingreceipt', 'error');
88     }
89     else if (empty($CONFIG['mdn_requests']))
90     {
91       $OUTPUT->add_label('mdnrequest');
92       $OUTPUT->set_env('mdn_request', true);
93     }
94   }
95
96   // get previous, first, next and last message UID
97   if ($RCMAIL->action != 'preview' && $RCMAIL->action != 'print')
98     {
99     $next = $prev = $first = $last = -1;
100
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($IMAP->get_id($MESSAGE->uid), $a_msg_index);
108
109       $prev = isset($a_msg_index[$MESSAGE->index-1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index-1]) : -1 ;
110       $first = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[0]) : -1;
111       $next = isset($a_msg_index[$MESSAGE->index+1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index+1]) : -1 ;
112       $last = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[count($a_msg_index)-1]) : -1;
113       }
114     else
115       {
116       // this assumes that we are sorted by date_DESC
117       $cnt = $IMAP->messagecount();
118       $seq = $IMAP->get_id($MESSAGE->uid);
119       $MESSAGE->index = $cnt - $seq;
120
121       $prev = $IMAP->get_uid($seq + 1);
122       $first = $IMAP->get_uid($cnt);
123       $next = $IMAP->get_uid($seq - 1);
124       $last = $IMAP->get_uid(1);
125       }
126
127     if ($prev > 0)
128       $OUTPUT->set_env('prev_uid', $prev);
129     if ($first > 0)
130       $OUTPUT->set_env('first_uid', $first);
131     if ($next > 0)
132       $OUTPUT->set_env('next_uid', $next);
133     if ($last > 0)
134       $OUTPUT->set_env('last_uid', $last);
135     }
136
137   // mark message as read
138   if (!$MESSAGE->headers->seen)
139     $IMAP->set_flag($MESSAGE->uid, 'SEEN');
140   }
141
142
143
144 function rcmail_message_attachments($attrib)
145 {
146   global $PRINT_MODE, $MESSAGE;
147   
148   $out = $ol = '';
149
150   if (sizeof($MESSAGE->attachments)) {
151     foreach ($MESSAGE->attachments as $attach_prop) {
152       if ($PRINT_MODE) {
153         $ol .= html::tag('li', null, sprintf("%s (%s)", Q($attach_prop->filename), Q(show_bytes($attach_prop->size))));
154       }
155       else {
156         if (rc_strlen($attach_prop->filename) > 50) {
157           $filename = abbreviate_string($attach_prop->filename, 50);
158           $title = $attach_prop->filename;
159       }
160       else {
161         $filename = $attach_prop->filename;
162         $title = '';
163       }
164
165         $ol .= html::tag('li', null,
166           html::a(array(
167             'href' => $MESSAGE->get_part_url($attach_prop->mime_id),
168             'onclick' => sprintf(
169               'return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)',
170               JS_OBJECT_NAME,
171               $attach_prop->mime_id,
172               $attach_prop->mimetype),
173               'title' => Q($title),
174             ),
175             Q($filename)));
176       }
177     }
178
179     $out = html::tag('ul', $attrib, $ol, html::$common_attrib);
180   } 
181   
182   return $out;
183 }
184
185
186
187 function rcmail_remote_objects_msg($attrib)
188 {
189   global $MESSAGE, $RCMAIL;
190   
191   if (!$attrib['id'])
192     $attrib['id'] = 'rcmremoteobjmsg';
193   
194   $msg = Q(rcube_label('blockedimages')) . '&nbsp;';
195   $msg .= html::a(array('href' => "#loadimages", 'onclick' => JS_OBJECT_NAME.".command('load-images')"), Q(rcube_label('showimages')));
196   
197   // add link to save sender in addressbook and reload message
198   if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) {
199     $msg .= ' ' . html::a(array('href' => "#alwaysload", 'onclick' => JS_OBJECT_NAME.".command('always-load')", 'style' => "white-space:nowrap"),
200       Q(rcube_label(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
201   }
202   
203   $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
204   return html::div($attrib, $msg);
205 }
206
207
208 $OUTPUT->add_handlers(array(
209   'messageattachments' => 'rcmail_message_attachments',
210   'mailboxname' => 'rcmail_mailbox_name_display',
211   'blockedobjects' => 'rcmail_remote_objects_msg'));
212
213
214 if ($RCMAIL->action=='print' && $OUTPUT->template_exists('printmessage'))
215   $OUTPUT->send('printmessage');
216 else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
217   $OUTPUT->send('messagepreview');
218 else
219   $OUTPUT->send('message');
220 ?>