* Request UID and UIDVALIDITY from the status response if not available in the
[squirrelmail.git] / src / right_main.php
1 <?php
2 /**
3 * right_main.php
4 *
5 * Copyright (c) 1999-2004 The SquirrelMail Project Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * This is where the mailboxes are listed. This controls most of what
9 * goes on in SquirrelMail.
10 *
11 * @version $Id$
12 * @package squirrelmail
13 */
14
15 /**
16 * Path for SquirrelMail required files.
17 * @ignore
18 */
19 define('SM_PATH','../');
20
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');
31
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 *
39 * *
40 * incoming from cookie: *
41 * $key pass *
42 * incoming from session: *
43 * $username duh *
44 * *
45 ***********************************************************/
46
47
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);
54
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);
62
63 if ( sqgetGlobalVar('startMessage', $temp) ) {
64 $startMessage = (int) $temp;
65 }
66 if ( sqgetGlobalVar('PG_SHOWNUM', $temp) ) {
67 $PG_SHOWNUM = (int) $temp;
68 }
69 if ( sqgetGlobalVar('PG_SHOWALL', $temp, SQ_GET) ) {
70 $PG_SHOWALL = (int) $temp;
71 }
72 if ( sqgetGlobalVar('newsort', $temp, SQ_GET) ) {
73 $newsort = (int) $temp;
74 }
75 if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) {
76 $checkall = (int) $temp;
77 }
78 if ( sqgetGlobalVar('set_thread', $temp, SQ_GET) ) {
79 $set_thread = (int) $temp;
80 }
81 if ( !sqgetGlobalVar('composenew', $composenew, SQ_GET) ) {
82 $composenew = false;
83 }
84 /* end of get globals */
85
86
87 /* Open a connection on the imap port (143) */
88
89 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
90
91 if (isset($PG_SHOWALL)) {
92 if ($PG_SHOWALL) {
93 $PG_SHOWNUM=999999;
94 $show_num=$PG_SHOWNUM;
95 sqsession_register($PG_SHOWNUM, 'PG_SHOWNUM');
96 }
97 else {
98 sqsession_unregister('PG_SHOWNUM');
99 unset($PG_SHOWNUM);
100 }
101 }
102 else if( isset( $PG_SHOWNUM ) ) {
103 $show_num = $PG_SHOWNUM;
104 }
105
106 if (isset($newsort) ) {
107 if ( $newsort != $sort )
108 setPref($data_dir, $username, 'sort', $newsort);
109
110 $sort = $newsort;
111 sqsession_register($sort, 'sort');
112 }
113
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;
119 }
120
121
122 if (!isset($startMessage) || ($startMessage == '')) {
123 $startMessage = 1;
124 }
125
126 /* compensate for the UW vulnerability. */
127 if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
128 substr($mailbox, 0, 1) == '/')) {
129 $mailbox = 'INBOX';
130 }
131
132 /* decide if we are thread sorting or not */
133 if ($allow_thread_sort == TRUE) {
134 if (isset($set_thread)) {
135 if ($set_thread == 1) {
136 setPref($data_dir, $username, "thread_$mailbox", 1);
137 $thread_sort_messages = '1';
138 }
139 elseif ($set_thread == 2) {
140 setPref($data_dir, $username, "thread_$mailbox", 0);
141 $thread_sort_messages = '0';
142 }
143 }
144 else {
145 $thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox");
146 }
147 }
148 else {
149 $thread_sort_messages = 0;
150 }
151
152 do_hook ('generic_header');
153
154 $aMbxResponse = sqimap_mailbox_select($imapConnection, $mailbox);
155 $aMbxResponse['SORT_ARRAY'] = false;
156
157 sqgetGlobalVar('aLastSelectedMailbox',$aLastSelectedMailbox,SQ_SESSION);
158
159 // deal with imap servers that do not return the required UIDNEXT or
160 // UIDVALIDITY response
161 // from a SELECT call (since rfc 3501 it's required)
162 if (!isset($aMbxResponse['UIDNEXT']) || !isset($aMbxResponse['UIDVALIDITY'])) {
163 $aStatus = sqimap_status_messages($imapConnection,$mailbox,
164 array('UIDNEXT','UIDVALIDITY'));
165 $aMbxResponse['UIDNEXT'] = $aStatus['UIDNEXT'];
166 $aMbxResponse['UIDVALIDTY'] = $aStatus['UIDVALIDITY'];
167 }
168
169 if ($aLastSelectedMailbox && !isset($newsort)) {
170 // check if we deal with the same mailbox
171 if ($aLastSelectedMailbox['NAME'] == $mailbox) {
172 if ($aLastSelectedMailbox['EXISTS'] == $aMbxResponse['EXISTS'] &&
173 $aLastSelectedMailbox['UIDVALIDITY'] == $aMbxResponse['UIDVALIDITY'] &&
174 $aLastSelectedMailbox['UIDNEXT'] == $aMbxResponse['UIDNEXT']) {
175 // sort is still valid
176 sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION);
177 if ($server_sort_array && is_array($server_sort_array)) {
178 $aMbxResponse['SORT_ARRAY'] = $server_sort_array;
179 }
180 }
181 }
182 }
183
184 $aLastSelectedMailbox['NAME'] = $mailbox;
185 $aLastSelectedMailbox['EXISTS'] = $aMbxResponse['EXISTS'];
186 $aLastSelectedMailbox['UIDVALIDITY'] = $aMbxResponse['UIDVALIDITY'];
187 $aLastSelectedMailbox['UIDNEXT'] = $aMbxResponse['UIDNEXT'];
188
189 if ($composenew) {
190 $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
191 "&session=$session";
192 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false);
193 } else {
194 displayPageHeader($color, $mailbox);
195 }
196 do_hook('right_main_after_header');
197
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.");
201 }
202 if (isset($note)) {
203 echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br>\n";
204 }
205
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');
210
211 if (strlen(trim($motd)) > 0) {
212 echo html_tag( 'table',
213 html_tag( 'tr',
214 html_tag( 'td',
215 html_tag( 'table',
216 html_tag( 'tr',
217 html_tag( 'td', $motd, 'center' )
218 ) ,
219 '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' )
220 )
221 ) ,
222 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' );
223 }
224 }
225 }
226
227
228 /*********************************************************************
229 * Check to see if we can use cache or not. Currently the only time *
230 * when you will not use it is when a link on the left hand frame is *
231 * used. Also check to make sure we actually have the array in the *
232 * registered session data. :) *
233 *********************************************************************/
234 if (! isset($use_mailbox_cache)) {
235 $use_mailbox_cache = 0;
236 }
237
238 if ($use_mailbox_cache && sqsession_is_registered('msgs')) {
239 showMessagesForMailbox($imapConnection, $mailbox, $numMessages,
240 $startMessage, $sort, $color, $show_num,
241 $use_mailbox_cache, '',$aMbxResponse);
242 } else {
243 if (sqsession_is_registered('msgs')) {
244 unset($msgs);
245 }
246
247 if (sqsession_is_registered('msort')) {
248 unset($msort);
249 }
250
251 if (sqsession_is_registered('numMessages')) {
252 unset($numMessages);
253 }
254
255 $numMessages = $aMbxResponse['EXISTS'];
256
257 showMessagesForMailbox($imapConnection, $mailbox, $numMessages,
258 $startMessage, $sort, $color, $show_num,
259 $use_mailbox_cache,'',$aMbxResponse);
260
261 if (sqsession_is_registered('msgs') && isset($msgs)) {
262 sqsession_register($msgs, 'msgs');
263 }
264
265 if (sqsession_is_registered('msort') && isset($msort)) {
266 sqsession_register($msort, 'msort');
267 }
268
269 sqsession_register($numMessages, 'numMessages');
270 }
271 do_hook('right_main_bottom');
272 sqimap_logout ($imapConnection);
273 echo '</body></html>';
274
275 sqsession_register($aLastSelectedMailbox,'aLastSelectedMailbox');
276
277 ?>