47f488a380b2f8c9ab662d64aa26489ac5119814
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('sort' , $sort, SQ_SESSION
);
58 sqgetGlobalVar('session', $session, SQ_GET
);
59 sqgetGlobalVar('note', $note, SQ_GET
);
60 sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET
);
62 if ( sqgetGlobalVar('startMessage', $temp) ) {
63 $startMessage = (int) $temp;
65 if ( sqgetGlobalVar('PG_SHOWNUM', $temp) ) {
66 $PG_SHOWNUM = (int) $temp;
68 if ( sqgetGlobalVar('PG_SHOWALL', $temp, SQ_GET
) ) {
69 $PG_SHOWALL = (int) $temp;
71 if ( sqgetGlobalVar('newsort', $temp, SQ_GET
) ) {
72 $newsort = (int) $temp;
74 if ( sqgetGlobalVar('checkall', $temp, SQ_GET
) ) {
75 $checkall = (int) $temp;
77 if ( sqgetGlobalVar('set_thread', $temp, SQ_GET
) ) {
78 $set_thread = (int) $temp;
80 if ( !sqgetGlobalVar('composenew', $composenew, SQ_GET
) ) {
83 /* end of get globals */
86 /* Open an imap connection */
88 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
90 if (isset($PG_SHOWALL)) {
93 $show_num=$PG_SHOWNUM;
94 sqsession_register($PG_SHOWNUM, 'PG_SHOWNUM');
97 sqsession_unregister('PG_SHOWNUM');
101 else if( isset( $PG_SHOWNUM ) ) {
102 $show_num = $PG_SHOWNUM;
104 $mailbox = (isset($mailbox) && $mailbox) ?
$mailbox : 'INBOX';
105 /* compensate for the UW vulnerability. */
106 if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
107 substr($mailbox, 0, 1) == '/')) {
111 if (isset($newsort) ) {
112 if ( $newsort != $sort ) {
113 setPref($data_dir, $username, 'sort', $newsort);
117 sqsession_register($sort, 'sort');
120 do_hook ('generic_header');
122 $aMbxResponse = sqimap_mailbox_select($imapConnection, $mailbox);
123 $aMbxResponse['SORT_ARRAY'] = false;
125 sqgetGlobalVar('aLastSelectedMailbox',$aLastSelectedMailbox,SQ_SESSION
);
127 // deal with imap servers that do not return the required UIDNEXT or
128 // UIDVALIDITY response
129 // from a SELECT call (since rfc 3501 it's required)
130 if (!isset($aMbxResponse['UIDNEXT']) ||
!isset($aMbxResponse['UIDVALIDITY'])) {
131 $aStatus = sqimap_status_messages($imapConnection,$mailbox,
132 array('UIDNEXT','UIDVALIDITY'));
133 $aMbxResponse['UIDNEXT'] = $aStatus['UIDNEXT'];
134 $aMbxResponse['UIDVALIDTY'] = $aStatus['UIDVALIDITY'];
137 if ($aLastSelectedMailbox) {
138 // check if we deal with the same mailbox
139 if ($aLastSelectedMailbox['NAME'] == $mailbox) {
140 if ($aLastSelectedMailbox['EXISTS'] == $aMbxResponse['EXISTS'] &&
141 $aLastSelectedMailbox['UIDVALIDITY'] == $aMbxResponse['UIDVALIDITY'] &&
142 $aLastSelectedMailbox['UIDNEXT'] == $aMbxResponse['UIDNEXT']) {
143 sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION
);
144 if ($server_sort_array && is_array($server_sort_array)) {
145 $aMbxResponse['SORT_ARRAY'] = $server_sort_array;
146 // check if oldsort can be used in case we changed the sort order of the same column
147 if (isset($newsort) ) {
148 if ((($newsort %
2) && ($newsort +
1 == $oldsort)) ||
149 (!($newsort %
2) && ($newsort - 1 == $oldsort))) {
150 $server_sort_array = array_reverse($server_sort_array);
152 $server_sort_array = false;
155 $aMbxResponse['SORT_ARRAY'] = $server_sort_array;
161 $aLastSelectedMailbox['NAME'] = $mailbox;
162 $aLastSelectedMailbox['EXISTS'] = $aMbxResponse['EXISTS'];
163 $aLastSelectedMailbox['UIDVALIDITY'] = $aMbxResponse['UIDVALIDITY'];
164 $aLastSelectedMailbox['UIDNEXT'] = $aMbxResponse['UIDNEXT'];
165 $aLastSelectedMailbox['PERMANENTFLAGS'] = $aMbxResponse['PERMANENTFLAGS'];
166 $aLastSelectedMailbox['OFFSET'] = (isset($startMessage) && $startMessage) ?
$startMessage -1 : 0;
167 $aLastSelectedMailbox['PAGEOFFSET'] = (isset($startMessage) && $startMessage) ?
$startMessage : 1;
168 $aLastSelectedMailbox['SORT'] = ($sort !== false) ?
$sort : 0;
169 $aLastSelectedMailbox['LIMIT'] = ($show_num != 999999) ?
$show_num : $aMbxResponse['EXISTS'];
171 $aLastSelectedMailbox['UIDSET'] = $aMbxResponse['SORT_ARRAY'];
172 $aLastSelectedMailbox['SEEN'] = (isset($aMbxResponse['SEEN'])) ?
$aMbxResponse['SEEN'] : $aMbxResponse['EXISTS'];
173 $aLastSelectedMailbox['RECENT'] = (isset($aMbxResponse['RECENT'])) ?
$aMbxResponse['RECENT'] : 0;
175 $aLastSelectedMailbox['AUTO_EXPUNGE'] = $auto_expunge;
177 /* decide if we are thread sorting or not */
178 $aLastSelectedMailbox['ALLOW_THREAD'] = $allow_thread_sort;
179 if ($allow_thread_sort == TRUE) {
180 if (isset($set_thread)) {
181 $aLastSelectedMailbox['SORT_ARRAY'] = false;
182 if (sqsession_is_registered('indent_array')) {
183 sqsession_unregister('indent_array');
185 if (sqsession_is_registered('server_sort_array')) {
186 sqsession_unregister('server_sort_array');
188 if ($set_thread == 1) {
189 setPref($data_dir, $username, "thread_$mailbox", 1);
190 $thread_sort_messages = '1';
191 } else if ($set_thread == 2) {
192 setPref($data_dir, $username, "thread_$mailbox", 0);
193 $thread_sort_messages = '0';
196 $thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox");
199 $thread_sort_messages = 0;
201 if ($thread_sort_messages == 1) {
202 $aLastSelectedMailbox['SORT_METHOD'] = 'THREAD';
203 } else if ($allow_server_sort) {
204 $aLastSelectedMailbox['SORT_METHOD'] = 'SERVER';
206 $aLastSelectedMailbox['SORT_METHOD'] = 'SQUIRREL';
210 $comp_uri = SM_PATH
. 'src/compose.php?mailbox='. urlencode($mailbox).
212 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false);
214 displayPageHeader($color, $mailbox);
216 do_hook('right_main_after_header');
218 /* display a message to the user that their mail has been sent */
219 if (isset($mail_sent) && $mail_sent == 'yes') {
220 $note = _("Your Message has been sent.");
223 echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br>\n";
226 if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION
) ) {
227 if ($just_logged_in == true) {
228 $just_logged_in = false;
229 sqsession_register($just_logged_in, 'just_logged_in');
231 if (strlen(trim($motd)) > 0) {
232 echo html_tag( 'table',
237 html_tag( 'td', $motd, 'center' )
239 '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' )
242 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' );
247 showMessagesForMailbox($imapConnection,$aLastSelectedMailbox);
249 do_hook('right_main_bottom');
250 sqimap_logout ($imapConnection);
251 echo '</body></html>';
253 sqsession_register($aLastSelectedMailbox,'aLastSelectedMailbox');