6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This is where the mailboxes are listed. This controls most of what
10 * goes on in SquirrelMail.
13 * @package squirrelmail
17 * Path for SquirrelMail required files.
20 define('SM_PATH','../');
22 /* SquirrelMail required files. */
23 require_once(SM_PATH
. 'include/validate.php');
24 require_once(SM_PATH
. 'functions/global.php');
25 require_once(SM_PATH
. 'functions/imap.php');
26 require_once(SM_PATH
. 'functions/date.php');
27 require_once(SM_PATH
. 'functions/mime.php');
28 require_once(SM_PATH
. 'functions/mailbox_display.php');
29 require_once(SM_PATH
. 'functions/display_messages.php');
30 require_once(SM_PATH
. 'functions/html.php');
31 require_once(SM_PATH
. 'functions/plugin.php');
32 include_once(SM_PATH
. 'class/error.class.php');
35 //include_once(SM_PATH . 'templates/default/message_list.tpl');
36 include_once(SM_PATH
. 'class/template/template.class.php');
39 * Which templatedir are we using. TODO, add make a config var of this and make it possible to switch templates
41 $sTplDir = SM_PATH
. 'templates/default/';
44 * Initialize the template object
46 $oTemplate = new Template($sTplDir);
49 * Initialize our custom error handler object
51 $oErrorHandler = new ErrorHandler($oTemplate,'error_message.tpl');
54 * Activate custom error handling
56 if (version_compare(PHP_VERSION
, "4.3.0", ">=")) {
57 $oldErrorHandler = set_error_handler(array($oErrorHandler, 'SquirrelMailErrorhandler'));
59 $oldErrorHandler = set_error_handler('SquirrelMailErrorhandler');
62 // Trigger Developers to look at CSS ;)
63 trigger_error("This layout sucks. Adapt squirrelmail.css!!!",E_USER_WARNING
);
64 //sqm_trigger_imap_error('SQM_IMAP_NO_THREAD',"BLA1",'BAD', 'BLA2', array('test1'=>'test1'));
66 /* lets get the global vars we may need */
67 sqgetGlobalVar('key', $key, SQ_COOKIE
);
68 sqgetGlobalVar('username', $username, SQ_SESSION
);
69 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
70 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
71 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
73 sqgetGlobalVar('mailbox', $mailbox);
74 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION
);
75 sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST
);
76 sqgetGlobalVar('note', $note, SQ_GET
);
77 sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET
);
80 if ( sqgetGlobalVar('startMessage', $temp) ) {
81 $startMessage = (int) $temp;
85 // sort => srt because of the changed behaviour which can break new behaviour
86 if ( sqgetGlobalVar('srt', $temp, SQ_GET
) ) {
90 if ( sqgetGlobalVar('showall', $temp, SQ_GET
) ) {
91 $showall = (int) $temp;
94 if ( sqgetGlobalVar('checkall', $temp, SQ_GET
) ) {
95 $checkall = (int) $temp;
99 if ( sqgetGlobalVar('account', $account, SQ_GET
) ) {
100 $account = (int) $account;
105 /* end of get globals */
108 /* Open an imap connection */
110 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
112 $mailbox = (isset($mailbox) && $mailbox) ?
$mailbox : 'INBOX';
114 /* compensate for the UW vulnerability. */
115 if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
116 substr($mailbox, 0, 1) == '/')) {
120 * Set the global settings for a mailbox and merge them with the usersettings
121 * for the mailbox. In the future we can add more mailbox specific preferences
126 /* not sure if this hook should be capable to alter the global pref array */
127 do_hook ('generic_header');
129 $aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$account.'_'.$mailbox);
130 if ($aMailboxPrefSer) {
131 $aMailboxPref = unserialize($aMailboxPrefSer);
132 $aMailboxPref[MBX_PREF_COLUMNS
] = $index_order; // index_order contains the columns to show and the order of the columns
134 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($default_mailbox_pref));
135 $aMailboxPref = $default_mailbox_pref;
138 $aMailboxPref[MBX_PREF_SORT
] = (int) $srt;
141 $trash_folder = (isset($trash_folder)) ?
$trash_folder : false;
142 $sent_folder = (isset($sent_folder)) ?
$sent_folder : false;
143 $draft_folder = (isset($draft_folder)) ?
$draft_folder : false;
147 * until there is no per mailbox option screen to set prefs we override
148 * the mailboxprefs by the default ones
150 $aMailboxPref[MBX_PREF_LIMIT
] = (int) $show_num;
151 $aMailboxPref[MBX_PREF_AUTO_EXPUNGE
] = (bool) $auto_expunge;
152 $aMailboxPref[MBX_PREF_INTERNALDATE
] = (bool) getPref($data_dir, $username, 'internal_date_sort');
153 $aMailboxPref[MBX_PREF_COLUMNS
] = $index_order;
156 * Replace From => To in case it concerns a draft or sent folder
158 if (($mailbox == $sent_folder ||
$mailbox == $draft_folder) &&
159 !in_array(SQM_COL_TO
,$aMailboxPref[MBX_PREF_COLUMNS
])) {
160 $aNewOrder = array(); // nice var name ;)
161 foreach($aMailboxPref[MBX_PREF_COLUMNS
] as $iCol) {
162 if ($iCol == SQM_COL_FROM
) {
165 $aNewOrder[] = $iCol;
167 $aMailboxPref[MBX_PREF_COLUMNS
] = $aNewOrder;
168 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($aMailboxPref));
174 * Set the config options for the messages list
176 $aColumns = array(); // contains settings per column. Switch to key -> value based array, order is the order of the array keys
177 foreach ($aMailboxPref[MBX_PREF_COLUMNS
] as $iCol) {
178 $aColumns[$iCol] = array();
181 if ($truncate_subject) {
182 $aColumns[$iCol]['truncate'] = $truncate_subject;
189 if ($truncate_sender) {
190 $aColumns[$iCol]['truncate'] = $truncate_sender;
197 * Properties required by showMessagesForMailbox
200 'columns' => $aColumns, // columns bound settings
201 'config' => array('alt_index_colors' => $alt_index_colors, // alternating row colors (should be a template thing)
202 'highlight_list' => $message_highlight_list, // row highlighting rules
203 'fancy_index_highlite' => $fancy_index_highlite, // highlight rows on hover or on click -> check
204 'show_flag_buttons' => (isset($show_flag_buttons)) ?
$show_flag_buttons : true,
205 'lastTargetMailbox' => (isset($lastTargetMailbox)) ?
$lastTargetMailbox : '', // last mailbox where messages are moved/copied to
206 'trash_folder' => $trash_folder,
207 'sent_folder' => $sent_folder,
208 'draft_folder' => $draft_folder,
210 'enablesort' => true // enable sorting on columns
212 'mailbox' => $mailbox,
213 'account' => (isset($account)) ?
$account : 0, // future usage if we support multiple imap accounts
214 'module' => 'read_body',
219 * system wide admin settings and incoming vars.
224 'offset' => $startMessage // offset in paginator
227 * The showall functionality is for the moment added to the config array
228 * to avoid storage of the showall link in the mailbox pref. We could change
229 * this behaviour later and add it to $aMailboxPref instead
231 if (isset($showall)) {
232 $aConfig['showall'] = $showall; // show all messages in a mailbox (paginator is disabled)
239 * Retrieve the mailbox cache from the session.
241 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION
);
244 * Select the mailbox and retrieve the cached info.
246 $aMailbox = sqm_api_mailbox_select($imapConnection,$account, $mailbox,$aConfig,$aMailboxPref);
249 * MOVE THIS to a central init section !!!!
251 if (!sqgetGlobalVar('align',$align,SQ_SESSION
)) {
252 $dir = ( isset( $languages[$squirrelmail_language]['DIR']) ) ?
$languages[$squirrelmail_language]['DIR'] : 'ltr';
253 if ( $dir == 'ltr' ) {
254 $align = array('left' => 'left', 'right' => 'right');
256 $align = array('left' => 'right', 'right' => 'left');
258 sqsession_register($align, 'align');
262 * After initialisation of the mailbox array it's time to handle the FORM data
264 $sError = handleMessageListForm($imapConnection,$aMailbox);
272 * If we try to forward messages as attachment we have to open a new window
273 * in case of compose in new window or redirect to compose.php
275 if (isset($aMailbox['FORWARD_SESSION'])) {
276 if ($compose_new_win) {
277 /* add the mailbox to the cache */
278 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
279 sqsession_register($mailbox_cache,'mailbox_cache');
280 // write the session in order to make sure that the compose window has
281 // access to the composemessages array which is stored in the session
282 session_write_close();
283 // restart the session. Do not use sqsession_is_active because the session_id
284 // isn't empty after a session_write_close
286 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
287 $compose_width = '640';
289 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
290 $compose_height = '550';
292 // do not use &, it will break the query string and $session will not be detected!!!
293 $comp_uri = SM_PATH
. 'src/compose.php?mailbox='. urlencode($mailbox).
294 '&session='.$aMailbox['FORWARD_SESSION'];
295 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri', $compose_width, $compose_height);", '');
297 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
298 sqsession_register($mailbox_cache,'mailbox_cache');
301 sqsession_register($aMailbox,'aLastSelectedMailbox');
302 session_write_close();
303 // we have to redirect to the compose page
304 $location = SM_PATH
. 'src/compose.php?mailbox='. urlencode($mailbox).
305 '&session='.$aMailbox['FORWARD_SESSION'];
306 header("Location: $location");
310 displayPageHeader($color, $mailbox);
313 do_hook('right_main_after_header');
315 /* display a message to the user that their mail has been sent */
316 if (isset($mail_sent) && $mail_sent == 'yes') {
317 $note = _("Your Message has been sent.");
320 echo html_tag( 'div', '<b>' . htmlspecialchars($note) .'</b>', 'center' ) . "<br />\n";
323 if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION
) ) {
324 if ($just_logged_in == true) {
325 $just_logged_in = false;
326 sqsession_register($just_logged_in, 'just_logged_in');
328 if (strlen(trim($motd)) > 0) {
329 echo html_tag( 'table',
334 html_tag( 'td', $motd, 'center' )
336 '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' )
339 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' );
345 if ($aMailbox['EXISTS'] > 0) {
346 $aTemplateVars = showMessagesForMailbox($imapConnection,$aMailbox,$aProps,$iError);
350 foreach ($aTemplateVars as $k => $v) {
351 $oTemplate->assign($k, $v);
355 * TODO: To many config related vars. We should move all config related vars to
356 * one single associative array and assign that to the template
358 $oTemplate->assign('page_selector', $page_selector);
359 $oTemplate->assign('page_selector_max', $page_selector_max);
360 $oTemplate->assign('compact_paginator', $compact_paginator);
361 $oTemplate->assign('javascript_on', $javascript_on);
362 $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ?
$aProps['config']['enablesort'] : false);
363 // Aaaaaahhhhhhh FIX ME DO NOT USE the string "none" for a var when you mean the boolean false or null
364 $oTemplate->assign('icon_theme', (isset($icon_theme) && $icon_theme !== 'none') ?
$icon_theme : false);
365 $oTemplate->assign('use_icons', (isset($use_icons)) ?
$use_icons : false);
366 $oTemplate->assign('aOrder', array_keys($aColumns));
367 $oTemplate->assign('alt_index_colors', isset($alt_index_colors) ?
$alt_index_colors: false);
368 $oTemplate->assign('color', $color);
369 $oTemplate->assign('align', $align);
371 $oTemplate->display('message_list.tpl');
374 $string = '<b>' . _("THIS FOLDER IS EMPTY") . '</b>';
375 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
377 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
378 echo ' <tr><td><br />';
379 echo ' <table cellpadding="1" cellspacing="5" align="center" border="0">';
380 echo ' <tr>' . html_tag( 'td', $string."\n", 'left')
383 echo ' <br /></td></tr>';
384 echo ' </table></td></tr>';
388 do_hook('right_main_bottom');
389 sqimap_logout ($imapConnection);
390 $oTemplate->display('footer.tpl');
393 /* add the mailbox to the cache */
394 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
395 sqsession_register($mailbox_cache,'mailbox_cache');