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