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