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 */ |
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 | |
7c612fdd |
132 | /* decide if we are thread sorting or not */ |
794d59c0 |
133 | if ($allow_thread_sort == TRUE) { |
7c612fdd |
134 | if (isset($set_thread)) { |
135 | if ($set_thread == 1) { |
78cc4b12 |
136 | setPref($data_dir, $username, "thread_$mailbox", 1); |
c97f4825 |
137 | $thread_sort_messages = '1'; |
7c612fdd |
138 | } |
139 | elseif ($set_thread == 2) { |
78cc4b12 |
140 | setPref($data_dir, $username, "thread_$mailbox", 0); |
c97f4825 |
141 | $thread_sort_messages = '0'; |
7c612fdd |
142 | } |
143 | } |
144 | else { |
78cc4b12 |
145 | $thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox"); |
7c612fdd |
146 | } |
147 | } |
148 | else { |
149 | $thread_sort_messages = 0; |
c97f4825 |
150 | } |
7c612fdd |
151 | |
a32985a5 |
152 | do_hook ('generic_header'); |
7c612fdd |
153 | |
fb75a74e |
154 | $aMbxResponse = sqimap_mailbox_select($imapConnection, $mailbox); |
fe6efa94 |
155 | $aMbxResponse['SORT_ARRAY'] = false; |
156 | |
157 | sqgetGlobalVar('aLastSelectedMailbox',$aLastSelectedMailbox,SQ_SESSION); |
158 | |
159 | if ($aLastSelectedMailbox && !isset($newsort)) { |
160 | // check if we deal with the same mailbox |
161 | if ($aLastSelectedMailbox['NAME'] == $mailbox) { |
162 | if ($aLastSelectedMailbox['EXISTS'] == $aMbxResponse['EXISTS'] && |
163 | $aLastSelectedMailbox['UIDVALIDITY'] == $aMbxResponse['UIDVALIDITY'] && |
164 | $aLastSelectedMailbox['UIDNEXT'] == $aMbxResponse['UIDNEXT']) { |
165 | // sort is still valid |
166 | sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION); |
167 | $aMbxResponse['SORT_ARRAY'] = $server_sort_array; |
168 | } |
169 | } |
170 | } |
171 | |
172 | $aLastSelectedMailbox['NAME'] = $mailbox; |
173 | $aLastSelectedMailbox['EXISTS'] = $aMbxResponse['EXISTS']; |
174 | $aLastSelectedMailbox['UIDVALIDITY'] = $aMbxResponse['UIDVALIDITY']; |
175 | $aLastSelectedMailbox['UIDNEXT'] = $aMbxResponse['UIDNEXT']; |
6f223ace |
176 | |
8cc72ada |
177 | if ($composenew) { |
178 | $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox). |
c97f4825 |
179 | "&session=$session"; |
11af81b9 |
180 | displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false); |
6f223ace |
181 | } else { |
182 | displayPageHeader($color, $mailbox); |
183 | } |
c57b0888 |
184 | do_hook('right_main_after_header'); |
2ffeb7c5 |
185 | |
186 | /* display a message to the user that their mail has been sent */ |
187 | if (isset($mail_sent) && $mail_sent == 'yes') { |
188 | $note = _("Your Message has been sent."); |
189 | } |
c57b0888 |
190 | if (isset($note)) { |
fab3baa6 |
191 | echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br>\n"; |
c57b0888 |
192 | } |
193 | |
f38b7cf0 |
194 | if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION) ) { |
a32985a5 |
195 | if ($just_logged_in == true) { |
196 | $just_logged_in = false; |
dd2a2e15 |
197 | sqsession_register($just_logged_in, 'just_logged_in'); |
a32985a5 |
198 | |
199 | if (strlen(trim($motd)) > 0) { |
200 | echo html_tag( 'table', |
201 | html_tag( 'tr', |
c97f4825 |
202 | html_tag( 'td', |
a32985a5 |
203 | html_tag( 'table', |
204 | html_tag( 'tr', |
205 | html_tag( 'td', $motd, 'center' ) |
206 | ) , |
207 | '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' ) |
208 | ) |
209 | ) , |
210 | 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' ); |
211 | } |
23d6bd09 |
212 | } |
c57b0888 |
213 | } |
214 | |
7c612fdd |
215 | |
c57b0888 |
216 | /********************************************************************* |
217 | * Check to see if we can use cache or not. Currently the only time * |
218 | * when you will not use it is when a link on the left hand frame is * |
219 | * used. Also check to make sure we actually have the array in the * |
220 | * registered session data. :) * |
221 | *********************************************************************/ |
222 | if (! isset($use_mailbox_cache)) { |
223 | $use_mailbox_cache = 0; |
224 | } |
225 | |
d7c82551 |
226 | if ($use_mailbox_cache && sqsession_is_registered('msgs')) { |
fb75a74e |
227 | showMessagesForMailbox($imapConnection, $mailbox, $numMessages, |
228 | $startMessage, $sort, $color, $show_num, |
229 | $use_mailbox_cache, '',$aMbxResponse); |
c57b0888 |
230 | } else { |
d7c82551 |
231 | if (sqsession_is_registered('msgs')) { |
c57b0888 |
232 | unset($msgs); |
23d6bd09 |
233 | } |
234 | |
d7c82551 |
235 | if (sqsession_is_registered('msort')) { |
c57b0888 |
236 | unset($msort); |
23d6bd09 |
237 | } |
a37f3771 |
238 | |
d7c82551 |
239 | if (sqsession_is_registered('numMessages')) { |
c57b0888 |
240 | unset($numMessages); |
2016e645 |
241 | } |
e452ce9b |
242 | |
fe6efa94 |
243 | $numMessages = $aMbxResponse['EXISTS']; |
23d6bd09 |
244 | |
c97f4825 |
245 | showMessagesForMailbox($imapConnection, $mailbox, $numMessages, |
c57b0888 |
246 | $startMessage, $sort, $color, $show_num, |
fb75a74e |
247 | $use_mailbox_cache,'',$aMbxResponse); |
23d6bd09 |
248 | |
d7c82551 |
249 | if (sqsession_is_registered('msgs') && isset($msgs)) { |
a32985a5 |
250 | sqsession_register($msgs, 'msgs'); |
c57b0888 |
251 | } |
1108e8bb |
252 | |
d7c82551 |
253 | if (sqsession_is_registered('msort') && isset($msort)) { |
a32985a5 |
254 | sqsession_register($msort, 'msort'); |
c57b0888 |
255 | } |
9f2215a1 |
256 | |
a32985a5 |
257 | sqsession_register($numMessages, 'numMessages'); |
c57b0888 |
258 | } |
c57b0888 |
259 | do_hook('right_main_bottom'); |
260 | sqimap_logout ($imapConnection); |
dcc1cc82 |
261 | echo '</body></html>'; |
262 | |
fe6efa94 |
263 | sqsession_register($aLastSelectedMailbox,'aLastSelectedMailbox'); |
264 | |
dcc1cc82 |
265 | ?> |