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('numMessages' , $numMessages, SQ_SESSION
);
58 sqgetGlobalVar('session', $session, SQ_GET
);
59 sqgetGlobalVar('note', $note, SQ_GET
);
60 sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET
);
61 sqgetGlobalVar('use_mailbox_cache', $use_mailbox_cache, SQ_GET
);
63 if ( sqgetGlobalVar('startMessage', $temp) ) {
64 $startMessage = (int) $temp;
66 if ( sqgetGlobalVar('PG_SHOWNUM', $temp) ) {
67 $PG_SHOWNUM = (int) $temp;
69 if ( sqgetGlobalVar('PG_SHOWALL', $temp, SQ_GET
) ) {
70 $PG_SHOWALL = (int) $temp;
72 if ( sqgetGlobalVar('newsort', $temp, SQ_GET
) ) {
73 $newsort = (int) $temp;
75 if ( sqgetGlobalVar('checkall', $temp, SQ_GET
) ) {
76 $checkall = (int) $temp;
78 if ( sqgetGlobalVar('set_thread', $temp, SQ_GET
) ) {
79 $set_thread = (int) $temp;
81 if ( !sqgetGlobalVar('composenew', $composenew, SQ_GET
) ) {
84 /* end of get globals */
87 /* Open a connection on the imap port (143) */
89 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
91 if (isset($PG_SHOWALL)) {
94 $show_num=$PG_SHOWNUM;
95 sqsession_register($PG_SHOWNUM, 'PG_SHOWNUM');
98 sqsession_unregister('PG_SHOWNUM');
102 else if( isset( $PG_SHOWNUM ) ) {
103 $show_num = $PG_SHOWNUM;
106 if (isset($newsort) ) {
107 if ( $newsort != $sort )
108 setPref($data_dir, $username, 'sort', $newsort);
111 sqsession_register($sort, 'sort');
114 /* If the page has been loaded without a specific mailbox, */
115 /* send them to the inbox */
116 //if (!isset($mailbox)) {
117 // $mailbox = 'INBOX';
118 // $startMessage = 1;
121 //if (!isset($startMessage) || ($startMessage == '')) {
122 // $startMessage = 1;
125 /* compensate for the UW vulnerability. */
126 if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
127 substr($mailbox, 0, 1) == '/')) {
131 do_hook ('generic_header');
133 $aMbxResponse = sqimap_mailbox_select($imapConnection, $mailbox);
134 $aMbxResponse['SORT_ARRAY'] = false;
136 sqgetGlobalVar('aLastSelectedMailbox',$aLastSelectedMailbox,SQ_SESSION
);
138 // deal with imap servers that do not return the required UIDNEXT or
139 // UIDVALIDITY response
140 // from a SELECT call (since rfc 3501 it's required)
141 if (!isset($aMbxResponse['UIDNEXT']) ||
!isset($aMbxResponse['UIDVALIDITY'])) {
142 $aStatus = sqimap_status_messages($imapConnection,$mailbox,
143 array('UIDNEXT','UIDVALIDITY'));
144 $aMbxResponse['UIDNEXT'] = $aStatus['UIDNEXT'];
145 $aMbxResponse['UIDVALIDTY'] = $aStatus['UIDVALIDITY'];
148 if ($aLastSelectedMailbox && !isset($newsort)) {
149 // check if we deal with the same mailbox
150 if ($aLastSelectedMailbox['NAME'] == $mailbox) {
151 if ($aLastSelectedMailbox['EXISTS'] == $aMbxResponse['EXISTS'] &&
152 $aLastSelectedMailbox['UIDVALIDITY'] == $aMbxResponse['UIDVALIDITY'] &&
153 $aLastSelectedMailbox['UIDNEXT'] == $aMbxResponse['UIDNEXT']) {
154 // sort is still valid
155 sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION
);
156 if ($server_sort_array && is_array($server_sort_array)) {
157 $aMbxResponse['SORT_ARRAY'] = $server_sort_array;
163 $aLastSelectedMailbox['NAME'] = $mailbox;
164 $aLastSelectedMailbox['EXISTS'] = $aMbxResponse['EXISTS'];
165 $aLastSelectedMailbox['UIDVALIDITY'] = $aMbxResponse['UIDVALIDITY'];
166 $aLastSelectedMailbox['UIDNEXT'] = $aMbxResponse['UIDNEXT'];
167 $aLastSelectedMailbox['PERMANENTFLAGS'] = $aMbxResponse['PERMANENTFLAGS'];
168 $aLastSelectedMailbox['OFFSET'] = (isset($startMessage) && $startMessage) ?
$startMessage -1 : 0;
169 $aLastSelectedMailbox['PAGEOFFSET'] = (isset($startMessage) && $startMessage) ?
$startMessage : 1;
170 $aLastSelectedMailbox['SORT'] = ($sort !== false) ?
$sort : 0;
171 $aLastSelectedMailbox['LIMIT'] = $show_num;
173 $aLastSelectedMailbox['UIDSET'] = $aMbxResponse['SORT_ARRAY'];
174 $aLastSelectedMailbox['SEEN'] = (isset($aMbxResponse['SEEN'])) ?
$aMbxResponse['SEEN'] : $aMbxResponse['EXISTS'];
175 $aLastSelectedMailbox['RECENT'] = (isset($aMbxResponse['RECENT'])) ?
$aMbxResponse['RECENT'] : 0;
177 $aLastSelectedMailbox['AUTO_EXPUNGE'] = $auto_expunge;
179 /* decide if we are thread sorting or not */
180 $aLastSelectedMailbox['ALLOW_THREAD'] = $allow_thread_sort;
181 if ($allow_thread_sort == TRUE) {
182 if (isset($set_thread)) {
183 $aLastSelectedMailbox['SORT_ARRAY'] = false;
184 if (sqsession_is_registered('indent_array')) {
185 sqsession_unregister('indent_array');
187 if (sqsession_is_registered('server_sort_array')) {
188 sqsession_unregister('server_sort_array');
190 if ($set_thread == 1) {
191 setPref($data_dir, $username, "thread_$mailbox", 1);
192 $thread_sort_messages = '1';
193 } else if ($set_thread == 2) {
194 setPref($data_dir, $username, "thread_$mailbox", 0);
195 $thread_sort_messages = '0';
198 $thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox");
201 $thread_sort_messages = 0;
203 if ($thread_sort_messages == 1) {
204 $aLastSelectedMailbox['SORT_METHOD'] = 'THREAD';
205 } else if ($allow_server_sort) {
206 $aLastSelectedMailbox['SORT_METHOD'] = 'SERVER';
208 $aLastSelectedMailbox['SORT_METHOD'] = 'SQUIRREL';
212 $comp_uri = SM_PATH
. 'src/compose.php?mailbox='. urlencode($mailbox).
214 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false);
216 displayPageHeader($color, $mailbox);
218 do_hook('right_main_after_header');
220 /* display a message to the user that their mail has been sent */
221 if (isset($mail_sent) && $mail_sent == 'yes') {
222 $note = _("Your Message has been sent.");
225 echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br>\n";
228 if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION
) ) {
229 if ($just_logged_in == true) {
230 $just_logged_in = false;
231 sqsession_register($just_logged_in, 'just_logged_in');
233 if (strlen(trim($motd)) > 0) {
234 echo html_tag( 'table',
239 html_tag( 'td', $motd, 'center' )
241 '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' )
244 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' );
250 /*********************************************************************
251 * Check to see if we can use cache or not. Currently the only time *
252 * when you will not use it is when a link on the left hand frame is *
253 * used. Also check to make sure we actually have the array in the *
254 * registered session data. :) *
255 *********************************************************************/
256 if (! isset($use_mailbox_cache)) {
257 $use_mailbox_cache = 0;
260 if ($use_mailbox_cache && sqsession_is_registered('msgs')) {
261 showMessagesForMailbox($imapConnection,$aLastSelectedMailbox);
262 // showMessagesForMailbox($imapConnection, $mailbox, $numMessages,
263 // $startMessage, $sort, $color, $show_num,
264 // $use_mailbox_cache, '',$aMbxResponse);
266 if (sqsession_is_registered('msgs')) {
270 if (sqsession_is_registered('msort')) {
274 if (sqsession_is_registered('numMessages')) {
278 $numMessages = $aMbxResponse['EXISTS'];
280 showMessagesForMailbox($imapConnection,$aLastSelectedMailbox);
281 // showMessagesForMailbox($imapConnection, $mailbox, $numMessages,
282 // $startMessage, $sort, $color, $show_num,
283 // $use_mailbox_cache,'',$aMbxResponse);
285 if (sqsession_is_registered('msgs') && isset($msgs)) {
286 sqsession_register($msgs, 'msgs');
289 if (sqsession_is_registered('msort') && isset($msort)) {
290 sqsession_register($msort, 'msort');
293 sqsession_register($numMessages, 'numMessages');
295 do_hook('right_main_bottom');
296 sqimap_logout ($imapConnection);
297 echo '</body></html>';
299 sqsession_register($aLastSelectedMailbox,'aLastSelectedMailbox');