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', $temp, SQ_GET
) ) {
71 $checkall = (int) $temp;
75 if ( sqgetGlobalVar('account', $account, SQ_GET
) ) {
76 $account = (int) $account;
81 /* end of get globals */
84 /* Open an imap connection */
86 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
88 $mailbox = (isset($mailbox) && $mailbox) ?
$mailbox : 'INBOX';
91 * Set the global settings for a mailbox and merge them with the usersettings
92 * for the mailbox. In the future we can add more mailbox specific preferences
96 $aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$account.'_'.$mailbox);
97 if ($aMailboxPrefSer) {
98 $aMailboxPref = unserialize($aMailboxPrefSer);
99 $aMailboxPref[MBX_PREF_COLUMNS
] = $index_order; // index_order contains the columns to show and the order of the columns
101 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($default_mailbox_pref));
102 $aMailboxPref = $default_mailbox_pref;
105 $aMailboxPref[MBX_PREF_SORT
] = (int) $srt;
108 $trash_folder = (isset($trash_folder)) ?
$trash_folder : false;
109 $sent_folder = (isset($sent_folder)) ?
$sent_folder : false;
110 $draft_folder = (isset($draft_folder)) ?
$draft_folder : false;
114 * until there is no per mailbox option screen to set prefs we override
115 * the mailboxprefs by the default ones
117 $aMailboxPref[MBX_PREF_LIMIT
] = (int) $show_num;
118 $aMailboxPref[MBX_PREF_AUTO_EXPUNGE
] = (bool) $auto_expunge;
119 $aMailboxPref[MBX_PREF_INTERNALDATE
] = (bool) getPref($data_dir, $username, 'internal_date_sort');
120 $aMailboxPref[MBX_PREF_COLUMNS
] = $index_order;
123 * Replace From => To in case it concerns a draft or sent folder
125 if (($mailbox == $sent_folder ||
$mailbox == $draft_folder) &&
126 !in_array(SQM_COL_TO
,$aMailboxPref[MBX_PREF_COLUMNS
])) {
127 $aNewOrder = array(); // nice var name ;)
128 foreach($aMailboxPref[MBX_PREF_COLUMNS
] as $iCol) {
129 if ($iCol == SQM_COL_FROM
) {
132 $aNewOrder[] = $iCol;
134 $aMailboxPref[MBX_PREF_COLUMNS
] = $aNewOrder;
135 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($aMailboxPref));
141 * Set the config options for the messages list
143 $aColumns = array(); // contains settings per column. Switch to key -> value based array, order is the order of the array keys
144 foreach ($aMailboxPref[MBX_PREF_COLUMNS
] as $iCol) {
145 $aColumns[$iCol] = array();
148 if ($truncate_subject) {
149 $aColumns[$iCol]['truncate'] = $truncate_subject;
156 if ($truncate_sender) {
157 $aColumns[$iCol]['truncate'] = $truncate_sender;
164 * Properties required by showMessagesForMailbox
167 'columns' => $aColumns, // columns bound settings
168 'config' => array('alt_index_colors' => $alt_index_colors, // alternating row colors (should be a template thing)
169 'highlight_list' => $message_highlight_list, // row highlighting rules
170 'fancy_index_highlite' => $fancy_index_highlite, // highlight rows on hover or on click -> check
171 'show_flag_buttons' => (isset($show_flag_buttons)) ?
$show_flag_buttons : true,
172 'lastTargetMailbox' => (isset($lastTargetMailbox)) ?
$lastTargetMailbox : '', // last mailbox where messages are moved/copied to
173 'trash_folder' => $trash_folder,
174 'sent_folder' => $sent_folder,
175 'draft_folder' => $draft_folder,
177 'enablesort' => true // enable sorting on columns
179 'mailbox' => $mailbox,
180 'account' => (isset($account)) ?
$account : 0, // future usage if we support multiple imap accounts
181 'module' => 'read_body',
186 * system wide admin settings and incoming vars.
191 'offset' => $startMessage // offset in paginator
194 * The showall functionality is for the moment added to the config array
195 * to avoid storage of the showall link in the mailbox pref. We could change
196 * this behaviour later and add it to $aMailboxPref instead
198 if (isset($showall)) {
199 $aConfig['showall'] = $showall; // show all messages in a mailbox (paginator is disabled)
206 * Retrieve the mailbox cache from the session.
208 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION
);
211 * Select the mailbox and retrieve the cached info.
213 $aMailbox = sqm_api_mailbox_select($imapConnection,$account, $mailbox,$aConfig,$aMailboxPref);
216 * MOVE THIS to a central init section !!!!
218 if (!sqgetGlobalVar('align',$align,SQ_SESSION
)) {
219 $dir = ( isset( $languages[$squirrelmail_language]['DIR']) ) ?
$languages[$squirrelmail_language]['DIR'] : 'ltr';
220 if ( $dir == 'ltr' ) {
221 $align = array('left' => 'left', 'right' => 'right');
223 $align = array('left' => 'right', 'right' => 'left');
225 sqsession_register($align, 'align');
229 * After initialisation of the mailbox array it's time to handle the FORM data
231 $sError = handleMessageListForm($imapConnection,$aMailbox);
239 * If we try to forward messages as attachment we have to open a new window
240 * in case of compose in new window or redirect to compose.php
242 if (isset($aMailbox['FORWARD_SESSION'])) {
243 if ($compose_new_win) {
244 /* add the mailbox to the cache */
245 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
246 sqsession_register($mailbox_cache,'mailbox_cache');
247 // write the session in order to make sure that the compose window has
248 // access to the composemessages array which is stored in the session
249 session_write_close();
250 // restart the session. Do not use sqsession_is_active because the session_id
251 // isn't empty after a session_write_close
253 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
254 $compose_width = '640';
256 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
257 $compose_height = '550';
259 // do not use &, it will break the query string and $session will not be detected!!!
260 $comp_uri = SM_PATH
. 'src/compose.php?mailbox='. urlencode($mailbox).
261 '&session='.urlencode($aMailbox['FORWARD_SESSION']);
262 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri', $compose_width, $compose_height);", '');
264 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
265 sqsession_register($mailbox_cache,'mailbox_cache');
268 sqsession_register($aMailbox,'aLastSelectedMailbox');
269 session_write_close();
270 // we have to redirect to the compose page
271 $location = SM_PATH
. 'src/compose.php?mailbox='. urlencode($mailbox).
272 '&session='.$aMailbox['FORWARD_SESSION'];
273 header("Location: $location");
277 displayPageHeader($color, $mailbox);
280 do_hook('right_main_after_header', $null);
282 /* display a message to the user that their mail has been sent */
283 if (isset($mail_sent) && $mail_sent == 'yes') {
284 $note = _("Your mail has been sent.");
287 $oTemplate->assign('note', htmlspecialchars($note));
288 $oTemplate->display('note.tpl');
291 if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION
) ) {
292 if ($just_logged_in == true) {
293 $just_logged_in = false;
294 sqsession_register($just_logged_in, 'just_logged_in');
297 if (strlen($motd) > 0) {
298 $oTemplate->assign('motd', $motd);
299 $oTemplate->display('motd.tpl');
305 if ($aMailbox['EXISTS'] > 0) {
306 $aTemplateVars = showMessagesForMailbox($imapConnection,$aMailbox,$aProps,$iError);
310 foreach ($aTemplateVars as $k => $v) {
311 $oTemplate->assign($k, $v);
315 * TODO: To many config related vars. We should move all config related vars to
316 * one single associative array and assign that to the template
318 $oTemplate->assign('page_selector', $page_selector);
319 $oTemplate->assign('page_selector_max', $page_selector_max);
320 $oTemplate->assign('compact_paginator', $compact_paginator);
321 $oTemplate->assign('javascript_on', checkForJavascript());
322 $oTemplate->assign('base_uri', sqm_baseuri());
323 $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ?
$aProps['config']['enablesort'] : false);
324 $oTemplate->assign('icon_theme_path', $icon_theme_path);
325 $oTemplate->assign('aOrder', array_keys($aColumns));
326 $oTemplate->assign('alt_index_colors', isset($alt_index_colors) ?
$alt_index_colors: false);
327 $oTemplate->assign('color', $color);
328 $oTemplate->assign('align', $align);
330 $oTemplate->display('message_list.tpl');
333 $oTemplate->display('empty_folder.tpl');
336 do_hook('right_main_bottom', $null);
337 sqimap_logout ($imapConnection);
338 $oTemplate->display('footer.tpl');
341 /* add the mailbox to the cache */
342 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
343 sqsession_register($mailbox_cache,'mailbox_cache');