Missed one var to set
[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('sort' , $sort, SQ_SESSION);
58 sqgetGlobalVar('session', $session, SQ_GET);
59 sqgetGlobalVar('note', $note, SQ_GET);
60 sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET);
61
62 if ( sqgetGlobalVar('startMessage', $temp) ) {
63 $startMessage = (int) $temp;
64 }
65 if ( sqgetGlobalVar('PG_SHOWNUM', $temp) ) {
66 $PG_SHOWNUM = (int) $temp;
67 }
68 if ( sqgetGlobalVar('PG_SHOWALL', $temp, SQ_GET) ) {
69 $PG_SHOWALL = (int) $temp;
70 }
71 if ( sqgetGlobalVar('newsort', $temp, SQ_GET) ) {
72 $newsort = (int) $temp;
73 }
74 if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) {
75 $checkall = (int) $temp;
76 }
77 if ( sqgetGlobalVar('set_thread', $temp, SQ_GET) ) {
78 $set_thread = (int) $temp;
79 }
80 if ( !sqgetGlobalVar('composenew', $composenew, SQ_GET) ) {
81 $composenew = false;
82 }
83 /* end of get globals */
84
85
86 /* Open an imap connection */
87
88 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
89
90 if (isset($PG_SHOWALL)) {
91 if ($PG_SHOWALL) {
92 $PG_SHOWNUM=999999;
93 $show_num=$PG_SHOWNUM;
94 sqsession_register($PG_SHOWNUM, 'PG_SHOWNUM');
95 }
96 else {
97 sqsession_unregister('PG_SHOWNUM');
98 unset($PG_SHOWNUM);
99 }
100 }
101 else if( isset( $PG_SHOWNUM ) ) {
102 $show_num = $PG_SHOWNUM;
103 }
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) == '/')) {
108 $mailbox = 'INBOX';
109 }
110
111 if (isset($newsort) ) {
112 if ( $newsort != $sort ) {
113 setPref($data_dir, $username, 'sort', $newsort);
114 }
115 $oldsort = $sort;
116 $sort = $newsort;
117 sqsession_register($sort, 'sort');
118 }
119
120 do_hook ('generic_header');
121
122 $aMbxResponse = sqimap_mailbox_select($imapConnection, $mailbox);
123 $aMbxResponse['SORT_ARRAY'] = false;
124
125 sqgetGlobalVar('aLastSelectedMailbox',$aLastSelectedMailbox,SQ_SESSION);
126
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'];
135 }
136
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);
151 } else {
152 $server_sort_array = false;
153 }
154 }
155 $aMbxResponse['SORT_ARRAY'] = $server_sort_array;
156 }
157 }
158 }
159 }
160
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'];
170
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;
174 $aLastSelectedMailbox['RIGHTS'] = $aMbxResponse['RIGHTS'];
175
176 $aLastSelectedMailbox['AUTO_EXPUNGE'] = $auto_expunge;
177
178 /* decide if we are thread sorting or not */
179 $aLastSelectedMailbox['ALLOW_THREAD'] = $allow_thread_sort;
180 if ($allow_thread_sort == TRUE) {
181 if (isset($set_thread)) {
182 $aLastSelectedMailbox['SORT_ARRAY'] = false;
183 if (sqsession_is_registered('indent_array')) {
184 sqsession_unregister('indent_array');
185 }
186 if (sqsession_is_registered('server_sort_array')) {
187 sqsession_unregister('server_sort_array');
188 }
189 if ($set_thread == 1) {
190 setPref($data_dir, $username, "thread_$mailbox", 1);
191 $thread_sort_messages = '1';
192 } else if ($set_thread == 2) {
193 setPref($data_dir, $username, "thread_$mailbox", 0);
194 $thread_sort_messages = '0';
195 }
196 } else {
197 $thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox");
198 }
199 } else {
200 $thread_sort_messages = 0;
201 }
202 if ($thread_sort_messages == 1) {
203 $aLastSelectedMailbox['SORT_METHOD'] = 'THREAD';
204 } else if ($allow_server_sort) {
205 $aLastSelectedMailbox['SORT_METHOD'] = 'SERVER';
206 } else {
207 $aLastSelectedMailbox['SORT_METHOD'] = 'SQUIRREL';
208 }
209
210 if ($composenew) {
211 $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
212 "&session=$session";
213 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false);
214 } else {
215 displayPageHeader($color, $mailbox);
216 }
217 do_hook('right_main_after_header');
218
219 /* display a message to the user that their mail has been sent */
220 if (isset($mail_sent) && $mail_sent == 'yes') {
221 $note = _("Your Message has been sent.");
222 }
223 if (isset($note)) {
224 echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br>\n";
225 }
226
227 if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION) ) {
228 if ($just_logged_in == true) {
229 $just_logged_in = false;
230 sqsession_register($just_logged_in, 'just_logged_in');
231
232 if (strlen(trim($motd)) > 0) {
233 echo html_tag( 'table',
234 html_tag( 'tr',
235 html_tag( 'td',
236 html_tag( 'table',
237 html_tag( 'tr',
238 html_tag( 'td', $motd, 'center' )
239 ) ,
240 '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' )
241 )
242 ) ,
243 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' );
244 }
245 }
246 }
247
248 showMessagesForMailbox($imapConnection,$aLastSelectedMailbox);
249
250 do_hook('right_main_bottom');
251 sqimap_logout ($imapConnection);
252 echo '</body></html>';
253
254 sqsession_register($aLastSelectedMailbox,'aLastSelectedMailbox');
255
256 ?>