error out on nonexistant option type.
[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 *
4b5049de 9 * @copyright &copy; 1999-2007 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
202bcbcc 15//xdebug_start_profiling("/var/spool/xdebug/right_main.txt");
16
17
30967a1e 18/**
202bcbcc 19 * Include the SquirrelMail initialization file.
30967a1e 20 */
202bcbcc 21include('../include/init.php');
86725763 22
23/* SquirrelMail required files. */
202bcbcc 24require_once(SM_PATH . 'functions/imap_asearch.php');
25require_once(SM_PATH . 'functions/imap_general.php');
26require_once(SM_PATH . 'functions/imap_messages.php');
86725763 27require_once(SM_PATH . 'functions/date.php');
86725763 28require_once(SM_PATH . 'functions/mime.php');
29require_once(SM_PATH . 'functions/mailbox_display.php');
628bce99 30require_once(SM_PATH . 'functions/compose.php');
c57b0888 31
a32985a5 32
33/* lets get the global vars we may need */
1e12d1ff 34sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
81de00c0 35sqgetGlobalVar('delayed_errors', $delayed_errors, SQ_SESSION);
36if (is_array($delayed_errors)) {
37 $oErrorHandler->AssignDelayedErrors($delayed_errors);
38 sqsession_unregister("delayed_errors");
39}
1e12d1ff 40sqgetGlobalVar('mailbox', $mailbox);
41sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
324ac3c5 42sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST);
1e12d1ff 43sqgetGlobalVar('note', $note, SQ_GET);
2ffeb7c5 44sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET);
1e12d1ff 45
324ac3c5 46
54ce41dd 47if ( sqGetGlobalVarMultiple('startMessage', $temp, 'paginator_submit') ) {
324ac3c5 48 $startMessage = (int) $temp;
49} else {
50 $startMessage = 1;
a32985a5 51}
324ac3c5 52// sort => srt because of the changed behaviour which can break new behaviour
53if ( sqgetGlobalVar('srt', $temp, SQ_GET) ) {
54 $srt = (int) $temp;
a32985a5 55}
324ac3c5 56
57if ( sqgetGlobalVar('showall', $temp, SQ_GET) ) {
58 $showall = (int) $temp;
a32985a5 59}
324ac3c5 60
1e12d1ff 61if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) {
62 $checkall = (int) $temp;
a32985a5 63}
91c27aee 64
65/* future work */
66if ( sqgetGlobalVar('account', $account, SQ_GET) ) {
67 $account = (int) $account;
68} else {
69 $account = 0;
70}
71
a32985a5 72/* end of get globals */
73
74
e0e30169 75/* Open an imap connection */
6f223ace 76
190dc452 77$imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
c57b0888 78
e0e30169 79$mailbox = (isset($mailbox) && $mailbox) ? $mailbox : 'INBOX';
324ac3c5 80
324ac3c5 81/**
82 * Set the global settings for a mailbox and merge them with the usersettings
83 * for the mailbox. In the future we can add more mailbox specific preferences
84 * preferences.
85 */
bdfb67f8 86
91c27aee 87$aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$account.'_'.$mailbox);
324ac3c5 88if ($aMailboxPrefSer) {
89 $aMailboxPref = unserialize($aMailboxPrefSer);
91c27aee 90 $aMailboxPref[MBX_PREF_COLUMNS] = $index_order; // index_order contains the columns to show and the order of the columns
324ac3c5 91} else {
91c27aee 92 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($default_mailbox_pref));
93 $aMailboxPref = $default_mailbox_pref;
324ac3c5 94}
95if (isset($srt)) {
96 $aMailboxPref[MBX_PREF_SORT] = (int) $srt;
97}
98
91c27aee 99$trash_folder = (isset($trash_folder)) ? $trash_folder : false;
100$sent_folder = (isset($sent_folder)) ? $sent_folder : false;
101$draft_folder = (isset($draft_folder)) ? $draft_folder : false;
102
324ac3c5 103
104/**
105 * until there is no per mailbox option screen to set prefs we override
106 * the mailboxprefs by the default ones
107 */
108$aMailboxPref[MBX_PREF_LIMIT] = (int) $show_num;
109$aMailboxPref[MBX_PREF_AUTO_EXPUNGE] = (bool) $auto_expunge;
110$aMailboxPref[MBX_PREF_INTERNALDATE] = (bool) getPref($data_dir, $username, 'internal_date_sort');
91c27aee 111$aMailboxPref[MBX_PREF_COLUMNS] = $index_order;
112
113/**
114 * Replace From => To in case it concerns a draft or sent folder
115 */
116if (($mailbox == $sent_folder || $mailbox == $draft_folder) &&
117 !in_array(SQM_COL_TO,$aMailboxPref[MBX_PREF_COLUMNS])) {
118 $aNewOrder = array(); // nice var name ;)
119 foreach($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
120 if ($iCol == SQM_COL_FROM) {
121 $iCol = SQM_COL_TO;
122 }
123 $aNewOrder[] = $iCol;
124 }
125 $aMailboxPref[MBX_PREF_COLUMNS] = $aNewOrder;
126 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($aMailboxPref));
127}
128
129
130
131/**
132 * Set the config options for the messages list
133 */
134$aColumns = array(); // contains settings per column. Switch to key -> value based array, order is the order of the array keys
135foreach ($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
136 $aColumns[$iCol] = array();
137 switch ($iCol) {
138 case SQM_COL_SUBJ:
139 if ($truncate_subject) {
140 $aColumns[$iCol]['truncate'] = $truncate_subject;
141 }
142 break;
143 case SQM_COL_FROM:
144 case SQM_COL_TO:
145 case SQM_COL_CC:
146 case SQM_COL_BCC:
147 if ($truncate_sender) {
148 $aColumns[$iCol]['truncate'] = $truncate_sender;
149 }
150 break;
151 }
152}
153
154/**
155 * Properties required by showMessagesForMailbox
156 */
157$aProps = array(
158 'columns' => $aColumns, // columns bound settings
159 'config' => array('alt_index_colors' => $alt_index_colors, // alternating row colors (should be a template thing)
160 'highlight_list' => $message_highlight_list, // row highlighting rules
161 'fancy_index_highlite' => $fancy_index_highlite, // highlight rows on hover or on click -> check
162 'show_flag_buttons' => (isset($show_flag_buttons)) ? $show_flag_buttons : true,
163 'lastTargetMailbox' => (isset($lastTargetMailbox)) ? $lastTargetMailbox : '', // last mailbox where messages are moved/copied to
164 'trash_folder' => $trash_folder,
165 'sent_folder' => $sent_folder,
166 'draft_folder' => $draft_folder,
167 'color' => $color,
168 'enablesort' => true // enable sorting on columns
169 ),
170 'mailbox' => $mailbox,
171 'account' => (isset($account)) ? $account : 0, // future usage if we support multiple imap accounts
172 'module' => 'read_body',
173 'email' => false);
fe6efa94 174
fe6efa94 175
324ac3c5 176/**
177 * system wide admin settings and incoming vars.
178 */
179$aConfig = array(
324ac3c5 180 'user' => $username,
181 // incoming vars
91c27aee 182 'offset' => $startMessage // offset in paginator
324ac3c5 183 );
184/**
185 * The showall functionality is for the moment added to the config array
186 * to avoid storage of the showall link in the mailbox pref. We could change
187 * this behaviour later and add it to $aMailboxPref instead
188 */
189if (isset($showall)) {
91c27aee 190 $aConfig['showall'] = $showall; // show all messages in a mailbox (paginator is disabled)
191} else {
192 $showall = false;
26e90c74 193}
194
91c27aee 195
324ac3c5 196/**
197 * Retrieve the mailbox cache from the session.
198 */
199sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION);
200
91c27aee 201/**
202 * Select the mailbox and retrieve the cached info.
203 */
204$aMailbox = sqm_api_mailbox_select($imapConnection,$account, $mailbox,$aConfig,$aMailboxPref);
324ac3c5 205
91c27aee 206/**
207 * MOVE THIS to a central init section !!!!
208 */
209if (!sqgetGlobalVar('align',$align,SQ_SESSION)) {
210 $dir = ( isset( $languages[$squirrelmail_language]['DIR']) ) ? $languages[$squirrelmail_language]['DIR'] : 'ltr';
211 if ( $dir == 'ltr' ) {
212 $align = array('left' => 'left', 'right' => 'right');
213 } else {
214 $align = array('left' => 'right', 'right' => 'left');
215 }
216 sqsession_register($align, 'align');
217}
324ac3c5 218
219/*
220 * After initialisation of the mailbox array it's time to handle the FORM data
221 */
222$sError = handleMessageListForm($imapConnection,$aMailbox);
223if ($sError) {
224 $note = $sError;
fe6efa94 225}
139b3991 226
91c27aee 227
228
324ac3c5 229/*
230 * If we try to forward messages as attachment we have to open a new window
231 * in case of compose in new window or redirect to compose.php
232 */
233if (isset($aMailbox['FORWARD_SESSION'])) {
234 if ($compose_new_win) {
91c27aee 235 /* add the mailbox to the cache */
236 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
237 sqsession_register($mailbox_cache,'mailbox_cache');
324ac3c5 238 // write the session in order to make sure that the compose window has
239 // access to the composemessages array which is stored in the session
240 session_write_close();
8517e764 241 // restart the session. Do not use sqsession_is_active because the session_id
242 // isn't empty after a session_write_close
3a1de9f1 243 sqsession_start();
91c27aee 244 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
245 $compose_width = '640';
246 }
247 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
248 $compose_height = '550';
249 }
250 // do not use &amp;, it will break the query string and $session will not be detected!!!
324ac3c5 251 $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
7e2ff844 252 '&session='.urlencode($aMailbox['FORWARD_SESSION']);
8517e764 253 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri', $compose_width, $compose_height);", '');
139b3991 254 } else {
91c27aee 255 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
256 sqsession_register($mailbox_cache,'mailbox_cache');
257
324ac3c5 258 // save mailboxstate
259 sqsession_register($aMailbox,'aLastSelectedMailbox');
260 session_write_close();
261 // we have to redirect to the compose page
dc2db59a 262 $location = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
bd466893 263 '&session='.$aMailbox['FORWARD_SESSION'];
324ac3c5 264 header("Location: $location");
265 exit;
139b3991 266 }
6f223ace 267} else {
268 displayPageHeader($color, $mailbox);
269}
324ac3c5 270
6e515418 271do_hook('right_main_after_header', $null);
2ffeb7c5 272
273/* display a message to the user that their mail has been sent */
274if (isset($mail_sent) && $mail_sent == 'yes') {
d7270cc4 275 $note = _("Your mail has been sent.");
2ffeb7c5 276}
c57b0888 277if (isset($note)) {
c03e9db0 278 $oTemplate->assign('note', htmlspecialchars($note));
279 $oTemplate->display('note.tpl');
c57b0888 280}
281
f38b7cf0 282if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION) ) {
a32985a5 283 if ($just_logged_in == true) {
284 $just_logged_in = false;
dd2a2e15 285 sqsession_register($just_logged_in, 'just_logged_in');
a32985a5 286
c03e9db0 287 $motd = trim($motd);
288 if (strlen($motd) > 0) {
289 $oTemplate->assign('motd', $motd);
290 $oTemplate->display('motd.tpl');
a32985a5 291 }
23d6bd09 292 }
c57b0888 293}
91c27aee 294
91c27aee 295
324ac3c5 296if ($aMailbox['EXISTS'] > 0) {
400222be 297 $aTemplateVars = showMessagesForMailbox($imapConnection,$aMailbox,$aProps,$iError);
91c27aee 298 if ($iError) {
299
300 }
301 foreach ($aTemplateVars as $k => $v) {
302 $oTemplate->assign($k, $v);
303 }
304
305 /*
306 * TODO: To many config related vars. We should move all config related vars to
307 * one single associative array and assign that to the template
308 */
309 $oTemplate->assign('page_selector', $page_selector);
310 $oTemplate->assign('page_selector_max', $page_selector_max);
311 $oTemplate->assign('compact_paginator', $compact_paginator);
457e8593 312 $oTemplate->assign('javascript_on', checkForJavascript());
fe8103c2 313 $oTemplate->assign('base_uri', sqm_baseuri());
91c27aee 314 $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ? $aProps['config']['enablesort'] : false);
29997535 315 $oTemplate->assign('icon_theme_path', $icon_theme_path);
91c27aee 316 $oTemplate->assign('aOrder', array_keys($aColumns));
317 $oTemplate->assign('alt_index_colors', isset($alt_index_colors) ? $alt_index_colors: false);
318 $oTemplate->assign('color', $color);
319 $oTemplate->assign('align', $align);
91c27aee 320
321 $oTemplate->display('message_list.tpl');
322
324ac3c5 323} else {
c03e9db0 324 $oTemplate->display('empty_folder.tpl');
324ac3c5 325}
7c612fdd 326
6e515418 327do_hook('right_main_bottom', $null);
c57b0888 328sqimap_logout ($imapConnection);
580e80b8 329$oTemplate->display('footer.tpl');
330
dcc1cc82 331
324ac3c5 332/* add the mailbox to the cache */
91c27aee 333$mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
324ac3c5 334sqsession_register($mailbox_cache,'mailbox_cache');