Explicitly disable caching for left_main and right_main pages (#2983134)
[squirrelmail.git] / src / right_main.php
1 <?php
2
3 /**
4 * right_main.php
5 *
6 * This is where the mailboxes are listed. This controls most of what
7 * goes on in SquirrelMail.
8 *
9 * @copyright 1999-2010 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
12 * @package squirrelmail
13 */
14
15 /** This is the right_main page */
16 define('PAGE_NAME', 'right_main');
17
18 //xdebug_start_profiling("/var/spool/xdebug/right_main.txt");
19
20 /* Disable browser caching */
21 header('Cache-Control: no-cache, no-store, must-revalidate');
22 header('Pragma: no-cache');
23 header('Expires: ' . gmdate(DATE_RFC1123, time()-1));
24
25 /**
26 * Include the SquirrelMail initialization file.
27 */
28 include('../include/init.php');
29
30 /* If email_address not set and admin wants us to ask user for it,
31 * redirect to options page. */
32 if ( $ask_user_info && getPref($data_dir, $username,'email_address') == "" ) {
33 header("Location: " . get_location() . "/options.php?optpage=personal");
34 exit;
35 }
36
37 /* SquirrelMail required files. */
38 require_once(SM_PATH . 'functions/imap_asearch.php');
39 require_once(SM_PATH . 'functions/imap_general.php');
40 require_once(SM_PATH . 'functions/imap_messages.php');
41 require_once(SM_PATH . 'functions/date.php');
42 require_once(SM_PATH . 'functions/mime.php');
43 require_once(SM_PATH . 'functions/mailbox_display.php');
44 require_once(SM_PATH . 'functions/compose.php');
45
46 /* lets get the global vars we may need */
47 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
48 sqgetGlobalVar('delayed_errors', $delayed_errors, SQ_SESSION);
49 if (is_array($delayed_errors)) {
50 $oErrorHandler->AssignDelayedErrors($delayed_errors);
51 sqsession_unregister("delayed_errors");
52 }
53 sqgetGlobalVar('mailbox', $mailbox);
54 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
55 sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST);
56 sqgetGlobalVar('note', $note, SQ_GET);
57 sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET);
58
59
60 if ( sqGetGlobalVarMultiple('startMessage', $temp, 'paginator_submit') ) {
61 $startMessage = (int) $temp;
62 } else {
63 $startMessage = 1;
64 }
65 // sort => srt because of the changed behaviour which can break new behaviour
66 if ( sqgetGlobalVar('srt', $temp, SQ_GET) ) {
67 $srt = (int) $temp;
68 }
69
70 if ( sqgetGlobalVar('showall', $temp, SQ_GET) ) {
71 $showall = (int) $temp;
72 }
73
74 if (!sqgetGlobalVar('checkall',$checkall,SQ_GET)) {
75 $checkall = false;
76 }
77
78 if (!sqgetGlobalVar('preselected', $preselected, SQ_GET) || !is_array($preselected)) {
79 $preselected = array();
80 } else {
81 $preselected = array_keys($preselected);
82 }
83
84 /* future work */
85 if ( sqgetGlobalVar('account', $account, SQ_GET) ) {
86 $account = (int) $account;
87 } else {
88 $account = 0;
89 }
90
91 /* end of get globals */
92
93
94 /* Open an imap connection */
95
96 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
97
98 $mailbox = (isset($mailbox) && $mailbox) ? $mailbox : 'INBOX';
99
100 /**
101 * Set the global settings for a mailbox and merge them with the usersettings
102 * for the mailbox. In the future we can add more mailbox specific preferences
103 * preferences.
104 */
105
106 $aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$account.'_'.$mailbox);
107 if ($aMailboxPrefSer) {
108 $aMailboxPref = unserialize($aMailboxPrefSer);
109 $aMailboxPref[MBX_PREF_COLUMNS] = $index_order; // index_order contains the columns to show and the order of the columns
110 } else {
111 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($default_mailbox_pref));
112 $aMailboxPref = $default_mailbox_pref;
113 }
114 if (isset($srt)) {
115 $aMailboxPref[MBX_PREF_SORT] = (int) $srt;
116 }
117
118 $trash_folder = (isset($trash_folder)) ? $trash_folder : false;
119 $sent_folder = (isset($sent_folder)) ? $sent_folder : false;
120 $draft_folder = (isset($draft_folder)) ? $draft_folder : false;
121
122
123 /**
124 * until there is no per mailbox option screen to set prefs we override
125 * the mailboxprefs by the default ones
126 */
127 $aMailboxPref[MBX_PREF_LIMIT] = (int) $show_num;
128 $aMailboxPref[MBX_PREF_AUTO_EXPUNGE] = (bool) $auto_expunge;
129 $aMailboxPref[MBX_PREF_INTERNALDATE] = (bool) getPref($data_dir, $username, 'internal_date_sort');
130 $aMailboxPref[MBX_PREF_COLUMNS] = $index_order;
131
132 /**
133 * Replace From => To in case it concerns a draft or sent folder
134 */
135 if (handleAsSent($mailbox)
136 && !in_array(SQM_COL_TO,$aMailboxPref[MBX_PREF_COLUMNS])) {
137 $aNewOrder = array(); // nice var name ;)
138 foreach($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
139 if ($iCol == SQM_COL_FROM) {
140 $iCol = SQM_COL_TO;
141 }
142 $aNewOrder[] = $iCol;
143 }
144 $aMailboxPref[MBX_PREF_COLUMNS] = $aNewOrder;
145 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($aMailboxPref));
146 }
147
148
149
150 /**
151 * Set the config options for the messages list
152 */
153 $aColumns = array(); // contains settings per column. Switch to key -> value based array, order is the order of the array keys
154 foreach ($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
155 $aColumns[$iCol] = array();
156 switch ($iCol) {
157 case SQM_COL_SUBJ:
158 if ($truncate_subject) {
159 $aColumns[$iCol]['truncate'] = $truncate_subject;
160 }
161 break;
162 case SQM_COL_FROM:
163 case SQM_COL_TO:
164 case SQM_COL_CC:
165 case SQM_COL_BCC:
166 if ($truncate_sender) {
167 $aColumns[$iCol]['truncate'] = $truncate_sender;
168 }
169 break;
170 }
171 }
172
173 /**
174 * Properties required by showMessagesForMailbox
175 */
176 $aProps = array(
177 'columns' => $aColumns, // columns bound settings
178 'config' => array('alt_index_colors' => $alt_index_colors, // alternating row colors (should be a template thing)
179 'highlight_list' => $message_highlight_list, // row highlighting rules
180 'fancy_index_highlite' => $fancy_index_highlite, // highlight rows on hover or on click -> check
181 'show_flag_buttons' => (isset($show_flag_buttons)) ? $show_flag_buttons : true,
182 'lastTargetMailbox' => (isset($lastTargetMailbox)) ? $lastTargetMailbox : '', // last mailbox where messages are moved/copied to
183 'trash_folder' => $trash_folder,
184 'sent_folder' => $sent_folder,
185 'draft_folder' => $draft_folder,
186 'color' => $color,
187 'enablesort' => true // enable sorting on columns
188 ),
189 'mailbox' => $mailbox,
190 'account' => (isset($account)) ? $account : 0, // future usage if we support multiple imap accounts
191 'module' => 'read_body',
192 'email' => false);
193
194
195 /**
196 * system wide admin settings and incoming vars.
197 */
198 $aConfig = array(
199 'user' => $username,
200 // incoming vars
201 'offset' => $startMessage // offset in paginator
202 );
203 /**
204 * The showall functionality is for the moment added to the config array
205 * to avoid storage of the showall link in the mailbox pref. We could change
206 * this behaviour later and add it to $aMailboxPref instead
207 */
208 if (isset($showall)) {
209 $aConfig['showall'] = $showall; // show all messages in a mailbox (paginator is disabled)
210 } else {
211 $showall = false;
212 }
213
214
215 /**
216 * Retrieve the mailbox cache from the session.
217 */
218 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION);
219
220 /**
221 * Select the mailbox and retrieve the cached info.
222 */
223 $aMailbox = sqm_api_mailbox_select($imapConnection,$account, $mailbox,$aConfig,$aMailboxPref);
224
225 /**
226 * MOVE THIS to a central init section !!!!
227 */
228 if (!sqgetGlobalVar('align',$align,SQ_SESSION)) {
229 $dir = ( isset( $languages[$squirrelmail_language]['DIR']) ) ? $languages[$squirrelmail_language]['DIR'] : 'ltr';
230 if ( $dir == 'ltr' ) {
231 $align = array('left' => 'left', 'right' => 'right');
232 } else {
233 $align = array('left' => 'right', 'right' => 'left');
234 }
235 sqsession_register($align, 'align');
236 }
237
238 /*
239 * After initialisation of the mailbox array it's time to handle the FORM data
240 */
241 $sError = handleMessageListForm($imapConnection,$aMailbox);
242 if ($sError) {
243 $note = $sError;
244 }
245
246
247
248 /*
249 * If we try to forward messages as attachment we have to open a new window
250 * in case of compose in new window or redirect to compose.php
251 */
252 $onload = '';
253 if (isset($aMailbox['FORWARD_SESSION'])) {
254 if ($compose_new_win) {
255 /* add the mailbox to the cache */
256 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
257 sqsession_register($mailbox_cache,'mailbox_cache');
258 // write the session in order to make sure that the compose window has
259 // access to the composemessages array which is stored in the session
260 session_write_close();
261 // restart the session. Do not use sqsession_is_active because the session_id
262 // isn't empty after a session_write_close
263 sqsession_start();
264 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
265 $compose_width = '640';
266 }
267 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
268 $compose_height = '550';
269 }
270 // do not use &amp;, it will break the query string and $session will not be detected!!!
271 $comp_uri = $base_uri . 'src/compose.php?mailbox='. urlencode($mailbox)
272 . '&session='.urlencode($aMailbox['FORWARD_SESSION']['SESSION_NUMBER'])
273 . '&smaction=forward_as_attachment'
274 . '&fwduid=' . implode('_', $aMailbox['FORWARD_SESSION']['UIDS']);
275 $onload = "comp_in_new('$comp_uri', $compose_width, $compose_height);";
276 } else {
277 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
278 sqsession_register($mailbox_cache,'mailbox_cache');
279
280 // save mailboxstate
281 sqsession_register($aMailbox,'aLastSelectedMailbox');
282 session_write_close();
283 // we have to redirect to the compose page
284 $location = $base_uri . 'src/compose.php?mailbox='. urlencode($mailbox)
285 . '&session='.$aMailbox['FORWARD_SESSION']['SESSION_NUMBER']
286 . '&smaction=forward_as_attachment'
287 . '&fwduid=' . implode('_', $aMailbox['FORWARD_SESSION']['UIDS']);
288 header("Location: $location");
289 exit;
290 }
291 }
292
293 // plugins can operate normally here (don't output anything, of course!),
294 // but can also return TRUE if they want to enable the MOTD display
295 // even when SM's MOTD is empty (there is plugin output that can
296 // be then hooked into in motd.tpl)
297 // NOTE a TRUE return value here will cause the display of the MOTD on
298 // *every* page view; if a plugin wants to support true MOTD (one-time
299 // message display upon login), it should also check the value of
300 // "just_logged_in" in the PHP session before returning TRUE.
301 //
302 $show_motd = boolean_hook_function('right_main_after_header', $null, 1);
303
304
305 // get "just_logged_in" from PHP session, save it in a temp variable
306 // for use below, and reset its value in PHP session
307 //
308 if (!sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION))
309 $just_logged_in = false;
310 $temp_just_logged_in = $just_logged_in;
311 $just_logged_in = false;
312 sqsession_register($just_logged_in, 'just_logged_in');
313
314
315 // now we're done with the PHP session, can send output to browser
316 //
317 displayPageHeader($color, $mailbox, $onload);
318
319
320 /* display a message to the user that their mail has been sent */
321 if (isset($mail_sent) && $mail_sent == 'yes') {
322 $note = _("Your mail has been sent.");
323 }
324 if (isset($note)) {
325 $oTemplate->assign('note', htmlspecialchars($note));
326 $oTemplate->display('note.tpl');
327 }
328
329 if ($temp_just_logged_in || $show_motd) {
330 $motd = trim($motd);
331 if ($show_motd || strlen($motd) > 0) {
332 $oTemplate->assign('motd', $motd);
333 $oTemplate->display('motd.tpl');
334 }
335 }
336
337
338 if ($aMailbox['EXISTS'] > 0) {
339 $aTemplateVars = showMessagesForMailbox($imapConnection,$aMailbox,$aProps,$iError);
340 if ($iError) {
341
342 }
343 foreach ($aTemplateVars as $k => $v) {
344 $oTemplate->assign($k, $v);
345 }
346
347 /*
348 * TODO: To many config related vars. We should move all config related vars to
349 * one single associative array and assign that to the template
350 */
351 $oTemplate->assign('page_selector', $page_selector);
352 $oTemplate->assign('page_selector_max', $page_selector_max);
353 $oTemplate->assign('compact_paginator', $compact_paginator);
354 $oTemplate->assign('javascript_on', checkForJavascript());
355 $oTemplate->assign('base_uri', sqm_baseuri());
356 $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ? $aProps['config']['enablesort'] : false);
357 $oTemplate->assign('icon_theme_path', $icon_theme_path);
358 $oTemplate->assign('aOrder', array_keys($aColumns));
359 $oTemplate->assign('alt_index_colors', isset($alt_index_colors) ? $alt_index_colors: false);
360 $oTemplate->assign('color', $color);
361 $oTemplate->assign('align', $align);
362 $oTemplate->assign('checkall', $checkall);
363 $oTemplate->assign('preselected', $preselected);
364
365 global $show_personal_names;
366 $oTemplate->assign('show_personal_names', $show_personal_names);
367
368 global $accesskey_mailbox_toggle_selected, $accesskey_mailbox_thread;
369 $oTemplate->assign('accesskey_mailbox_toggle_selected', $accesskey_mailbox_toggle_selected);
370 $oTemplate->assign('accesskey_mailbox_thread', $accesskey_mailbox_thread);
371
372 $oTemplate->display('message_list.tpl');
373
374 } else {
375 $oTemplate->display('empty_folder.tpl');
376 }
377
378 do_hook('right_main_bottom', $null);
379 sqimap_logout ($imapConnection);
380 $oTemplate->display('footer.tpl');
381
382
383 /* add the mailbox to the cache */
384 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
385 sqsession_register($mailbox_cache,'mailbox_cache');