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 |
19 | define('SM_PATH','../'); |
20 | |
21 | /* SquirrelMail required files. */ |
08185f2a |
22 | require_once(SM_PATH . 'include/validate.php'); |
8650e9e1 |
23 | require_once(SM_PATH . 'functions/global.php'); |
86725763 |
24 | require_once(SM_PATH . 'functions/imap.php'); |
25 | require_once(SM_PATH . 'functions/date.php'); |
86725763 |
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'); |
c97f4825 |
30 | require_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 |
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); |
d7048dd4 |
57 | sqgetGlobalVar('numMessages' , $numMessages, SQ_SESSION); |
1e12d1ff |
58 | sqgetGlobalVar('session', $session, SQ_GET); |
59 | sqgetGlobalVar('note', $note, SQ_GET); |
2ffeb7c5 |
60 | sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET); |
d7048dd4 |
61 | sqgetGlobalVar('use_mailbox_cache', $use_mailbox_cache, SQ_GET); |
1e12d1ff |
62 | |
63 | if ( sqgetGlobalVar('startMessage', $temp) ) { |
64 | $startMessage = (int) $temp; |
a32985a5 |
65 | } |
1e12d1ff |
66 | if ( sqgetGlobalVar('PG_SHOWNUM', $temp) ) { |
67 | $PG_SHOWNUM = (int) $temp; |
a32985a5 |
68 | } |
1e12d1ff |
69 | if ( sqgetGlobalVar('PG_SHOWALL', $temp, SQ_GET) ) { |
70 | $PG_SHOWALL = (int) $temp; |
a32985a5 |
71 | } |
1e12d1ff |
72 | if ( sqgetGlobalVar('newsort', $temp, SQ_GET) ) { |
73 | $newsort = (int) $temp; |
a32985a5 |
74 | } |
1e12d1ff |
75 | if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) { |
76 | $checkall = (int) $temp; |
a32985a5 |
77 | } |
1e12d1ff |
78 | if ( sqgetGlobalVar('set_thread', $temp, SQ_GET) ) { |
79 | $set_thread = (int) $temp; |
a32985a5 |
80 | } |
1e12d1ff |
81 | if ( !sqgetGlobalVar('composenew', $composenew, SQ_GET) ) { |
8cc72ada |
82 | $composenew = false; |
83 | } |
a32985a5 |
84 | /* end of get globals */ |
85 | |
86 | |
c57b0888 |
87 | /* Open a connection on the imap port (143) */ |
6f223ace |
88 | |
c57b0888 |
89 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
90 | |
cf710efe |
91 | if (isset($PG_SHOWALL)) { |
92 | if ($PG_SHOWALL) { |
93 | $PG_SHOWNUM=999999; |
94 | $show_num=$PG_SHOWNUM; |
a32985a5 |
95 | sqsession_register($PG_SHOWNUM, 'PG_SHOWNUM'); |
cf710efe |
96 | } |
97 | else { |
a32985a5 |
98 | sqsession_unregister('PG_SHOWNUM'); |
cf710efe |
99 | unset($PG_SHOWNUM); |
100 | } |
101 | } |
102 | else if( isset( $PG_SHOWNUM ) ) { |
bdfb67f8 |
103 | $show_num = $PG_SHOWNUM; |
104 | } |
105 | |
94a4ea53 |
106 | if (isset($newsort) ) { |
107 | if ( $newsort != $sort ) |
108 | setPref($data_dir, $username, 'sort', $newsort); |
e372ee8c |
109 | |
94a4ea53 |
110 | $sort = $newsort; |
111 | sqsession_register($sort, 'sort'); |
112 | } |
e372ee8c |
113 | |
114 | /* If the page has been loaded without a specific mailbox, */ |
115 | /* send them to the inbox */ |
8cc8ec79 |
116 | //if (!isset($mailbox)) { |
117 | // $mailbox = 'INBOX'; |
118 | // $startMessage = 1; |
119 | //} |
e372ee8c |
120 | |
8cc8ec79 |
121 | //if (!isset($startMessage) || ($startMessage == '')) { |
122 | // $startMessage = 1; |
123 | //} |
e372ee8c |
124 | |
125 | /* compensate for the UW vulnerability. */ |
126 | if ($imap_server_type == 'uw' && (strstr($mailbox, '../') || |
127 | substr($mailbox, 0, 1) == '/')) { |
128 | $mailbox = 'INBOX'; |
129 | } |
130 | |
a32985a5 |
131 | do_hook ('generic_header'); |
7c612fdd |
132 | |
fb75a74e |
133 | $aMbxResponse = sqimap_mailbox_select($imapConnection, $mailbox); |
fe6efa94 |
134 | $aMbxResponse['SORT_ARRAY'] = false; |
135 | |
136 | sqgetGlobalVar('aLastSelectedMailbox',$aLastSelectedMailbox,SQ_SESSION); |
137 | |
26e90c74 |
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) |
141 | if (!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 | |
fe6efa94 |
148 | if ($aLastSelectedMailbox && !isset($newsort)) { |
26e90c74 |
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 | } |
139b3991 |
160 | } |
fe6efa94 |
161 | } |
139b3991 |
162 | |
fe6efa94 |
163 | $aLastSelectedMailbox['NAME'] = $mailbox; |
164 | $aLastSelectedMailbox['EXISTS'] = $aMbxResponse['EXISTS']; |
165 | $aLastSelectedMailbox['UIDVALIDITY'] = $aMbxResponse['UIDVALIDITY']; |
166 | $aLastSelectedMailbox['UIDNEXT'] = $aMbxResponse['UIDNEXT']; |
8cc8ec79 |
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; |
6f223ace |
178 | |
139b3991 |
179 | /* decide if we are thread sorting or not */ |
8cc8ec79 |
180 | $aLastSelectedMailbox['ALLOW_THREAD'] = $allow_thread_sort; |
139b3991 |
181 | if ($allow_thread_sort == TRUE) { |
182 | if (isset($set_thread)) { |
8cc8ec79 |
183 | $aLastSelectedMailbox['SORT_ARRAY'] = false; |
139b3991 |
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 | } |
8cc8ec79 |
203 | if ($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 | } |
139b3991 |
210 | |
8cc72ada |
211 | if ($composenew) { |
212 | $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox). |
c97f4825 |
213 | "&session=$session"; |
11af81b9 |
214 | displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false); |
6f223ace |
215 | } else { |
216 | displayPageHeader($color, $mailbox); |
217 | } |
c57b0888 |
218 | do_hook('right_main_after_header'); |
2ffeb7c5 |
219 | |
220 | /* display a message to the user that their mail has been sent */ |
221 | if (isset($mail_sent) && $mail_sent == 'yes') { |
222 | $note = _("Your Message has been sent."); |
223 | } |
c57b0888 |
224 | if (isset($note)) { |
fab3baa6 |
225 | echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br>\n"; |
c57b0888 |
226 | } |
227 | |
f38b7cf0 |
228 | if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION) ) { |
a32985a5 |
229 | if ($just_logged_in == true) { |
230 | $just_logged_in = false; |
dd2a2e15 |
231 | sqsession_register($just_logged_in, 'just_logged_in'); |
a32985a5 |
232 | |
233 | if (strlen(trim($motd)) > 0) { |
234 | echo html_tag( 'table', |
235 | html_tag( 'tr', |
c97f4825 |
236 | html_tag( 'td', |
a32985a5 |
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 | } |
23d6bd09 |
246 | } |
c57b0888 |
247 | } |
248 | |
7c612fdd |
249 | |
c57b0888 |
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 | *********************************************************************/ |
256 | if (! isset($use_mailbox_cache)) { |
257 | $use_mailbox_cache = 0; |
258 | } |
259 | |
d7c82551 |
260 | if ($use_mailbox_cache && sqsession_is_registered('msgs')) { |
8cc8ec79 |
261 | showMessagesForMailbox($imapConnection,$aLastSelectedMailbox); |
262 | // showMessagesForMailbox($imapConnection, $mailbox, $numMessages, |
263 | // $startMessage, $sort, $color, $show_num, |
264 | // $use_mailbox_cache, '',$aMbxResponse); |
c57b0888 |
265 | } else { |
d7c82551 |
266 | if (sqsession_is_registered('msgs')) { |
c57b0888 |
267 | unset($msgs); |
23d6bd09 |
268 | } |
269 | |
d7c82551 |
270 | if (sqsession_is_registered('msort')) { |
c57b0888 |
271 | unset($msort); |
23d6bd09 |
272 | } |
a37f3771 |
273 | |
d7c82551 |
274 | if (sqsession_is_registered('numMessages')) { |
c57b0888 |
275 | unset($numMessages); |
2016e645 |
276 | } |
e452ce9b |
277 | |
fe6efa94 |
278 | $numMessages = $aMbxResponse['EXISTS']; |
23d6bd09 |
279 | |
8cc8ec79 |
280 | showMessagesForMailbox($imapConnection,$aLastSelectedMailbox); |
281 | // showMessagesForMailbox($imapConnection, $mailbox, $numMessages, |
282 | // $startMessage, $sort, $color, $show_num, |
283 | // $use_mailbox_cache,'',$aMbxResponse); |
23d6bd09 |
284 | |
d7c82551 |
285 | if (sqsession_is_registered('msgs') && isset($msgs)) { |
a32985a5 |
286 | sqsession_register($msgs, 'msgs'); |
c57b0888 |
287 | } |
1108e8bb |
288 | |
d7c82551 |
289 | if (sqsession_is_registered('msort') && isset($msort)) { |
a32985a5 |
290 | sqsession_register($msort, 'msort'); |
c57b0888 |
291 | } |
9f2215a1 |
292 | |
a32985a5 |
293 | sqsession_register($numMessages, 'numMessages'); |
c57b0888 |
294 | } |
c57b0888 |
295 | do_hook('right_main_bottom'); |
296 | sqimap_logout ($imapConnection); |
dcc1cc82 |
297 | echo '</body></html>'; |
298 | |
fe6efa94 |
299 | sqsession_register($aLastSelectedMailbox,'aLastSelectedMailbox'); |
300 | |
dcc1cc82 |
301 | ?> |