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