6 * This is where the mailboxes are listed. This controls most of what
7 * goes on in SquirrelMail.
9 * @copyright 1999-2011 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @package squirrelmail
15 /** This is the right_main page */
16 define('PAGE_NAME', 'right_main');
18 //xdebug_start_profiling("/var/spool/xdebug/right_main.txt");
21 * Include the SquirrelMail initialization file.
23 include('../include/init.php');
25 /* If email_address not set and admin wants us to ask user for it,
26 * redirect to options page. */
27 if ( $ask_user_info && getPref($data_dir, $username,'email_address') == "" ) {
28 header("Location: " . get_location() . "/options.php?optpage=personal");
32 /* SquirrelMail required files. */
33 require_once(SM_PATH
. 'functions/imap_asearch.php');
34 require_once(SM_PATH
. 'functions/imap_general.php');
35 require_once(SM_PATH
. 'functions/imap_messages.php');
36 require_once(SM_PATH
. 'functions/date.php');
37 require_once(SM_PATH
. 'functions/mime.php');
38 require_once(SM_PATH
. 'functions/mailbox_display.php');
39 require_once(SM_PATH
. 'functions/compose.php');
41 /* lets get the global vars we may need */
42 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
43 sqgetGlobalVar('delayed_errors', $delayed_errors, SQ_SESSION
);
44 if (is_array($delayed_errors)) {
45 $oErrorHandler->AssignDelayedErrors($delayed_errors);
46 sqsession_unregister("delayed_errors");
48 sqgetGlobalVar('mailbox', $mailbox);
49 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION
);
50 sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST
);
51 sqgetGlobalVar('note', $note, SQ_GET
);
52 sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET
);
55 if ( sqGetGlobalVarMultiple('startMessage', $temp, 'paginator_submit') ) {
56 $startMessage = (int) $temp;
60 // sort => srt because of the changed behaviour which can break new behaviour
61 if ( sqgetGlobalVar('srt', $temp, SQ_GET
) ) {
65 if ( sqgetGlobalVar('showall', $temp, SQ_GET
) ) {
66 $showall = (int) $temp;
69 if (!sqgetGlobalVar('checkall',$checkall,SQ_GET
)) {
73 if (!sqgetGlobalVar('preselected', $preselected, SQ_GET
) ||
!is_array($preselected)) {
74 $preselected = array();
76 $preselected = array_keys($preselected);
80 if ( sqgetGlobalVar('account', $account, SQ_GET
) ) {
81 $account = (int) $account;
86 /* end of get globals */
89 /* Open an imap connection */
91 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
93 $mailbox = (isset($mailbox) && $mailbox) ?
$mailbox : 'INBOX';
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
101 $aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$account.'_'.$mailbox);
102 if ($aMailboxPrefSer) {
103 $aMailboxPref = unserialize($aMailboxPrefSer);
104 $aMailboxPref[MBX_PREF_COLUMNS
] = $index_order; // index_order contains the columns to show and the order of the columns
106 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($default_mailbox_pref));
107 $aMailboxPref = $default_mailbox_pref;
110 $aMailboxPref[MBX_PREF_SORT
] = (int) $srt;
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;
119 * until there is no per mailbox option screen to set prefs we override
120 * the mailboxprefs by the default ones
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');
125 $aMailboxPref[MBX_PREF_COLUMNS
] = $index_order;
128 * Replace From => To in case it concerns a draft or sent folder
130 if (handleAsSent($mailbox)
131 && !in_array(SQM_COL_TO
,$aMailboxPref[MBX_PREF_COLUMNS
])) {
132 $aNewOrder = array(); // nice var name ;)
133 foreach($aMailboxPref[MBX_PREF_COLUMNS
] as $iCol) {
134 if ($iCol == SQM_COL_FROM
) {
137 $aNewOrder[] = $iCol;
139 $aMailboxPref[MBX_PREF_COLUMNS
] = $aNewOrder;
140 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($aMailboxPref));
146 * Set the config options for the messages list
148 $aColumns = array(); // contains settings per column. Switch to key -> value based array, order is the order of the array keys
149 foreach ($aMailboxPref[MBX_PREF_COLUMNS
] as $iCol) {
150 $aColumns[$iCol] = array();
153 if ($truncate_subject) {
154 $aColumns[$iCol]['truncate'] = $truncate_subject;
161 if ($truncate_sender) {
162 $aColumns[$iCol]['truncate'] = $truncate_sender;
169 * Properties required by showMessagesForMailbox
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,
182 'enablesort' => true // enable sorting on columns
184 'mailbox' => $mailbox,
185 'account' => (isset($account)) ?
$account : 0, // future usage if we support multiple imap accounts
186 'module' => 'read_body',
191 * system wide admin settings and incoming vars.
196 'offset' => $startMessage // offset in paginator
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
203 if (isset($showall)) {
204 $aConfig['showall'] = $showall; // show all messages in a mailbox (paginator is disabled)
211 * Retrieve the mailbox cache from the session.
213 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION
);
216 * Select the mailbox and retrieve the cached info.
218 $aMailbox = sqm_api_mailbox_select($imapConnection,$account, $mailbox,$aConfig,$aMailboxPref);
221 * MOVE THIS to a central init section !!!!
223 if (!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');
228 $align = array('left' => 'right', 'right' => 'left');
230 sqsession_register($align, 'align');
234 * After initialisation of the mailbox array it's time to handle the FORM data
236 $sError = handleMessageListForm($imapConnection,$aMailbox);
244 * If we try to forward messages as attachment we have to open a new window
245 * in case of compose in new window or redirect to compose.php
248 if (isset($aMailbox['FORWARD_SESSION'])) {
249 if ($compose_new_win) {
250 /* add the mailbox to the cache */
251 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
252 sqsession_register($mailbox_cache,'mailbox_cache');
253 // write the session in order to make sure that the compose window has
254 // access to the composemessages array which is stored in the session
255 session_write_close();
256 // restart the session. Do not use sqsession_is_active because the session_id
257 // isn't empty after a session_write_close
259 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
260 $compose_width = '640';
262 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
263 $compose_height = '550';
265 // do not use &, it will break the query string and $session will not be detected!!!
266 $comp_uri = $base_uri . 'src/compose.php?mailbox='. urlencode($mailbox)
267 . '&session='.urlencode($aMailbox['FORWARD_SESSION']['SESSION_NUMBER'])
268 . '&smaction=forward_as_attachment'
269 . '&fwduid=' . implode('_', $aMailbox['FORWARD_SESSION']['UIDS']);
270 $onload = "comp_in_new('$comp_uri', $compose_width, $compose_height);";
272 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
273 sqsession_register($mailbox_cache,'mailbox_cache');
276 sqsession_register($aMailbox,'aLastSelectedMailbox');
277 session_write_close();
278 // we have to redirect to the compose page
279 $location = $base_uri . 'src/compose.php?mailbox='. urlencode($mailbox)
280 . '&session='.$aMailbox['FORWARD_SESSION']['SESSION_NUMBER']
281 . '&smaction=forward_as_attachment'
282 . '&fwduid=' . implode('_', $aMailbox['FORWARD_SESSION']['UIDS']);
283 header("Location: $location");
288 // plugins can operate normally here (don't output anything, of course!),
289 // but can also return TRUE if they want to enable the MOTD display
290 // even when SM's MOTD is empty (there is plugin output that can
291 // be then hooked into in motd.tpl)
292 // NOTE a TRUE return value here will cause the display of the MOTD on
293 // *every* page view; if a plugin wants to support true MOTD (one-time
294 // message display upon login), it should also check the value of
295 // "just_logged_in" in the PHP session before returning TRUE.
297 $show_motd = boolean_hook_function('right_main_after_header', $null, 1);
300 // get "just_logged_in" from PHP session, save it in a temp variable
301 // for use below, and reset its value in PHP session
303 if (!sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION
))
304 $just_logged_in = false;
305 $temp_just_logged_in = $just_logged_in;
306 $just_logged_in = false;
307 sqsession_register($just_logged_in, 'just_logged_in');
310 // now we're done with the PHP session, can send output to browser
312 displayPageHeader($color, $mailbox, $onload);
315 /* display a message to the user that their mail has been sent */
316 if (isset($mail_sent) && $mail_sent == 'yes') {
317 $note = _("Your mail has been sent.");
320 $oTemplate->assign('note', htmlspecialchars($note));
321 $oTemplate->display('note.tpl');
324 if ($temp_just_logged_in ||
$show_motd) {
326 if ($show_motd ||
strlen($motd) > 0) {
327 $oTemplate->assign('motd', $motd);
328 $oTemplate->display('motd.tpl');
333 if ($aMailbox['EXISTS'] > 0) {
334 $aTemplateVars = showMessagesForMailbox($imapConnection,$aMailbox,$aProps,$iError);
338 foreach ($aTemplateVars as $k => $v) {
339 $oTemplate->assign($k, $v);
343 * TODO: To many config related vars. We should move all config related vars to
344 * one single associative array and assign that to the template
346 $oTemplate->assign('page_selector', $page_selector);
347 $oTemplate->assign('page_selector_max', $page_selector_max);
348 $oTemplate->assign('compact_paginator', $compact_paginator);
349 $oTemplate->assign('javascript_on', checkForJavascript());
350 $oTemplate->assign('base_uri', sqm_baseuri());
351 $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ?
$aProps['config']['enablesort'] : false);
352 $oTemplate->assign('icon_theme_path', $icon_theme_path);
353 $oTemplate->assign('aOrder', array_keys($aColumns));
354 $oTemplate->assign('alt_index_colors', isset($alt_index_colors) ?
$alt_index_colors: false);
355 $oTemplate->assign('color', $color);
356 $oTemplate->assign('align', $align);
357 $oTemplate->assign('checkall', $checkall);
358 $oTemplate->assign('preselected', $preselected);
360 global $show_personal_names;
361 $oTemplate->assign('show_personal_names', $show_personal_names);
363 global $accesskey_mailbox_toggle_selected, $accesskey_mailbox_thread;
364 $oTemplate->assign('accesskey_mailbox_toggle_selected', $accesskey_mailbox_toggle_selected);
365 $oTemplate->assign('accesskey_mailbox_thread', $accesskey_mailbox_thread);
367 $oTemplate->display('message_list.tpl');
370 $oTemplate->display('empty_folder.tpl');
373 do_hook('right_main_bottom', $null);
374 sqimap_logout ($imapConnection);
375 $oTemplate->display('footer.tpl');
378 /* add the mailbox to the cache */
379 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
380 sqsession_register($mailbox_cache,'mailbox_cache');