Fix for #1093360.
[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 *
47ccfad4 9 * @copyright &copy; 1999-2006 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
30967a1e 15/**
16 * Path for SquirrelMail required files.
17 * @ignore
18 */
86725763 19define('SM_PATH','../');
20
21/* SquirrelMail required files. */
5c4ff7bf 22include_once(SM_PATH . 'include/validate.php');
23//include_once(SM_PATH . 'functions/global.php');
86725763 24require_once(SM_PATH . 'functions/imap.php');
25require_once(SM_PATH . 'functions/date.php');
86725763 26require_once(SM_PATH . 'functions/mime.php');
27require_once(SM_PATH . 'functions/mailbox_display.php');
28require_once(SM_PATH . 'functions/display_messages.php');
29require_once(SM_PATH . 'functions/html.php');
5c4ff7bf 30//require_once(SM_PATH . 'functions/plugin.php');
580e80b8 31
c57b0888 32
580e80b8 33// Trigger Developers to look at CSS ;)
751d5d7a 34// trigger_error("This layout sucks. Adapt squirrelmail.css!!!",E_USER_WARNING);
580e80b8 35//sqm_trigger_imap_error('SQM_IMAP_NO_THREAD',"BLA1",'BAD', 'BLA2', array('test1'=>'test1'));
a32985a5 36
37/* lets get the global vars we may need */
1e12d1ff 38sqgetGlobalVar('key', $key, SQ_COOKIE);
39sqgetGlobalVar('username', $username, SQ_SESSION);
40sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
41sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
42sqgetGlobalVar('base_uri', $base_uri, 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
1e12d1ff 55if ( sqgetGlobalVar('startMessage', $temp) ) {
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
1e12d1ff 69if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) {
70 $checkall = (int) $temp;
a32985a5 71}
91c27aee 72
73/* future work */
74if ( sqgetGlobalVar('account', $account, SQ_GET) ) {
75 $account = (int) $account;
76} else {
77 $account = 0;
78}
79
a32985a5 80/* end of get globals */
81
82
e0e30169 83/* Open an imap connection */
6f223ace 84
c57b0888 85$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
86
e0e30169 87$mailbox = (isset($mailbox) && $mailbox) ? $mailbox : 'INBOX';
324ac3c5 88
e0e30169 89/* compensate for the UW vulnerability. */
90if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
91 substr($mailbox, 0, 1) == '/')) {
92 $mailbox = 'INBOX';
93}
324ac3c5 94/**
95 * Set the global settings for a mailbox and merge them with the usersettings
96 * for the mailbox. In the future we can add more mailbox specific preferences
97 * preferences.
98 */
bdfb67f8 99
91c27aee 100$aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$account.'_'.$mailbox);
324ac3c5 101if ($aMailboxPrefSer) {
102 $aMailboxPref = unserialize($aMailboxPrefSer);
91c27aee 103 $aMailboxPref[MBX_PREF_COLUMNS] = $index_order; // index_order contains the columns to show and the order of the columns
324ac3c5 104} else {
91c27aee 105 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($default_mailbox_pref));
106 $aMailboxPref = $default_mailbox_pref;
324ac3c5 107}
108if (isset($srt)) {
109 $aMailboxPref[MBX_PREF_SORT] = (int) $srt;
110}
111
91c27aee 112$trash_folder = (isset($trash_folder)) ? $trash_folder : false;
113$sent_folder = (isset($sent_folder)) ? $sent_folder : false;
114$draft_folder = (isset($draft_folder)) ? $draft_folder : false;
115
324ac3c5 116
117/**
118 * until there is no per mailbox option screen to set prefs we override
119 * the mailboxprefs by the default ones
120 */
121$aMailboxPref[MBX_PREF_LIMIT] = (int) $show_num;
122$aMailboxPref[MBX_PREF_AUTO_EXPUNGE] = (bool) $auto_expunge;
123$aMailboxPref[MBX_PREF_INTERNALDATE] = (bool) getPref($data_dir, $username, 'internal_date_sort');
91c27aee 124$aMailboxPref[MBX_PREF_COLUMNS] = $index_order;
125
126/**
127 * Replace From => To in case it concerns a draft or sent folder
128 */
129if (($mailbox == $sent_folder || $mailbox == $draft_folder) &&
130 !in_array(SQM_COL_TO,$aMailboxPref[MBX_PREF_COLUMNS])) {
131 $aNewOrder = array(); // nice var name ;)
132 foreach($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
133 if ($iCol == SQM_COL_FROM) {
134 $iCol = SQM_COL_TO;
135 }
136 $aNewOrder[] = $iCol;
137 }
138 $aMailboxPref[MBX_PREF_COLUMNS] = $aNewOrder;
139 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($aMailboxPref));
140}
141
142
143
144/**
145 * Set the config options for the messages list
146 */
147$aColumns = array(); // contains settings per column. Switch to key -> value based array, order is the order of the array keys
148foreach ($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
149 $aColumns[$iCol] = array();
150 switch ($iCol) {
151 case SQM_COL_SUBJ:
152 if ($truncate_subject) {
153 $aColumns[$iCol]['truncate'] = $truncate_subject;
154 }
155 break;
156 case SQM_COL_FROM:
157 case SQM_COL_TO:
158 case SQM_COL_CC:
159 case SQM_COL_BCC:
160 if ($truncate_sender) {
161 $aColumns[$iCol]['truncate'] = $truncate_sender;
162 }
163 break;
164 }
165}
166
167/**
168 * Properties required by showMessagesForMailbox
169 */
170$aProps = array(
171 'columns' => $aColumns, // columns bound settings
172 'config' => array('alt_index_colors' => $alt_index_colors, // alternating row colors (should be a template thing)
173 'highlight_list' => $message_highlight_list, // row highlighting rules
174 'fancy_index_highlite' => $fancy_index_highlite, // highlight rows on hover or on click -> check
175 'show_flag_buttons' => (isset($show_flag_buttons)) ? $show_flag_buttons : true,
176 'lastTargetMailbox' => (isset($lastTargetMailbox)) ? $lastTargetMailbox : '', // last mailbox where messages are moved/copied to
177 'trash_folder' => $trash_folder,
178 'sent_folder' => $sent_folder,
179 'draft_folder' => $draft_folder,
180 'color' => $color,
181 'enablesort' => true // enable sorting on columns
182 ),
183 'mailbox' => $mailbox,
184 'account' => (isset($account)) ? $account : 0, // future usage if we support multiple imap accounts
185 'module' => 'read_body',
186 'email' => false);
fe6efa94 187
fe6efa94 188
324ac3c5 189/**
190 * system wide admin settings and incoming vars.
191 */
192$aConfig = array(
324ac3c5 193 'user' => $username,
194 // incoming vars
91c27aee 195 'offset' => $startMessage // offset in paginator
324ac3c5 196 );
197/**
198 * The showall functionality is for the moment added to the config array
199 * to avoid storage of the showall link in the mailbox pref. We could change
200 * this behaviour later and add it to $aMailboxPref instead
201 */
202if (isset($showall)) {
91c27aee 203 $aConfig['showall'] = $showall; // show all messages in a mailbox (paginator is disabled)
204} else {
205 $showall = false;
26e90c74 206}
207
91c27aee 208
324ac3c5 209/**
210 * Retrieve the mailbox cache from the session.
211 */
212sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION);
213
91c27aee 214/**
215 * Select the mailbox and retrieve the cached info.
216 */
217$aMailbox = sqm_api_mailbox_select($imapConnection,$account, $mailbox,$aConfig,$aMailboxPref);
324ac3c5 218
91c27aee 219/**
220 * MOVE THIS to a central init section !!!!
221 */
222if (!sqgetGlobalVar('align',$align,SQ_SESSION)) {
223 $dir = ( isset( $languages[$squirrelmail_language]['DIR']) ) ? $languages[$squirrelmail_language]['DIR'] : 'ltr';
224 if ( $dir == 'ltr' ) {
225 $align = array('left' => 'left', 'right' => 'right');
226 } else {
227 $align = array('left' => 'right', 'right' => 'left');
228 }
229 sqsession_register($align, 'align');
230}
324ac3c5 231
232/*
233 * After initialisation of the mailbox array it's time to handle the FORM data
234 */
235$sError = handleMessageListForm($imapConnection,$aMailbox);
236if ($sError) {
237 $note = $sError;
fe6efa94 238}
139b3991 239
91c27aee 240
241
324ac3c5 242/*
243 * If we try to forward messages as attachment we have to open a new window
244 * in case of compose in new window or redirect to compose.php
245 */
246if (isset($aMailbox['FORWARD_SESSION'])) {
247 if ($compose_new_win) {
91c27aee 248 /* add the mailbox to the cache */
249 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
250 sqsession_register($mailbox_cache,'mailbox_cache');
324ac3c5 251 // write the session in order to make sure that the compose window has
252 // access to the composemessages array which is stored in the session
253 session_write_close();
8517e764 254 // restart the session. Do not use sqsession_is_active because the session_id
255 // isn't empty after a session_write_close
3a1de9f1 256 sqsession_start();
91c27aee 257 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
258 $compose_width = '640';
259 }
260 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
261 $compose_height = '550';
262 }
263 // do not use &amp;, it will break the query string and $session will not be detected!!!
324ac3c5 264 $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
91c27aee 265 '&session='.$aMailbox['FORWARD_SESSION'];
8517e764 266 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri', $compose_width, $compose_height);", '');
139b3991 267 } else {
91c27aee 268 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
269 sqsession_register($mailbox_cache,'mailbox_cache');
270
324ac3c5 271 // save mailboxstate
272 sqsession_register($aMailbox,'aLastSelectedMailbox');
273 session_write_close();
274 // we have to redirect to the compose page
dc2db59a 275 $location = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
bd466893 276 '&session='.$aMailbox['FORWARD_SESSION'];
324ac3c5 277 header("Location: $location");
278 exit;
139b3991 279 }
280} else {
6f223ace 281 displayPageHeader($color, $mailbox);
282}
324ac3c5 283
c57b0888 284do_hook('right_main_after_header');
2ffeb7c5 285
286/* display a message to the user that their mail has been sent */
287if (isset($mail_sent) && $mail_sent == 'yes') {
288 $note = _("Your Message has been sent.");
289}
c57b0888 290if (isset($note)) {
a6d3eff6 291 echo html_tag( 'div', '<b>' . htmlspecialchars($note) .'</b>', 'center' ) . "<br />\n";
c57b0888 292}
293
f38b7cf0 294if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION) ) {
a32985a5 295 if ($just_logged_in == true) {
296 $just_logged_in = false;
dd2a2e15 297 sqsession_register($just_logged_in, 'just_logged_in');
a32985a5 298
299 if (strlen(trim($motd)) > 0) {
300 echo html_tag( 'table',
301 html_tag( 'tr',
c97f4825 302 html_tag( 'td',
a32985a5 303 html_tag( 'table',
304 html_tag( 'tr',
305 html_tag( 'td', $motd, 'center' )
306 ) ,
307 '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' )
308 )
309 ) ,
310 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' );
311 }
23d6bd09 312 }
c57b0888 313}
91c27aee 314
91c27aee 315
324ac3c5 316if ($aMailbox['EXISTS'] > 0) {
400222be 317 $aTemplateVars = showMessagesForMailbox($imapConnection,$aMailbox,$aProps,$iError);
91c27aee 318 if ($iError) {
319
320 }
321 foreach ($aTemplateVars as $k => $v) {
322 $oTemplate->assign($k, $v);
323 }
324
325 /*
326 * TODO: To many config related vars. We should move all config related vars to
327 * one single associative array and assign that to the template
328 */
329 $oTemplate->assign('page_selector', $page_selector);
330 $oTemplate->assign('page_selector_max', $page_selector_max);
331 $oTemplate->assign('compact_paginator', $compact_paginator);
332 $oTemplate->assign('javascript_on', $javascript_on);
333 $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ? $aProps['config']['enablesort'] : false);
334 // Aaaaaahhhhhhh FIX ME DO NOT USE the string "none" for a var when you mean the boolean false or null
335 $oTemplate->assign('icon_theme', (isset($icon_theme) && $icon_theme !== 'none') ? $icon_theme : false);
336 $oTemplate->assign('use_icons', (isset($use_icons)) ? $use_icons : false);
337 $oTemplate->assign('aOrder', array_keys($aColumns));
338 $oTemplate->assign('alt_index_colors', isset($alt_index_colors) ? $alt_index_colors: false);
339 $oTemplate->assign('color', $color);
340 $oTemplate->assign('align', $align);
91c27aee 341
342 $oTemplate->display('message_list.tpl');
343
324ac3c5 344} else {
345 $string = '<b>' . _("THIS FOLDER IS EMPTY") . '</b>';
3c621ba1 346 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
324ac3c5 347 echo ' <tr><td>';
348 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
349 echo ' <tr><td><br />';
350 echo ' <table cellpadding="1" cellspacing="5" align="center" border="0">';
351 echo ' <tr>' . html_tag( 'td', $string."\n", 'left')
352 . '</tr>';
353 echo ' </table>';
354 echo ' <br /></td></tr>';
355 echo ' </table></td></tr>';
356 echo ' </table>';
357}
7c612fdd 358
c57b0888 359do_hook('right_main_bottom');
360sqimap_logout ($imapConnection);
580e80b8 361$oTemplate->display('footer.tpl');
362
dcc1cc82 363
324ac3c5 364/* add the mailbox to the cache */
91c27aee 365$mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
324ac3c5 366sqsession_register($mailbox_cache,'mailbox_cache');
4b4abf93 367?>