6 * This is where the mailboxes are listed. This controls most of what
7 * goes on in SquirrelMail.
9 * @copyright © 1999-2007 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @package squirrelmail
15 //xdebug_start_profiling("/var/spool/xdebug/right_main.txt");
19 * Include the SquirrelMail initialization file.
21 include('../include/init.php');
23 /* If email_address not set and admin wants us to ask user for it,
24 * redirect to options page. */
25 if ( $ask_user_info && getPref($data_dir, $username,'email_address') == "" ) {
26 header("Location: " . get_location() . "/options.php?optpage=personal");
30 /* SquirrelMail required files. */
31 require_once(SM_PATH
. 'functions/imap_asearch.php');
32 require_once(SM_PATH
. 'functions/imap_general.php');
33 require_once(SM_PATH
. 'functions/imap_messages.php');
34 require_once(SM_PATH
. 'functions/date.php');
35 require_once(SM_PATH
. 'functions/mime.php');
36 require_once(SM_PATH
. 'functions/mailbox_display.php');
37 require_once(SM_PATH
. 'functions/compose.php');
39 /* lets get the global vars we may need */
40 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
41 sqgetGlobalVar('delayed_errors', $delayed_errors, SQ_SESSION
);
42 if (is_array($delayed_errors)) {
43 $oErrorHandler->AssignDelayedErrors($delayed_errors);
44 sqsession_unregister("delayed_errors");
46 sqgetGlobalVar('mailbox', $mailbox);
47 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION
);
48 sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST
);
49 sqgetGlobalVar('note', $note, SQ_GET
);
50 sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET
);
53 if ( sqGetGlobalVarMultiple('startMessage', $temp, 'paginator_submit') ) {
54 $startMessage = (int) $temp;
58 // sort => srt because of the changed behaviour which can break new behaviour
59 if ( sqgetGlobalVar('srt', $temp, SQ_GET
) ) {
63 if ( sqgetGlobalVar('showall', $temp, SQ_GET
) ) {
64 $showall = (int) $temp;
67 if ( sqgetGlobalVar('checkall', $temp, SQ_GET
) ) {
68 $checkall = (int) $temp;
72 if ( sqgetGlobalVar('account', $account, SQ_GET
) ) {
73 $account = (int) $account;
78 /* end of get globals */
81 /* Open an imap connection */
83 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
85 $mailbox = (isset($mailbox) && $mailbox) ?
$mailbox : 'INBOX';
88 * Set the global settings for a mailbox and merge them with the usersettings
89 * for the mailbox. In the future we can add more mailbox specific preferences
93 $aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$account.'_'.$mailbox);
94 if ($aMailboxPrefSer) {
95 $aMailboxPref = unserialize($aMailboxPrefSer);
96 $aMailboxPref[MBX_PREF_COLUMNS
] = $index_order; // index_order contains the columns to show and the order of the columns
98 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($default_mailbox_pref));
99 $aMailboxPref = $default_mailbox_pref;
102 $aMailboxPref[MBX_PREF_SORT
] = (int) $srt;
105 $trash_folder = (isset($trash_folder)) ?
$trash_folder : false;
106 $sent_folder = (isset($sent_folder)) ?
$sent_folder : false;
107 $draft_folder = (isset($draft_folder)) ?
$draft_folder : false;
111 * until there is no per mailbox option screen to set prefs we override
112 * the mailboxprefs by the default ones
114 $aMailboxPref[MBX_PREF_LIMIT
] = (int) $show_num;
115 $aMailboxPref[MBX_PREF_AUTO_EXPUNGE
] = (bool) $auto_expunge;
116 $aMailboxPref[MBX_PREF_INTERNALDATE
] = (bool) getPref($data_dir, $username, 'internal_date_sort');
117 $aMailboxPref[MBX_PREF_COLUMNS
] = $index_order;
120 * Replace From => To in case it concerns a draft or sent folder
122 if (($mailbox == $sent_folder ||
$mailbox == $draft_folder) &&
123 !in_array(SQM_COL_TO
,$aMailboxPref[MBX_PREF_COLUMNS
])) {
124 $aNewOrder = array(); // nice var name ;)
125 foreach($aMailboxPref[MBX_PREF_COLUMNS
] as $iCol) {
126 if ($iCol == SQM_COL_FROM
) {
129 $aNewOrder[] = $iCol;
131 $aMailboxPref[MBX_PREF_COLUMNS
] = $aNewOrder;
132 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($aMailboxPref));
138 * Set the config options for the messages list
140 $aColumns = array(); // contains settings per column. Switch to key -> value based array, order is the order of the array keys
141 foreach ($aMailboxPref[MBX_PREF_COLUMNS
] as $iCol) {
142 $aColumns[$iCol] = array();
145 if ($truncate_subject) {
146 $aColumns[$iCol]['truncate'] = $truncate_subject;
153 if ($truncate_sender) {
154 $aColumns[$iCol]['truncate'] = $truncate_sender;
161 * Properties required by showMessagesForMailbox
164 'columns' => $aColumns, // columns bound settings
165 'config' => array('alt_index_colors' => $alt_index_colors, // alternating row colors (should be a template thing)
166 'highlight_list' => $message_highlight_list, // row highlighting rules
167 'fancy_index_highlite' => $fancy_index_highlite, // highlight rows on hover or on click -> check
168 'show_flag_buttons' => (isset($show_flag_buttons)) ?
$show_flag_buttons : true,
169 'lastTargetMailbox' => (isset($lastTargetMailbox)) ?
$lastTargetMailbox : '', // last mailbox where messages are moved/copied to
170 'trash_folder' => $trash_folder,
171 'sent_folder' => $sent_folder,
172 'draft_folder' => $draft_folder,
174 'enablesort' => true // enable sorting on columns
176 'mailbox' => $mailbox,
177 'account' => (isset($account)) ?
$account : 0, // future usage if we support multiple imap accounts
178 'module' => 'read_body',
183 * system wide admin settings and incoming vars.
188 'offset' => $startMessage // offset in paginator
191 * The showall functionality is for the moment added to the config array
192 * to avoid storage of the showall link in the mailbox pref. We could change
193 * this behaviour later and add it to $aMailboxPref instead
195 if (isset($showall)) {
196 $aConfig['showall'] = $showall; // show all messages in a mailbox (paginator is disabled)
203 * Retrieve the mailbox cache from the session.
205 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION
);
208 * Select the mailbox and retrieve the cached info.
210 $aMailbox = sqm_api_mailbox_select($imapConnection,$account, $mailbox,$aConfig,$aMailboxPref);
213 * MOVE THIS to a central init section !!!!
215 if (!sqgetGlobalVar('align',$align,SQ_SESSION
)) {
216 $dir = ( isset( $languages[$squirrelmail_language]['DIR']) ) ?
$languages[$squirrelmail_language]['DIR'] : 'ltr';
217 if ( $dir == 'ltr' ) {
218 $align = array('left' => 'left', 'right' => 'right');
220 $align = array('left' => 'right', 'right' => 'left');
222 sqsession_register($align, 'align');
226 * After initialisation of the mailbox array it's time to handle the FORM data
228 $sError = handleMessageListForm($imapConnection,$aMailbox);
236 * If we try to forward messages as attachment we have to open a new window
237 * in case of compose in new window or redirect to compose.php
239 if (isset($aMailbox['FORWARD_SESSION'])) {
240 if ($compose_new_win) {
241 /* add the mailbox to the cache */
242 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
243 sqsession_register($mailbox_cache,'mailbox_cache');
244 // write the session in order to make sure that the compose window has
245 // access to the composemessages array which is stored in the session
246 session_write_close();
247 // restart the session. Do not use sqsession_is_active because the session_id
248 // isn't empty after a session_write_close
250 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
251 $compose_width = '640';
253 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
254 $compose_height = '550';
256 // do not use &, it will break the query string and $session will not be detected!!!
257 $comp_uri = SM_PATH
. 'src/compose.php?mailbox='. urlencode($mailbox).
258 '&session='.urlencode($aMailbox['FORWARD_SESSION']);
259 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri', $compose_width, $compose_height);", '');
261 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
262 sqsession_register($mailbox_cache,'mailbox_cache');
265 sqsession_register($aMailbox,'aLastSelectedMailbox');
266 session_write_close();
267 // we have to redirect to the compose page
268 $location = SM_PATH
. 'src/compose.php?mailbox='. urlencode($mailbox).
269 '&session='.$aMailbox['FORWARD_SESSION'];
270 header("Location: $location");
274 displayPageHeader($color, $mailbox);
277 do_hook('right_main_after_header', $null);
279 /* display a message to the user that their mail has been sent */
280 if (isset($mail_sent) && $mail_sent == 'yes') {
281 $note = _("Your mail has been sent.");
284 $oTemplate->assign('note', htmlspecialchars($note));
285 $oTemplate->display('note.tpl');
288 if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION
) ) {
289 if ($just_logged_in == true) {
290 $just_logged_in = false;
291 sqsession_register($just_logged_in, 'just_logged_in');
294 if (strlen($motd) > 0) {
295 $oTemplate->assign('motd', $motd);
296 $oTemplate->display('motd.tpl');
302 if ($aMailbox['EXISTS'] > 0) {
303 $aTemplateVars = showMessagesForMailbox($imapConnection,$aMailbox,$aProps,$iError);
307 foreach ($aTemplateVars as $k => $v) {
308 $oTemplate->assign($k, $v);
312 * TODO: To many config related vars. We should move all config related vars to
313 * one single associative array and assign that to the template
315 $oTemplate->assign('page_selector', $page_selector);
316 $oTemplate->assign('page_selector_max', $page_selector_max);
317 $oTemplate->assign('compact_paginator', $compact_paginator);
318 $oTemplate->assign('javascript_on', checkForJavascript());
319 $oTemplate->assign('base_uri', sqm_baseuri());
320 $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ?
$aProps['config']['enablesort'] : false);
321 $oTemplate->assign('icon_theme_path', $icon_theme_path);
322 $oTemplate->assign('aOrder', array_keys($aColumns));
323 $oTemplate->assign('alt_index_colors', isset($alt_index_colors) ?
$alt_index_colors: false);
324 $oTemplate->assign('color', $color);
325 $oTemplate->assign('align', $align);
327 $oTemplate->display('message_list.tpl');
330 $oTemplate->display('empty_folder.tpl');
333 do_hook('right_main_bottom', $null);
334 sqimap_logout ($imapConnection);
335 $oTemplate->display('footer.tpl');
338 /* add the mailbox to the cache */
339 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
340 sqsession_register($mailbox_cache,'mailbox_cache');