Another big update:
[squirrelmail.git] / src / right_main.php
... / ...
CommitLineData
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 */
19define('SM_PATH','../');
20
21/* SquirrelMail required files. */
22require_once(SM_PATH . 'include/validate.php');
23require_once(SM_PATH . 'functions/global.php');
24require_once(SM_PATH . 'functions/imap.php');
25require_once(SM_PATH . 'functions/date.php');
26require_once(SM_PATH . 'functions/mime.php');
27require_once(SM_PATH . 'functions/mailbox_display.php');
28require_once(SM_PATH . 'functions/display_messages.php');
29require_once(SM_PATH . 'functions/html.php');
30require_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 */
49sqgetGlobalVar('key', $key, SQ_COOKIE);
50sqgetGlobalVar('username', $username, SQ_SESSION);
51sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
52sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
53sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
54
55sqgetGlobalVar('mailbox', $mailbox);
56sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
57sqgetGlobalVar('numMessages' , $numMessages, SQ_SESSION);
58sqgetGlobalVar('session', $session, SQ_GET);
59sqgetGlobalVar('note', $note, SQ_GET);
60sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET);
61sqgetGlobalVar('use_mailbox_cache', $use_mailbox_cache, SQ_GET);
62
63if ( sqgetGlobalVar('startMessage', $temp) ) {
64 $startMessage = (int) $temp;
65}
66if ( sqgetGlobalVar('PG_SHOWNUM', $temp) ) {
67 $PG_SHOWNUM = (int) $temp;
68}
69if ( sqgetGlobalVar('PG_SHOWALL', $temp, SQ_GET) ) {
70 $PG_SHOWALL = (int) $temp;
71}
72if ( sqgetGlobalVar('newsort', $temp, SQ_GET) ) {
73 $newsort = (int) $temp;
74}
75if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) {
76 $checkall = (int) $temp;
77}
78if ( sqgetGlobalVar('set_thread', $temp, SQ_GET) ) {
79 $set_thread = (int) $temp;
80}
81if ( !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
91if (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}
102else if( isset( $PG_SHOWNUM ) ) {
103 $show_num = $PG_SHOWNUM;
104}
105
106if (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//if (!isset($startMessage) || ($startMessage == '')) {
122// $startMessage = 1;
123//}
124
125/* compensate for the UW vulnerability. */
126if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
127 substr($mailbox, 0, 1) == '/')) {
128 $mailbox = 'INBOX';
129}
130
131do_hook ('generic_header');
132
133$aMbxResponse = sqimap_mailbox_select($imapConnection, $mailbox);
134$aMbxResponse['SORT_ARRAY'] = false;
135
136sqgetGlobalVar('aLastSelectedMailbox',$aLastSelectedMailbox,SQ_SESSION);
137
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)
141if (!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'];
146}
147
148if ($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;
158 }
159 }
160 }
161}
162
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;
172
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;
176
177$aLastSelectedMailbox['AUTO_EXPUNGE'] = $auto_expunge;
178
179/* decide if we are thread sorting or not */
180$aLastSelectedMailbox['ALLOW_THREAD'] = $allow_thread_sort;
181if ($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');
186 }
187 if (sqsession_is_registered('server_sort_array')) {
188 sqsession_unregister('server_sort_array');
189 }
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';
196 }
197 } else {
198 $thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox");
199 }
200} else {
201 $thread_sort_messages = 0;
202}
203if ($thread_sort_messages == 1) {
204 $aLastSelectedMailbox['SORT_METHOD'] = 'THREAD';
205} else if ($allow_server_sort) {
206 $aLastSelectedMailbox['SORT_METHOD'] = 'SERVER';
207} else {
208 $aLastSelectedMailbox['SORT_METHOD'] = 'SQUIRREL';
209}
210
211if ($composenew) {
212 $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
213 "&session=$session";
214 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false);
215} else {
216 displayPageHeader($color, $mailbox);
217}
218do_hook('right_main_after_header');
219
220/* display a message to the user that their mail has been sent */
221if (isset($mail_sent) && $mail_sent == 'yes') {
222 $note = _("Your Message has been sent.");
223}
224if (isset($note)) {
225 echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br>\n";
226}
227
228if ( 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');
232
233 if (strlen(trim($motd)) > 0) {
234 echo html_tag( 'table',
235 html_tag( 'tr',
236 html_tag( 'td',
237 html_tag( 'table',
238 html_tag( 'tr',
239 html_tag( 'td', $motd, 'center' )
240 ) ,
241 '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' )
242 )
243 ) ,
244 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' );
245 }
246 }
247}
248
249
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 *********************************************************************/
256if (! isset($use_mailbox_cache)) {
257 $use_mailbox_cache = 0;
258}
259
260if ($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);
265} else {
266 if (sqsession_is_registered('msgs')) {
267 unset($msgs);
268 }
269
270 if (sqsession_is_registered('msort')) {
271 unset($msort);
272 }
273
274 if (sqsession_is_registered('numMessages')) {
275 unset($numMessages);
276 }
277
278 $numMessages = $aMbxResponse['EXISTS'];
279
280 showMessagesForMailbox($imapConnection,$aLastSelectedMailbox);
281// showMessagesForMailbox($imapConnection, $mailbox, $numMessages,
282// $startMessage, $sort, $color, $show_num,
283// $use_mailbox_cache,'',$aMbxResponse);
284
285 if (sqsession_is_registered('msgs') && isset($msgs)) {
286 sqsession_register($msgs, 'msgs');
287 }
288
289 if (sqsession_is_registered('msort') && isset($msort)) {
290 sqsession_register($msort, 'msort');
291 }
292
293 sqsession_register($numMessages, 'numMessages');
294}
295do_hook('right_main_bottom');
296sqimap_logout ($imapConnection);
297echo '</body></html>';
298
299sqsession_register($aLastSelectedMailbox,'aLastSelectedMailbox');
300
301?>