]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/show.inc
c33f6e9d5d9a502687a1679f514b0169678ad369
[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 4294 2010-12-01 09:52:23Z 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   if ($CONFIG['trash_mbox'])
56     $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']);
57   if ($CONFIG['flag_for_deletion'])
58     $OUTPUT->set_env('flag_for_deletion', true);
59   if ($CONFIG['read_when_deleted'])
60     $OUTPUT->set_env('read_when_deleted', true);
61   if ($CONFIG['skip_deleted'])
62     $OUTPUT->set_env('skip_deleted', true);
63   if ($CONFIG['display_next'])
64     $OUTPUT->set_env('display_next', true);
65   if ($MESSAGE->headers->others['list-post'])
66     $OUTPUT->set_env('list_post', true);
67
68   if (!$OUTPUT->ajax_call)
69     $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash',
70       'movingmessage', 'deletingmessage');
71
72   // check for unset disposition notification
73   if ($MESSAGE->headers->mdn_to &&
74       !$MESSAGE->headers->mdn_sent && !$MESSAGE->headers->seen &&
75       ($IMAP->check_permflag('MDNSENT') || $IMAP->check_permflag('*')) &&
76       $mbox_name != $CONFIG['drafts_mbox'] &&
77       $mbox_name != $CONFIG['sent_mbox'])
78   {
79     $mdn_cfg = intval($CONFIG['mdn_requests']);
80
81     if ($mdn_cfg == 1 || (($mdn_cfg == 3 || $mdn_cfg ==  4) && rcmail_contact_exists($MESSAGE->sender['mailto']))) {
82       // Send MDN
83       if (rcmail_send_mdn($MESSAGE, $smtp_error))
84         $OUTPUT->show_message('receiptsent', 'confirmation');
85       else if ($smtp_error)
86         $OUTPUT->show_message($smtp_error['label'], 'error', $smtp_error['vars']);
87       else
88         $OUTPUT->show_message('errorsendingreceipt', 'error');
89     }
90     else if ($mdn_cfg != 2 && $mdn_cfg != 4) {
91       // Ask user
92       $OUTPUT->add_label('mdnrequest');
93       $OUTPUT->set_env('mdn_request', true);
94     }
95   }
96
97   if (!$MESSAGE->headers->seen && ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0)))
98     $RCMAIL->plugins->exec_hook('message_read', array('uid' => $MESSAGE->uid,
99       'mailbox' => $mbox_name, 'message' => $MESSAGE));
100 }
101
102
103
104 function rcmail_message_attachments($attrib)
105 {
106   global $PRINT_MODE, $MESSAGE;
107
108   $out = $ol = '';
109
110   if (sizeof($MESSAGE->attachments)) {
111     foreach ($MESSAGE->attachments as $attach_prop) {
112       if ($PRINT_MODE) {
113         $ol .= html::tag('li', null, sprintf("%s (%s)", Q($attach_prop->filename), Q(show_bytes($attach_prop->size))));
114       }
115       else {
116         if (mb_strlen($attach_prop->filename) > 50) {
117           $filename = abbreviate_string($attach_prop->filename, 50);
118           $title = $attach_prop->filename;
119       }
120       else {
121         $filename = $attach_prop->filename;
122         $title = '';
123       }
124
125         $ol .= html::tag('li', null,
126           html::a(array(
127             'href' => $MESSAGE->get_part_url($attach_prop->mime_id),
128             'onclick' => sprintf(
129               'return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)',
130               JS_OBJECT_NAME,
131               $attach_prop->mime_id,
132               rcmail_fix_mimetype($attach_prop->mimetype)),
133               'title' => Q($title),
134             ),
135             Q($filename)));
136       }
137     }
138
139     $out = html::tag('ul', $attrib, $ol, html::$common_attrib);
140   }
141
142   return $out;
143 }
144
145 function rcmail_remote_objects_msg($attrib)
146 {
147   global $MESSAGE, $RCMAIL;
148
149   if (!$attrib['id'])
150     $attrib['id'] = 'rcmremoteobjmsg';
151
152   $msg = Q(rcube_label('blockedimages')) . '&nbsp;';
153   $msg .= html::a(array('href' => "#loadimages", 'onclick' => JS_OBJECT_NAME.".command('load-images')"), Q(rcube_label('showimages')));
154
155   // add link to save sender in addressbook and reload message
156   if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) {
157     $msg .= ' ' . html::a(array('href' => "#alwaysload", 'onclick' => JS_OBJECT_NAME.".command('always-load')", 'style' => "white-space:nowrap"),
158       Q(rcube_label(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
159   }
160
161   $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
162   return html::div($attrib, $msg);
163 }
164
165 function rcmail_contact_exists($email)
166 {
167   global $RCMAIL;
168
169   if ($email) {
170     // @TODO: search in all address books?
171     $CONTACTS = $RCMAIL->get_address_book(null, true);
172     $existing = $CONTACTS->search('email', $email, true, false);
173     if ($existing->count)
174       return true;
175   }
176
177   return false;
178 }
179
180
181 $OUTPUT->add_handlers(array(
182   'messageattachments' => 'rcmail_message_attachments',
183   'mailboxname' => 'rcmail_mailbox_name_display',
184   'blockedobjects' => 'rcmail_remote_objects_msg'));
185
186
187 if ($RCMAIL->action=='print' && $OUTPUT->template_exists('messageprint'))
188   $OUTPUT->send('messageprint', false);
189 else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview'))
190   $OUTPUT->send('messagepreview', false);
191 else
192   $OUTPUT->send('message', false);
193
194
195 // mark message as read
196 if ($MESSAGE && $MESSAGE->headers && !$MESSAGE->headers->seen &&
197   ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0)))
198 {
199   if ($IMAP->set_flag($MESSAGE->uid, 'SEEN')) {
200     if ($count = rcmail_get_unseen_count($mbox_name)) {
201       rcmail_set_unseen_count($mbox_name, $count - 1);
202     }
203   }
204 }
205
206 exit;
207