1ad78c92968bf7ca2326f2582ec65e5463312488
6 * This is where the mailboxes are listed. This controls most of what
7 * goes on in SquirrelMail.
9 * @copyright © 1999-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @package squirrelmail
16 * Path for SquirrelMail required files.
19 define('SM_PATH','../');
21 /* SquirrelMail required files. */
22 include_once(SM_PATH
. 'include/validate.php');
23 //include_once(SM_PATH . 'functions/global.php');
24 require_once(SM_PATH
. 'functions/imap.php');
25 require_once(SM_PATH
. 'functions/date.php');
26 require_once(SM_PATH
. 'functions/mime.php');
27 require_once(SM_PATH
. 'functions/mailbox_display.php');
28 require_once(SM_PATH
. 'functions/display_messages.php');
29 require_once(SM_PATH
. 'functions/html.php');
30 //require_once(SM_PATH . 'functions/plugin.php');
33 // Trigger Developers to look at CSS ;)
34 // trigger_error("This layout sucks. Adapt squirrelmail.css!!!",E_USER_WARNING);
35 //sqm_trigger_imap_error('SQM_IMAP_NO_THREAD',"BLA1",'BAD', 'BLA2', array('test1'=>'test1'));
37 /* lets get the global vars we may need */
38 sqgetGlobalVar('key', $key, SQ_COOKIE
);
39 sqgetGlobalVar('username', $username, SQ_SESSION
);
40 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
41 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
42 sqgetGlobalVar('base_uri', $base_uri, 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 ( sqgetGlobalVar('startMessage', $temp) ) {
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', $temp, SQ_GET
) ) {
70 $checkall = (int) $temp;
74 if ( sqgetGlobalVar('account', $account, SQ_GET
) ) {
75 $account = (int) $account;
80 /* end of get globals */
83 /* Open an imap connection */
85 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
87 $mailbox = (isset($mailbox) && $mailbox) ?
$mailbox : 'INBOX';
89 /* compensate for the UW vulnerability. */
90 if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
91 substr($mailbox, 0, 1) == '/')) {
95 * Set the global settings for a mailbox and merge them with the usersettings
96 * for the mailbox. In the future we can add more mailbox specific preferences
100 $aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$account.'_'.$mailbox);
101 if ($aMailboxPrefSer) {
102 $aMailboxPref = unserialize($aMailboxPrefSer);
103 $aMailboxPref[MBX_PREF_COLUMNS
] = $index_order; // index_order contains the columns to show and the order of the columns
105 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($default_mailbox_pref));
106 $aMailboxPref = $default_mailbox_pref;
109 $aMailboxPref[MBX_PREF_SORT
] = (int) $srt;
112 $trash_folder = (isset($trash_folder)) ?
$trash_folder : false;
113 $sent_folder = (isset($sent_folder)) ?
$sent_folder : false;
114 $draft_folder = (isset($draft_folder)) ?
$draft_folder : false;
118 * until there is no per mailbox option screen to set prefs we override
119 * the mailboxprefs by the default ones
121 $aMailboxPref[MBX_PREF_LIMIT
] = (int) $show_num;
122 $aMailboxPref[MBX_PREF_AUTO_EXPUNGE
] = (bool) $auto_expunge;
123 $aMailboxPref[MBX_PREF_INTERNALDATE
] = (bool) getPref($data_dir, $username, 'internal_date_sort');
124 $aMailboxPref[MBX_PREF_COLUMNS
] = $index_order;
127 * Replace From => To in case it concerns a draft or sent folder
129 if (($mailbox == $sent_folder ||
$mailbox == $draft_folder) &&
130 !in_array(SQM_COL_TO
,$aMailboxPref[MBX_PREF_COLUMNS
])) {
131 $aNewOrder = array(); // nice var name ;)
132 foreach($aMailboxPref[MBX_PREF_COLUMNS
] as $iCol) {
133 if ($iCol == SQM_COL_FROM
) {
136 $aNewOrder[] = $iCol;
138 $aMailboxPref[MBX_PREF_COLUMNS
] = $aNewOrder;
139 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($aMailboxPref));
145 * Set the config options for the messages list
147 $aColumns = array(); // contains settings per column. Switch to key -> value based array, order is the order of the array keys
148 foreach ($aMailboxPref[MBX_PREF_COLUMNS
] as $iCol) {
149 $aColumns[$iCol] = array();
152 if ($truncate_subject) {
153 $aColumns[$iCol]['truncate'] = $truncate_subject;
160 if ($truncate_sender) {
161 $aColumns[$iCol]['truncate'] = $truncate_sender;
168 * Properties required by showMessagesForMailbox
171 'columns' => $aColumns, // columns bound settings
172 'config' => array('alt_index_colors' => $alt_index_colors, // alternating row colors (should be a template thing)
173 'highlight_list' => $message_highlight_list, // row highlighting rules
174 'fancy_index_highlite' => $fancy_index_highlite, // highlight rows on hover or on click -> check
175 'show_flag_buttons' => (isset($show_flag_buttons)) ?
$show_flag_buttons : true,
176 'lastTargetMailbox' => (isset($lastTargetMailbox)) ?
$lastTargetMailbox : '', // last mailbox where messages are moved/copied to
177 'trash_folder' => $trash_folder,
178 'sent_folder' => $sent_folder,
179 'draft_folder' => $draft_folder,
181 'enablesort' => true // enable sorting on columns
183 'mailbox' => $mailbox,
184 'account' => (isset($account)) ?
$account : 0, // future usage if we support multiple imap accounts
185 'module' => 'read_body',
190 * system wide admin settings and incoming vars.
195 'offset' => $startMessage // offset in paginator
198 * The showall functionality is for the moment added to the config array
199 * to avoid storage of the showall link in the mailbox pref. We could change
200 * this behaviour later and add it to $aMailboxPref instead
202 if (isset($showall)) {
203 $aConfig['showall'] = $showall; // show all messages in a mailbox (paginator is disabled)
210 * Retrieve the mailbox cache from the session.
212 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION
);
215 * Select the mailbox and retrieve the cached info.
217 $aMailbox = sqm_api_mailbox_select($imapConnection,$account, $mailbox,$aConfig,$aMailboxPref);
220 * MOVE THIS to a central init section !!!!
222 if (!sqgetGlobalVar('align',$align,SQ_SESSION
)) {
223 $dir = ( isset( $languages[$squirrelmail_language]['DIR']) ) ?
$languages[$squirrelmail_language]['DIR'] : 'ltr';
224 if ( $dir == 'ltr' ) {
225 $align = array('left' => 'left', 'right' => 'right');
227 $align = array('left' => 'right', 'right' => 'left');
229 sqsession_register($align, 'align');
233 * After initialisation of the mailbox array it's time to handle the FORM data
235 $sError = handleMessageListForm($imapConnection,$aMailbox);
243 * If we try to forward messages as attachment we have to open a new window
244 * in case of compose in new window or redirect to compose.php
246 if (isset($aMailbox['FORWARD_SESSION'])) {
247 if ($compose_new_win) {
248 /* add the mailbox to the cache */
249 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
250 sqsession_register($mailbox_cache,'mailbox_cache');
251 // write the session in order to make sure that the compose window has
252 // access to the composemessages array which is stored in the session
253 session_write_close();
254 // restart the session. Do not use sqsession_is_active because the session_id
255 // isn't empty after a session_write_close
257 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
258 $compose_width = '640';
260 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
261 $compose_height = '550';
263 // do not use &, it will break the query string and $session will not be detected!!!
264 $comp_uri = SM_PATH
. 'src/compose.php?mailbox='. urlencode($mailbox).
265 '&session='.$aMailbox['FORWARD_SESSION'];
266 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri', $compose_width, $compose_height);", '');
268 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
269 sqsession_register($mailbox_cache,'mailbox_cache');
272 sqsession_register($aMailbox,'aLastSelectedMailbox');
273 session_write_close();
274 // we have to redirect to the compose page
275 $location = SM_PATH
. 'src/compose.php?mailbox='. urlencode($mailbox).
276 '&session='.$aMailbox['FORWARD_SESSION'];
277 header("Location: $location");
281 displayPageHeader($color, $mailbox);
284 do_hook('right_main_after_header');
286 /* display a message to the user that their mail has been sent */
287 if (isset($mail_sent) && $mail_sent == 'yes') {
288 $note = _("Your Message has been sent.");
291 echo html_tag( 'div', '<b>' . htmlspecialchars($note) .'</b>', 'center' ) . "<br />\n";
294 if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION
) ) {
295 if ($just_logged_in == true) {
296 $just_logged_in = false;
297 sqsession_register($just_logged_in, 'just_logged_in');
299 if (strlen(trim($motd)) > 0) {
300 echo html_tag( 'table',
305 html_tag( 'td', $motd, 'center' )
307 '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' )
310 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' );
316 if ($aMailbox['EXISTS'] > 0) {
317 $aTemplateVars = showMessagesForMailbox($imapConnection,$aMailbox,$aProps,$iError);
321 foreach ($aTemplateVars as $k => $v) {
322 $oTemplate->assign($k, $v);
326 * TODO: To many config related vars. We should move all config related vars to
327 * one single associative array and assign that to the template
329 $oTemplate->assign('page_selector', $page_selector);
330 $oTemplate->assign('page_selector_max', $page_selector_max);
331 $oTemplate->assign('compact_paginator', $compact_paginator);
332 $oTemplate->assign('javascript_on', $javascript_on);
333 $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ?
$aProps['config']['enablesort'] : false);
334 $oTemplate->assign('icon_theme_path', $icon_theme_path);
335 $oTemplate->assign('aOrder', array_keys($aColumns));
336 $oTemplate->assign('alt_index_colors', isset($alt_index_colors) ?
$alt_index_colors: false);
337 $oTemplate->assign('color', $color);
338 $oTemplate->assign('align', $align);
340 $oTemplate->display('message_list.tpl');
343 $string = '<b>' . _("THIS FOLDER IS EMPTY") . '</b>';
344 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
346 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
347 echo ' <tr><td><br />';
348 echo ' <table cellpadding="1" cellspacing="5" align="center" border="0">';
349 echo ' <tr>' . html_tag( 'td', $string."\n", 'left')
352 echo ' <br /></td></tr>';
353 echo ' </table></td></tr>';
357 do_hook('right_main_bottom');
358 sqimap_logout ($imapConnection);
359 $oTemplate->display('footer.tpl');
362 /* add the mailbox to the cache */
363 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
364 sqsession_register($mailbox_cache,'mailbox_cache');