typo
[squirrelmail.git] / src / right_main.php
CommitLineData
59177427 1<?php
c57b0888 2/**
3 * right_main.php
4 *
82d304a0 5 * Copyright (c) 1999-2004 The SquirrelMail Project Team
c57b0888 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 *
30967a1e 11 * @version $Id$
8f6f9ba5 12 * @package squirrelmail
c57b0888 13 */
14
30967a1e 15/**
16 * Path for SquirrelMail required files.
17 * @ignore
18 */
86725763 19define('SM_PATH','../');
20
21/* SquirrelMail required files. */
08185f2a 22require_once(SM_PATH . 'include/validate.php');
8650e9e1 23require_once(SM_PATH . 'functions/global.php');
86725763 24require_once(SM_PATH . 'functions/imap.php');
25require_once(SM_PATH . 'functions/date.php');
86725763 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');
c97f4825 30require_once(SM_PATH . 'functions/plugin.php');
c57b0888 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: *
c57b0888 41 * $key pass *
a32985a5 42 * incoming from session: *
43 * $username duh *
44 * *
c57b0888 45 ***********************************************************/
46
a32985a5 47
48/* lets get the global vars we may need */
1e12d1ff 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);
e0e30169 57sqgetGlobalVar('sort' , $sort, SQ_SESSION);
1e12d1ff 58sqgetGlobalVar('session', $session, SQ_GET);
59sqgetGlobalVar('note', $note, SQ_GET);
2ffeb7c5 60sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET);
1e12d1ff 61
62if ( sqgetGlobalVar('startMessage', $temp) ) {
63 $startMessage = (int) $temp;
a32985a5 64}
1e12d1ff 65if ( sqgetGlobalVar('PG_SHOWNUM', $temp) ) {
66 $PG_SHOWNUM = (int) $temp;
a32985a5 67}
1e12d1ff 68if ( sqgetGlobalVar('PG_SHOWALL', $temp, SQ_GET) ) {
69 $PG_SHOWALL = (int) $temp;
a32985a5 70}
1e12d1ff 71if ( sqgetGlobalVar('newsort', $temp, SQ_GET) ) {
72 $newsort = (int) $temp;
a32985a5 73}
1e12d1ff 74if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) {
75 $checkall = (int) $temp;
a32985a5 76}
1e12d1ff 77if ( sqgetGlobalVar('set_thread', $temp, SQ_GET) ) {
78 $set_thread = (int) $temp;
a32985a5 79}
1e12d1ff 80if ( !sqgetGlobalVar('composenew', $composenew, SQ_GET) ) {
8cc72ada 81 $composenew = false;
82}
a32985a5 83/* end of get globals */
84
85
e0e30169 86/* Open an imap connection */
6f223ace 87
c57b0888 88$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
89
cf710efe 90if (isset($PG_SHOWALL)) {
91 if ($PG_SHOWALL) {
92 $PG_SHOWNUM=999999;
93 $show_num=$PG_SHOWNUM;
a32985a5 94 sqsession_register($PG_SHOWNUM, 'PG_SHOWNUM');
cf710efe 95 }
96 else {
a32985a5 97 sqsession_unregister('PG_SHOWNUM');
cf710efe 98 unset($PG_SHOWNUM);
99 }
100}
101else if( isset( $PG_SHOWNUM ) ) {
bdfb67f8 102 $show_num = $PG_SHOWNUM;
103}
e0e30169 104$mailbox = (isset($mailbox) && $mailbox) ? $mailbox : 'INBOX';
105/* compensate for the UW vulnerability. */
106if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
107 substr($mailbox, 0, 1) == '/')) {
108 $mailbox = 'INBOX';
109}
bdfb67f8 110
94a4ea53 111if (isset($newsort) ) {
e0e30169 112 if ( $newsort != $sort ) {
94a4ea53 113 setPref($data_dir, $username, 'sort', $newsort);
e0e30169 114 }
115 $oldsort = $sort;
94a4ea53 116 $sort = $newsort;
117 sqsession_register($sort, 'sort');
118}
e372ee8c 119
a32985a5 120do_hook ('generic_header');
7c612fdd 121
fb75a74e 122$aMbxResponse = sqimap_mailbox_select($imapConnection, $mailbox);
fe6efa94 123$aMbxResponse['SORT_ARRAY'] = false;
124
125sqgetGlobalVar('aLastSelectedMailbox',$aLastSelectedMailbox,SQ_SESSION);
126
26e90c74 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)
130if (!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
e0e30169 137if ($aLastSelectedMailbox) {
26e90c74 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']) {
26e90c74 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;
e0e30169 146 // check if oldsort can be used in case we changed the sort order of the same column
f6fbffac 147 if (isset($newsort) && $newsort) {
e0e30169 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;
26e90c74 156 }
157 }
139b3991 158 }
fe6efa94 159}
139b3991 160
fe6efa94 161$aLastSelectedMailbox['NAME'] = $mailbox;
162$aLastSelectedMailbox['EXISTS'] = $aMbxResponse['EXISTS'];
163$aLastSelectedMailbox['UIDVALIDITY'] = $aMbxResponse['UIDVALIDITY'];
164$aLastSelectedMailbox['UIDNEXT'] = $aMbxResponse['UIDNEXT'];
8cc8ec79 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;
e0e30169 169$aLastSelectedMailbox['LIMIT'] = ($show_num != 999999) ? $show_num : $aMbxResponse['EXISTS'];
8cc8ec79 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;
96e3c0bd 174$aLastSelectedMailbox['RIGHTS'] = $aMbxResponse['RIGHTS'];
8cc8ec79 175
176$aLastSelectedMailbox['AUTO_EXPUNGE'] = $auto_expunge;
6f223ace 177
139b3991 178/* decide if we are thread sorting or not */
8cc8ec79 179$aLastSelectedMailbox['ALLOW_THREAD'] = $allow_thread_sort;
139b3991 180if ($allow_thread_sort == TRUE) {
181 if (isset($set_thread)) {
8cc8ec79 182 $aLastSelectedMailbox['SORT_ARRAY'] = false;
139b3991 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}
8cc8ec79 202if ($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}
139b3991 209
8cc72ada 210if ($composenew) {
211 $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
c97f4825 212 "&session=$session";
11af81b9 213 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false);
6f223ace 214} else {
215 displayPageHeader($color, $mailbox);
216}
c57b0888 217do_hook('right_main_after_header');
2ffeb7c5 218
219/* display a message to the user that their mail has been sent */
220if (isset($mail_sent) && $mail_sent == 'yes') {
221 $note = _("Your Message has been sent.");
222}
c57b0888 223if (isset($note)) {
fab3baa6 224 echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br>\n";
c57b0888 225}
226
f38b7cf0 227if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION) ) {
a32985a5 228 if ($just_logged_in == true) {
229 $just_logged_in = false;
dd2a2e15 230 sqsession_register($just_logged_in, 'just_logged_in');
a32985a5 231
232 if (strlen(trim($motd)) > 0) {
233 echo html_tag( 'table',
234 html_tag( 'tr',
c97f4825 235 html_tag( 'td',
a32985a5 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 }
23d6bd09 245 }
c57b0888 246}
247
e0e30169 248showMessagesForMailbox($imapConnection,$aLastSelectedMailbox);
7c612fdd 249
c57b0888 250do_hook('right_main_bottom');
251sqimap_logout ($imapConnection);
dcc1cc82 252echo '</body></html>';
253
fe6efa94 254sqsession_register($aLastSelectedMailbox,'aLastSelectedMailbox');
255
dcc1cc82 256?>