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 /** This is the right_main page */
16 define('PAGE_NAME', 'right_main');
18 //xdebug_start_profiling("/var/spool/xdebug/right_main.txt");
22 * Include the SquirrelMail initialization file.
24 include('../include/init.php');
26 /* If email_address not set and admin wants us to ask user for it,
27 * redirect to options page. */
28 if ( $ask_user_info && getPref($data_dir, $username,'email_address') == "" ) {
29 header("Location: " . get_location() . "/options.php?optpage=personal");
33 /* SquirrelMail required files. */
34 require_once(SM_PATH
. 'functions/imap_asearch.php');
35 require_once(SM_PATH
. 'functions/imap_general.php');
36 require_once(SM_PATH
. 'functions/imap_messages.php');
37 require_once(SM_PATH
. 'functions/date.php');
38 require_once(SM_PATH
. 'functions/mime.php');
39 require_once(SM_PATH
. 'functions/mailbox_display.php');
40 require_once(SM_PATH
. 'functions/compose.php');
42 /* lets get the global vars we may need */
43 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
44 sqgetGlobalVar('delayed_errors', $delayed_errors, SQ_SESSION
);
45 if (is_array($delayed_errors)) {
46 $oErrorHandler->AssignDelayedErrors($delayed_errors);
47 sqsession_unregister("delayed_errors");
49 sqgetGlobalVar('mailbox', $mailbox);
50 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION
);
51 sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST
);
52 sqgetGlobalVar('note', $note, SQ_GET
);
53 sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET
);
56 if ( sqGetGlobalVarMultiple('startMessage', $temp, 'paginator_submit') ) {
57 $startMessage = (int) $temp;
61 // sort => srt because of the changed behaviour which can break new behaviour
62 if ( sqgetGlobalVar('srt', $temp, SQ_GET
) ) {
66 if ( sqgetGlobalVar('showall', $temp, SQ_GET
) ) {
67 $showall = (int) $temp;
70 if (!sqgetGlobalVar('checkall',$checkall,SQ_GET
)) {
74 if (!sqgetGlobalVar('preselected', $preselected, SQ_GET
) ||
!is_array($preselected)) {
75 $preselected = array();
77 $preselected = array_keys($preselected);
81 if ( sqgetGlobalVar('account', $account, SQ_GET
) ) {
82 $account = (int) $account;
87 /* end of get globals */
90 /* Open an imap connection */
92 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
94 $mailbox = (isset($mailbox) && $mailbox) ?
$mailbox : 'INBOX';
97 * Set the global settings for a mailbox and merge them with the usersettings
98 * for the mailbox. In the future we can add more mailbox specific preferences
102 $aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$account.'_'.$mailbox);
103 if ($aMailboxPrefSer) {
104 $aMailboxPref = unserialize($aMailboxPrefSer);
105 $aMailboxPref[MBX_PREF_COLUMNS
] = $index_order; // index_order contains the columns to show and the order of the columns
107 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($default_mailbox_pref));
108 $aMailboxPref = $default_mailbox_pref;
111 $aMailboxPref[MBX_PREF_SORT
] = (int) $srt;
114 $trash_folder = (isset($trash_folder)) ?
$trash_folder : false;
115 $sent_folder = (isset($sent_folder)) ?
$sent_folder : false;
116 $draft_folder = (isset($draft_folder)) ?
$draft_folder : false;
120 * until there is no per mailbox option screen to set prefs we override
121 * the mailboxprefs by the default ones
123 $aMailboxPref[MBX_PREF_LIMIT
] = (int) $show_num;
124 $aMailboxPref[MBX_PREF_AUTO_EXPUNGE
] = (bool) $auto_expunge;
125 $aMailboxPref[MBX_PREF_INTERNALDATE
] = (bool) getPref($data_dir, $username, 'internal_date_sort');
126 $aMailboxPref[MBX_PREF_COLUMNS
] = $index_order;
129 * Replace From => To in case it concerns a draft or sent folder
131 if (($mailbox == $sent_folder ||
$mailbox == $draft_folder) &&
132 !in_array(SQM_COL_TO
,$aMailboxPref[MBX_PREF_COLUMNS
])) {
133 $aNewOrder = array(); // nice var name ;)
134 foreach($aMailboxPref[MBX_PREF_COLUMNS
] as $iCol) {
135 if ($iCol == SQM_COL_FROM
) {
138 $aNewOrder[] = $iCol;
140 $aMailboxPref[MBX_PREF_COLUMNS
] = $aNewOrder;
141 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($aMailboxPref));
147 * Set the config options for the messages list
149 $aColumns = array(); // contains settings per column. Switch to key -> value based array, order is the order of the array keys
150 foreach ($aMailboxPref[MBX_PREF_COLUMNS
] as $iCol) {
151 $aColumns[$iCol] = array();
154 if ($truncate_subject) {
155 $aColumns[$iCol]['truncate'] = $truncate_subject;
162 if ($truncate_sender) {
163 $aColumns[$iCol]['truncate'] = $truncate_sender;
170 * Properties required by showMessagesForMailbox
173 'columns' => $aColumns, // columns bound settings
174 'config' => array('alt_index_colors' => $alt_index_colors, // alternating row colors (should be a template thing)
175 'highlight_list' => $message_highlight_list, // row highlighting rules
176 'fancy_index_highlite' => $fancy_index_highlite, // highlight rows on hover or on click -> check
177 'show_flag_buttons' => (isset($show_flag_buttons)) ?
$show_flag_buttons : true,
178 'lastTargetMailbox' => (isset($lastTargetMailbox)) ?
$lastTargetMailbox : '', // last mailbox where messages are moved/copied to
179 'trash_folder' => $trash_folder,
180 'sent_folder' => $sent_folder,
181 'draft_folder' => $draft_folder,
183 'enablesort' => true // enable sorting on columns
185 'mailbox' => $mailbox,
186 'account' => (isset($account)) ?
$account : 0, // future usage if we support multiple imap accounts
187 'module' => 'read_body',
192 * system wide admin settings and incoming vars.
197 'offset' => $startMessage // offset in paginator
200 * The showall functionality is for the moment added to the config array
201 * to avoid storage of the showall link in the mailbox pref. We could change
202 * this behaviour later and add it to $aMailboxPref instead
204 if (isset($showall)) {
205 $aConfig['showall'] = $showall; // show all messages in a mailbox (paginator is disabled)
212 * Retrieve the mailbox cache from the session.
214 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION
);
217 * Select the mailbox and retrieve the cached info.
219 $aMailbox = sqm_api_mailbox_select($imapConnection,$account, $mailbox,$aConfig,$aMailboxPref);
222 * MOVE THIS to a central init section !!!!
224 if (!sqgetGlobalVar('align',$align,SQ_SESSION
)) {
225 $dir = ( isset( $languages[$squirrelmail_language]['DIR']) ) ?
$languages[$squirrelmail_language]['DIR'] : 'ltr';
226 if ( $dir == 'ltr' ) {
227 $align = array('left' => 'left', 'right' => 'right');
229 $align = array('left' => 'right', 'right' => 'left');
231 sqsession_register($align, 'align');
235 * After initialisation of the mailbox array it's time to handle the FORM data
237 $sError = handleMessageListForm($imapConnection,$aMailbox);
245 * If we try to forward messages as attachment we have to open a new window
246 * in case of compose in new window or redirect to compose.php
249 if (isset($aMailbox['FORWARD_SESSION'])) {
250 if ($compose_new_win) {
251 /* add the mailbox to the cache */
252 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
253 sqsession_register($mailbox_cache,'mailbox_cache');
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 // restart the session. Do not use sqsession_is_active because the session_id
258 // isn't empty after a session_write_close
260 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
261 $compose_width = '640';
263 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
264 $compose_height = '550';
266 // do not use &, it will break the query string and $session will not be detected!!!
267 $comp_uri = SM_PATH
. 'src/compose.php?mailbox='. urlencode($mailbox).
268 '&session='.urlencode($aMailbox['FORWARD_SESSION']);
269 $onload = "comp_in_new('$comp_uri', $compose_width, $compose_height);";
271 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
272 sqsession_register($mailbox_cache,'mailbox_cache');
275 sqsession_register($aMailbox,'aLastSelectedMailbox');
276 session_write_close();
277 // we have to redirect to the compose page
278 $location = SM_PATH
. 'src/compose.php?mailbox='. urlencode($mailbox).
279 '&session='.$aMailbox['FORWARD_SESSION'];
280 header("Location: $location");
285 // plugins can operate normally here (don't output anything, of course!),
286 // but can also return TRUE if they want to enable the MOTD display
287 // even when SM's MOTD is empty (there is plugin output that can
288 // be then hooked into in motd.tpl)
289 // NOTE a TRUE return value here will cause the display of the MOTD on
290 // *every* page view; if a plugin wants to support true MOTD (one-time
291 // message display upon login), it should also check the value of
292 // "just_logged_in" in the PHP session before returning TRUE.
294 $show_motd = boolean_hook_function('right_main_after_header', $null, 1);
297 // get "just_logged_in" from PHP session, save it in a temp variable
298 // for use below, and reset its value in PHP session
300 if (!sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION
))
301 $just_logged_in = false;
302 $temp_just_logged_in = $just_logged_in;
303 $just_logged_in = false;
304 sqsession_register($just_logged_in, 'just_logged_in');
307 // now we're done with the PHP session, can send output to browser
309 displayPageHeader($color, $mailbox, $onload);
312 /* display a message to the user that their mail has been sent */
313 if (isset($mail_sent) && $mail_sent == 'yes') {
314 $note = _("Your mail has been sent.");
317 $oTemplate->assign('note', htmlspecialchars($note));
318 $oTemplate->display('note.tpl');
321 if ($temp_just_logged_in ||
$show_motd) {
323 if ($show_motd ||
strlen($motd) > 0) {
324 $oTemplate->assign('motd', $motd);
325 $oTemplate->display('motd.tpl');
330 if ($aMailbox['EXISTS'] > 0) {
331 $aTemplateVars = showMessagesForMailbox($imapConnection,$aMailbox,$aProps,$iError);
335 foreach ($aTemplateVars as $k => $v) {
336 $oTemplate->assign($k, $v);
340 * TODO: To many config related vars. We should move all config related vars to
341 * one single associative array and assign that to the template
343 $oTemplate->assign('page_selector', $page_selector);
344 $oTemplate->assign('page_selector_max', $page_selector_max);
345 $oTemplate->assign('compact_paginator', $compact_paginator);
346 $oTemplate->assign('javascript_on', checkForJavascript());
347 $oTemplate->assign('base_uri', sqm_baseuri());
348 $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ?
$aProps['config']['enablesort'] : false);
349 $oTemplate->assign('icon_theme_path', $icon_theme_path);
350 $oTemplate->assign('aOrder', array_keys($aColumns));
351 $oTemplate->assign('alt_index_colors', isset($alt_index_colors) ?
$alt_index_colors: false);
352 $oTemplate->assign('color', $color);
353 $oTemplate->assign('align', $align);
354 $oTemplate->assign('checkall', $checkall);
355 $oTemplate->assign('preselected', $preselected);
357 $oTemplate->display('message_list.tpl');
360 $oTemplate->display('empty_folder.tpl');
363 do_hook('right_main_bottom', $null);
364 sqimap_logout ($imapConnection);
365 $oTemplate->display('footer.tpl');
368 /* add the mailbox to the cache */
369 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
370 sqsession_register($mailbox_cache,'mailbox_cache');