6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This is where the mailboxes are listed. This controls most of what
10 * goes on in SquirrelMail.
13 * @package squirrelmail
17 * Path for SquirrelMail required files.
20 define('SM_PATH','../');
22 /* SquirrelMail required files. */
23 require_once(SM_PATH
. 'include/validate.php');
24 require_once(SM_PATH
. 'functions/global.php');
25 require_once(SM_PATH
. 'functions/imap.php');
26 require_once(SM_PATH
. 'functions/date.php');
27 require_once(SM_PATH
. 'functions/mime.php');
28 require_once(SM_PATH
. 'functions/mailbox_display.php');
29 require_once(SM_PATH
. 'functions/display_messages.php');
30 require_once(SM_PATH
. 'functions/html.php');
31 require_once(SM_PATH
. 'functions/plugin.php');
33 /***********************************************************
34 * incoming variables from URL: *
35 * $sort Direction to sort by date *
36 * values: 0 - descending order *
37 * values: 1 - ascending order *
38 * $startMessage Message to start at *
39 * $mailbox Full Mailbox name *
41 * incoming from cookie: *
43 * incoming from session: *
46 ***********************************************************/
49 /* lets get the global vars we may need */
50 sqgetGlobalVar('key', $key, SQ_COOKIE
);
51 sqgetGlobalVar('username', $username, SQ_SESSION
);
52 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
53 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
54 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
56 sqgetGlobalVar('mailbox', $mailbox);
57 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION
);
58 sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST
);
59 sqgetGlobalVar('note', $note, SQ_GET
);
60 sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET
);
63 if ( sqgetGlobalVar('startMessage', $temp) ) {
64 $startMessage = (int) $temp;
68 // sort => srt because of the changed behaviour which can break new behaviour
69 if ( sqgetGlobalVar('srt', $temp, SQ_GET
) ) {
73 if ( sqgetGlobalVar('showall', $temp, SQ_GET
) ) {
74 $showall = (int) $temp;
77 if ( sqgetGlobalVar('checkall', $temp, SQ_GET
) ) {
78 $checkall = (int) $temp;
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
101 $aMailboxGlobalPref = array(
103 MBX_PREF_LIMIT
=> (int) $show_num,
104 MBX_PREF_AUTO_EXPUNGE
=> (bool) $auto_expunge,
105 MBX_PREF_INTERNALDATE
=> (bool) getPref($data_dir, $username, 'internal_date_sort')
106 // MBX_PREF_FUTURE => (var) $future
109 /* not sure if this hook should be capable to alter the global pref array */
110 do_hook ('generic_header');
112 $aMailboxPrefSer=getPref($data_dir, $username, "pref_$mailbox");
113 if ($aMailboxPrefSer) {
114 $aMailboxPref = unserialize($aMailboxPrefSer);
116 setUserPref($username,"pref_$mailbox",serialize($aMailboxGlobalPref));
117 $aMailboxPref = $aMailboxGlobalPref;
120 $aMailboxPref[MBX_PREF_SORT
] = (int) $srt;
125 * until there is no per mailbox option screen to set prefs we override
126 * the mailboxprefs by the default ones
128 $aMailboxPref[MBX_PREF_LIMIT
] = (int) $show_num;
129 $aMailboxPref[MBX_PREF_AUTO_EXPUNGE
] = (bool) $auto_expunge;
130 $aMailboxPref[MBX_PREF_INTERNALDATE
] = (bool) getPref($data_dir, $username, 'internal_date_sort');
134 * system wide admin settings and incoming vars.
137 'allow_thread_sort' => $allow_thread_sort,
138 'allow_server_sort' => $allow_server_sort,
141 'offset' => $startMessage
144 * The showall functionality is for the moment added to the config array
145 * to avoid storage of the showall link in the mailbox pref. We could change
146 * this behaviour later and add it to $aMailboxPref instead
148 if (isset($showall)) {
149 $aConfig['showall'] = $showall;
153 * Retrieve the mailbox cache from the session.
155 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION
);
158 $aMailbox = sqm_api_mailbox_select($imapConnection,$mailbox,$aConfig,$aMailboxPref);
162 * After initialisation of the mailbox array it's time to handle the FORM data
164 $sError = handleMessageListForm($imapConnection,$aMailbox);
170 * If we try to forward messages as attachment we have to open a new window
171 * in case of compose in new window or redirect to compose.php
173 if (isset($aMailbox['FORWARD_SESSION'])) {
174 if ($compose_new_win) {
175 // write the session in order to make sure that the compose window has
176 // access to the composemessages array which is stored in the session
177 session_write_close();
178 sqsession_is_active();
179 $comp_uri = SM_PATH
. 'src/compose.php?mailbox='. urlencode($mailbox).
180 '&session='.$aMailbox['FORWARD_SESSION'];
181 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false);
184 sqsession_register($aMailbox,'aLastSelectedMailbox');
185 session_write_close();
186 // we have to redirect to the compose page
187 $location = SM_PATH
. 'src/compose.php?mailbox='. urlencode($mailbox).
188 '&session='.$aMailbox['FORWARD_SESSION'];
189 header("Location: $location");
193 displayPageHeader($color, $mailbox);
196 do_hook('right_main_after_header');
198 /* display a message to the user that their mail has been sent */
199 if (isset($mail_sent) && $mail_sent == 'yes') {
200 $note = _("Your Message has been sent.");
203 echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br />\n";
206 if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION
) ) {
207 if ($just_logged_in == true) {
208 $just_logged_in = false;
209 sqsession_register($just_logged_in, 'just_logged_in');
211 if (strlen(trim($motd)) > 0) {
212 echo html_tag( 'table',
217 html_tag( 'td', $motd, 'center' )
219 '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' )
222 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' );
226 if ($aMailbox['EXISTS'] > 0) {
227 showMessagesForMailbox($imapConnection,$aMailbox);
229 $string = '<b>' . _("THIS FOLDER IS EMPTY") . '</b>';
230 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
232 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
233 echo ' <tr><td><br />';
234 echo ' <table cellpadding="1" cellspacing="5" align="center" border="0">';
235 echo ' <tr>' . html_tag( 'td', $string."\n", 'left')
238 echo ' <br /></td></tr>';
239 echo ' </table></td></tr>';
243 do_hook('right_main_bottom');
244 sqimap_logout ($imapConnection);
245 echo '</body></html>';
247 /* add the mailbox to the cache */
248 $mailbox_cache[$aMailbox['NAME']] = $aMailbox;
249 sqsession_register($mailbox_cache,'mailbox_cache');