]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/show.inc
a1f9977e1e3cac6dd565a5b7ab2b6e5b246398d4
[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, The Roundcube Dev Team                       |
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 5151 2011-08-31 12:49:44Z 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 ($uid = get_input_value('_uid', RCUBE_INPUT_GET)) {
26   $MESSAGE = new rcube_message($uid);
27
28   // if message not found (wrong UID)...
29   if (empty($MESSAGE->headers)) {
30     rcmail_message_error($uid);
31   }
32
33   send_nocacheing_headers();
34
35   $mbox_name = $IMAP->get_mailbox_name();
36
37   // show images?
38   rcmail_check_safe($MESSAGE);
39
40   // set message charset as default
41   if (!empty($MESSAGE->headers->charset))
42     $IMAP->set_charset($MESSAGE->headers->charset);
43
44   $OUTPUT->set_pagetitle(abbreviate_string($MESSAGE->subject, 128, '...', true));
45
46   // give message uid to the client
47   $OUTPUT->set_env('uid', $MESSAGE->uid);
48   // set environement
49   $OUTPUT->set_env('safemode', $MESSAGE->is_safe);
50   $OUTPUT->set_env('sender', $MESSAGE->sender['string']);
51   $OUTPUT->set_env('permaurl', rcmail_url('show', array('_uid' => $MESSAGE->uid, '_mbox' => $mbox_name)));
52   $OUTPUT->set_env('delimiter', $IMAP->get_hierarchy_delimiter());
53   $OUTPUT->set_env('mailbox', $mbox_name);
54
55   // mimetypes supported by the browser (default settings)
56   $mimetypes = $RCMAIL->config->get('client_mimetypes', 'text/plain,text/html,text/xml,image/jpeg,image/gif,image/png,application/x-javascript,application/pdf,application/x-shockwave-flash');
57   $OUTPUT->set_env('mimetypes', is_string($mimetypes) ? explode(',', $mimetypes) : (array)$mimetypes);
58
59   if ($CONFIG['trash_mbox'])
60     $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']);
61   if ($CONFIG['flag_for_deletion'])
62     $OUTPUT->set_env('flag_for_deletion', true);
63   if ($CONFIG['read_when_deleted'])
64     $OUTPUT->set_env('read_when_deleted', true);
65   if ($CONFIG['skip_deleted'])
66     $OUTPUT->set_env('skip_deleted', true);
67   if ($CONFIG['display_next'])
68     $OUTPUT->set_env('display_next', true);
69   if ($MESSAGE->headers->others['list-post'])
70     $OUTPUT->set_env('list_post', true);
71   if ($CONFIG['forward_attachment'])
72     $OUTPUT->set_env('forward_attachment', true);
73
74   if (!$OUTPUT->ajax_call)
75     $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash',
76       'movingmessage', 'deletingmessage');
77
78   // check for unset disposition notification
79   if ($MESSAGE->headers->mdn_to &&
80       !$MESSAGE->headers->mdn_sent && !$MESSAGE->headers->seen &&
81       ($IMAP->check_permflag('MDNSENT') || $IMAP->check_permflag('*')) &&
82       $mbox_name != $CONFIG['drafts_mbox'] &&
83       $mbox_name != $CONFIG['sent_mbox'])
84   {
85     $mdn_cfg = intval($CONFIG['mdn_requests']);
86
87     if ($mdn_cfg == 1 || (($mdn_cfg == 3 || $mdn_cfg ==  4) && rcmail_contact_exists($MESSAGE->sender['mailto']))) {
88       // Send MDN
89       if (rcmail_send_mdn($MESSAGE, $smtp_error))
90         $OUTPUT->show_message('receiptsent', 'confirmation');
91       else if ($smtp_error)
92         $OUTPUT->show_message($smtp_error['label'], 'error', $smtp_error['vars']);
93       else
94         $OUTPUT->show_message('errorsendingreceipt', 'error');
95     }
96     else if ($mdn_cfg != 2 && $mdn_cfg != 4) {
97       // Ask user
98       $OUTPUT->add_label('mdnrequest');
99       $OUTPUT->set_env('mdn_request', true);
100     }
101   }
102
103   if (!$MESSAGE->headers->seen && ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0)))
104     $RCMAIL->plugins->exec_hook('message_read', array('uid' => $MESSAGE->uid,
105       'mailbox' => $mbox_name, 'message' => $MESSAGE));
106 }
107
108
109
110 function rcmail_message_attachments($attrib)
111 {
112   global $PRINT_MODE, $MESSAGE;
113
114   $out = $ol = '';
115
116   if (sizeof($MESSAGE->attachments)) {
117     foreach ($MESSAGE->attachments as $attach_prop) {
118       if ($PRINT_MODE) {
119         $ol .= html::tag('li', null, sprintf("%s (%s)", Q($attach_prop->filename), Q(show_bytes($attach_prop->size))));
120       }
121       else {
122         if (mb_strlen($attach_prop->filename) > 50) {
123           $filename = abbreviate_string($attach_prop->filename, 50);
124           $title = $attach_prop->filename;
125       }
126       else {
127         $filename = $attach_prop->filename;
128         $title = '';
129       }
130
131         $ol .= html::tag('li', null,
132           html::a(array(
133             'href' => $MESSAGE->get_part_url($attach_prop->mime_id),
134             'onclick' => sprintf(
135               'return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)',
136               JS_OBJECT_NAME,
137               $attach_prop->mime_id,
138               rcmail_fix_mimetype($attach_prop->mimetype)),
139               'title' => Q($title),
140             ),
141             Q($filename)));
142       }
143     }
144
145     $out = html::tag('ul', $attrib, $ol, html::$common_attrib);
146   }
147
148   return $out;
149 }
150
151 function rcmail_remote_objects_msg($attrib)
152 {
153   global $MESSAGE, $RCMAIL;
154
155   if (!$attrib['id'])
156     $attrib['id'] = 'rcmremoteobjmsg';
157
158   $msg = Q(rcube_label('blockedimages')) . '&nbsp;';
159   $msg .= html::a(array('href' => "#loadimages", 'onclick' => JS_OBJECT_NAME.".command('load-images')"), Q(rcube_label('showimages')));
160
161   // add link to save sender in addressbook and reload message
162   if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) {
163     $msg .= ' ' . html::a(array('href' => "#alwaysload", 'onclick' => JS_OBJECT_NAME.".command('always-load')", 'style' => "white-space:nowrap"),
164       Q(rcube_label(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
165   }
166
167   $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
168   return html::div($attrib, $msg);
169 }
170
171 function rcmail_contact_exists($email)
172 {
173   global $RCMAIL;
174
175   if ($email) {
176     // @TODO: search in all address books?
177     $CONTACTS = $RCMAIL->get_address_book(null, true);
178     $existing = $CONTACTS->search('email', $email, true, false);
179     if ($existing->count)
180       return true;
181   }
182
183   return false;
184 }
185
186
187 $OUTPUT->add_handlers(array(
188   'messageattachments' => 'rcmail_message_attachments',
189   'mailboxname' => 'rcmail_mailbox_name_display',
190   'blockedobjects' => 'rcmail_remote_objects_msg'));
191
192
193 if ($RCMAIL->action=='print' && $OUTPUT->template_exists('messageprint'))
194   $OUTPUT->send('messageprint', false);
195 else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
196   $OUTPUT->send('messagepreview', false);
197 else
198   $OUTPUT->send('message', false);
199
200
201 // mark message as read
202 if ($MESSAGE && $MESSAGE->headers && !$MESSAGE->headers->seen &&
203   ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0)))
204 {
205   if ($IMAP->set_flag($MESSAGE->uid, 'SEEN')) {
206     if ($count = rcmail_get_unseen_count($mbox_name)) {
207       rcmail_set_unseen_count($mbox_name, $count - 1);
208     }
209   }
210 }
211
212 exit;
213