5 * Copyright (c) 1999-2004 The SquirrelMail Project Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 * This is where the mailboxes are listed. This controls most of what
9 * goes on in SquirrelMail.
12 * @package squirrelmail
16 * Path for SquirrelMail required files.
19 define('SM_PATH','../');
21 /* SquirrelMail required files. */
22 require_once(SM_PATH
. 'include/validate.php');
23 require_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');
32 /***********************************************************
33 * incoming variables from URL: *
34 * $sort Direction to sort by date *
35 * values: 0 - descending order *
36 * values: 1 - ascending order *
37 * $startMessage Message to start at *
38 * $mailbox Full Mailbox name *
40 * incoming from cookie: *
42 * incoming from session: *
45 ***********************************************************/
48 /* lets get the global vars we may need */
49 sqgetGlobalVar('key', $key, SQ_COOKIE
);
50 sqgetGlobalVar('username', $username, SQ_SESSION
);
51 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
52 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
53 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
55 sqgetGlobalVar('mailbox', $mailbox);
56 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION
);
57 sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST
);
58 sqgetGlobalVar('note', $note, SQ_GET
);
59 sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET
);
62 if ( sqgetGlobalVar('startMessage', $temp) ) {
63 $startMessage = (int) $temp;
67 // sort => srt because of the changed behaviour which can break new behaviour
68 if ( sqgetGlobalVar('srt', $temp, SQ_GET
) ) {
72 if ( sqgetGlobalVar('showall', $temp, SQ_GET
) ) {
73 $showall = (int) $temp;
76 if ( sqgetGlobalVar('checkall', $temp, SQ_GET
) ) {
77 $checkall = (int) $temp;
79 /* end of get globals */
82 /* Open an imap connection */
84 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
86 $mailbox = (isset($mailbox) && $mailbox) ?
$mailbox : 'INBOX';
88 /* compensate for the UW vulnerability. */
89 if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
90 substr($mailbox, 0, 1) == '/')) {
94 * Set the global settings for a mailbox and merge them with the usersettings
95 * for the mailbox. In the future we can add more mailbox specific preferences
100 $aMailboxGlobalPref = array(
102 MBX_PREF_LIMIT
=> (int) $show_num,
103 MBX_PREF_AUTO_EXPUNGE
=> (bool) $auto_expunge,
104 MBX_PREF_INTERNALDATE
=> (bool) getPref($data_dir, $username, 'internal_date_sort')
105 // MBX_PREF_FUTURE => (var) $future
108 /* not sure if this hook should be capable to alter the global pref array */
109 do_hook ('generic_header');
111 $aMailboxPrefSer=getPref($data_dir, $username, "pref_$mailbox");
112 if ($aMailboxPrefSer) {
113 $aMailboxPref = unserialize($aMailboxPrefSer);
115 setUserPref($username,"pref_$mailbox",serialize($aMailboxGlobalPref));
116 $aMailboxPref = $aMailboxGlobalPref;
119 $aMailboxPref[MBX_PREF_SORT
] = (int) $srt;
124 * until there is no per mailbox option screen to set prefs we override
125 * the mailboxprefs by the default ones
127 $aMailboxPref[MBX_PREF_LIMIT
] = (int) $show_num;
128 $aMailboxPref[MBX_PREF_AUTO_EXPUNGE
] = (bool) $auto_expunge;
129 $aMailboxPref[MBX_PREF_INTERNALDATE
] = (bool) getPref($data_dir, $username, 'internal_date_sort');
133 * system wide admin settings and incoming vars.
136 'allow_thread_sort' => $allow_thread_sort,
137 'allow_server_sort' => $allow_server_sort,
140 'offset' => $startMessage
143 * The showall functionality is for the moment added to the config array
144 * to avoid storage of the showall link in the mailbox pref. We could change
145 * this behaviour later and add it to $aMailboxPref instead
147 if (isset($showall)) {
148 $aConfig['showall'] = $showall;
152 * Retrieve the mailbox cache from the session.
154 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION
);
157 $aMailbox = sqm_api_mailbox_select($imapConnection,$mailbox,$aConfig,$aMailboxPref);
161 * After initialisation of the mailbox array it's time to handle the FORM data
163 $sError = handleMessageListForm($imapConnection,$aMailbox);
169 * If we try to forward messages as attachment we have to open a new window
170 * in case of compose in new window or redirect to compose.php
172 if (isset($aMailbox['FORWARD_SESSION'])) {
173 if ($compose_new_win) {
174 // write the session in order to make sure that the compose window has
175 // access to the composemessages array which is stored in the session
176 session_write_close();
177 sqsession_is_active();
178 $comp_uri = SM_PATH
. 'src/compose.php?mailbox='. urlencode($mailbox).
179 '&session='.$aMailbox['FORWARD_SESSION'];
180 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false);
183 sqsession_register($aMailbox,'aLastSelectedMailbox');
184 session_write_close();
185 // we have to redirect to the compose page
187 if (!strpos($PHP_SELF,'?')) {
188 $location = $PHP_SELF.'?mailbox=INBOX&startMessage=1';
190 $location = $PHP_SELF;
192 $location = set_url_var($location, 'session',$aMailbox['FORWARD_SESSION'], false);
193 header("Location: $location");
197 displayPageHeader($color, $mailbox);
200 do_hook('right_main_after_header');
202 /* display a message to the user that their mail has been sent */
203 if (isset($mail_sent) && $mail_sent == 'yes') {
204 $note = _("Your Message has been sent.");
207 echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br>\n";
210 if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION
) ) {
211 if ($just_logged_in == true) {
212 $just_logged_in = false;
213 sqsession_register($just_logged_in, 'just_logged_in');
215 if (strlen(trim($motd)) > 0) {
216 echo html_tag( 'table',
221 html_tag( 'td', $motd, 'center' )
223 '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' )
226 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' );
230 if ($aMailbox['EXISTS'] > 0) {
231 showMessagesForMailbox($imapConnection,$aMailbox);
233 $string = '<b>' . _("THIS FOLDER IS EMPTY") . '</b>';
234 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
236 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
237 echo ' <tr><td><br />';
238 echo ' <table cellpadding="1" cellspacing="5" align="center" border="0">';
239 echo ' <tr>' . html_tag( 'td', $string."\n", 'left')
242 echo ' <br /></td></tr>';
243 echo ' </table></td></tr>';
247 do_hook('right_main_bottom');
248 sqimap_logout ($imapConnection);
249 echo '</body></html>';
251 /* add the mailbox to the cache */
252 $mailbox_cache[$aMailbox['NAME']] = $aMailbox;
253 sqsession_register($mailbox_cache,'mailbox_cache');