]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/show.inc
Fix symlink mess
[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 5801 2012-01-19 07:32:08Z 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   $mbox_name = $IMAP->get_mailbox_name();
34
35   // show images?
36   rcmail_check_safe($MESSAGE);
37
38   // set message charset as default
39   if (!empty($MESSAGE->headers->charset))
40     $IMAP->set_charset($MESSAGE->headers->charset);
41
42   $OUTPUT->set_pagetitle(abbreviate_string($MESSAGE->subject, 128, '...', true));
43
44   // give message uid to the client
45   $OUTPUT->set_env('uid', $MESSAGE->uid);
46   // set environement
47   $OUTPUT->set_env('safemode', $MESSAGE->is_safe);
48   $OUTPUT->set_env('sender', $MESSAGE->sender['string']);
49   $OUTPUT->set_env('permaurl', rcmail_url('show', array('_uid' => $MESSAGE->uid, '_mbox' => $mbox_name)));
50   $OUTPUT->set_env('delimiter', $IMAP->get_hierarchy_delimiter());
51   $OUTPUT->set_env('mailbox', $mbox_name);
52   if ($CONFIG['drafts_mbox']) {
53     $OUTPUT->set_env('drafts_mailbox', $CONFIG['drafts_mbox']);
54   }
55
56   // mimetypes supported by the browser (default settings)
57   $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');
58   $OUTPUT->set_env('mimetypes', is_string($mimetypes) ? explode(',', $mimetypes) : (array)$mimetypes);
59
60   if ($CONFIG['trash_mbox'])
61     $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']);
62   if ($CONFIG['flag_for_deletion'])
63     $OUTPUT->set_env('flag_for_deletion', true);
64   if ($CONFIG['read_when_deleted'])
65     $OUTPUT->set_env('read_when_deleted', true);
66   if ($CONFIG['skip_deleted'])
67     $OUTPUT->set_env('skip_deleted', true);
68   if ($CONFIG['display_next'])
69     $OUTPUT->set_env('display_next', true);
70   if ($MESSAGE->headers->others['list-post'])
71     $OUTPUT->set_env('list_post', true);
72   if ($CONFIG['forward_attachment'])
73     $OUTPUT->set_env('forward_attachment', true);
74
75   if (!$OUTPUT->ajax_call)
76     $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash',
77       'movingmessage', 'deletingmessage');
78
79   // check for unset disposition notification
80   if ($MESSAGE->headers->mdn_to
81       && empty($MESSAGE->headers->flags['MDNSENT'])
82       && empty($MESSAGE->headers->flags['SEEN'])
83       && ($IMAP->check_permflag('MDNSENT') || $IMAP->check_permflag('*'))
84       && $mbox_name != $CONFIG['drafts_mbox']
85       && $mbox_name != $CONFIG['sent_mbox']
86   ) {
87     $mdn_cfg = intval($CONFIG['mdn_requests']);
88
89     if ($mdn_cfg == 1 || (($mdn_cfg == 3 || $mdn_cfg ==  4) && rcmail_contact_exists($MESSAGE->sender['mailto']))) {
90       // Send MDN
91       if (rcmail_send_mdn($MESSAGE, $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 ($mdn_cfg != 2 && $mdn_cfg != 4) {
99       // Ask user
100       $OUTPUT->add_label('mdnrequest');
101       $OUTPUT->set_env('mdn_request', true);
102     }
103   }
104
105   if (empty($MESSAGE->headers->flags['SEEN'])
106     && ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0))
107   ) {
108     $RCMAIL->plugins->exec_hook('message_read', array('uid' => $MESSAGE->uid,
109       'mailbox' => $mbox_name, 'message' => $MESSAGE));
110   }
111 }
112
113
114
115 function rcmail_message_attachments($attrib)
116 {
117   global $PRINT_MODE, $MESSAGE;
118
119   $out = $ol = '';
120
121   if (sizeof($MESSAGE->attachments)) {
122     foreach ($MESSAGE->attachments as $attach_prop) {
123       if ($PRINT_MODE) {
124         $ol .= html::tag('li', null, sprintf("%s (%s)", Q($attach_prop->filename), Q(show_bytes($attach_prop->size))));
125       }
126       else {
127         if (mb_strlen($attach_prop->filename) > 50) {
128           $filename = abbreviate_string($attach_prop->filename, 50);
129           $title = $attach_prop->filename;
130       }
131       else {
132         $filename = $attach_prop->filename;
133         $title = '';
134       }
135
136         $ol .= html::tag('li', null,
137           html::a(array(
138             'href' => $MESSAGE->get_part_url($attach_prop->mime_id, false),
139             'onclick' => sprintf(
140               'return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)',
141               JS_OBJECT_NAME,
142               $attach_prop->mime_id,
143               rcmail_fix_mimetype($attach_prop->mimetype)),
144               'title' => Q($title),
145             ),
146             Q($filename)));
147       }
148     }
149
150     $out = html::tag('ul', $attrib, $ol, html::$common_attrib);
151   }
152
153   return $out;
154 }
155
156 function rcmail_remote_objects_msg()
157 {
158   global $MESSAGE, $RCMAIL;
159
160   $attrib['id']    = 'remote-objects-message';
161   $attrib['class'] = 'notice';
162   $attrib['style'] = 'display: none';
163
164   $msg = Q(rcube_label('blockedimages')) . '&nbsp;';
165   $msg .= html::a(array('href' => "#loadimages", 'onclick' => JS_OBJECT_NAME.".command('load-images')"), Q(rcube_label('showimages')));
166
167   // add link to save sender in addressbook and reload message
168   if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) {
169     $msg .= ' ' . html::a(array('href' => "#alwaysload", 'onclick' => JS_OBJECT_NAME.".command('always-load')", 'style' => "white-space:nowrap"),
170       Q(rcube_label(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
171   }
172
173   $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
174   return html::div($attrib, $msg);
175 }
176
177 function rcmail_message_buttons()
178 {
179   global $MESSAGE, $RCMAIL, $CONFIG;
180
181   $mbox  = $RCMAIL->imap->get_mailbox_name();
182   $delim = $RCMAIL->imap->get_hierarchy_delimiter();
183   $dbox  = $CONFIG['drafts_mbox'];
184
185   // the message is not a draft
186   if ($mbox != $dbox && strpos($mbox, $dbox.$delim) !== 0) {
187     return '';
188   }
189
190   $attrib['id']    = 'message-buttons';
191   $attrib['class'] = 'notice';
192
193   $msg = Q(rcube_label('isdraft')) . '&nbsp;';
194   $msg .= html::a(array('href' => "#edit", 'onclick' => JS_OBJECT_NAME.".command('edit')"), Q(rcube_label('edit')));
195
196   return html::div($attrib, $msg);
197 }
198
199 function rcmail_message_objects($attrib)
200 {
201   global $RCMAIL, $MESSAGE;
202
203   if (!$attrib['id'])
204     $attrib['id'] = 'message-objects';
205
206   $content = array(
207     rcmail_message_buttons(),
208     rcmail_remote_objects_msg(),
209   );
210
211   $plugin = $RCMAIL->plugins->exec_hook('message_objects',
212     array('content' => $content, 'message' => $MESSAGE));
213
214   $content = implode("\n", $plugin['content']);
215
216   return html::div($attrib, $content);
217 }
218
219 function rcmail_contact_exists($email)
220 {
221   global $RCMAIL;
222
223   if ($email) {
224     // @TODO: search in all address books?
225     $CONTACTS = $RCMAIL->get_address_book(null, true);
226     $existing = $CONTACTS->search('email', $email, true, false);
227     if ($existing->count)
228       return true;
229   }
230
231   return false;
232 }
233
234
235 $OUTPUT->add_handlers(array(
236   'messageattachments' => 'rcmail_message_attachments',
237   'mailboxname' => 'rcmail_mailbox_name_display',
238   'messageobjects' => 'rcmail_message_objects',
239 ));
240
241
242 if ($RCMAIL->action=='print' && $OUTPUT->template_exists('messageprint'))
243   $OUTPUT->send('messageprint', false);
244 else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
245   $OUTPUT->send('messagepreview', false);
246 else
247   $OUTPUT->send('message', false);
248
249
250 // mark message as read
251 if ($MESSAGE && $MESSAGE->headers && empty($MESSAGE->headers->flags['SEEN']) &&
252   ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0)))
253 {
254   if ($IMAP->set_flag($MESSAGE->uid, 'SEEN')) {
255     if ($count = rcmail_get_unseen_count($mbox_name)) {
256       rcmail_set_unseen_count($mbox_name, $count - 1);
257     }
258   }
259 }
260
261 exit;
262