59177427 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * left_main.php |
5 | * |
15e6162e |
6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * This is the code for the left bar. The left bar shows the folders |
10 | * available, and has cookie information. |
11 | * |
12 | * $Id$ |
1c52ba77 |
13 | */ |
35586184 |
14 | |
86725763 |
15 | /* Path for SquirrelMail required files. */ |
16 | define('SM_PATH','../'); |
17 | |
18 | /* SquirrelMail required files. */ |
08185f2a |
19 | require_once(SM_PATH . 'include/validate.php'); |
86725763 |
20 | require_once(SM_PATH . 'functions/array.php'); |
21 | require_once(SM_PATH . 'functions/imap.php'); |
22 | require_once(SM_PATH . 'functions/plugin.php'); |
23 | require_once(SM_PATH . 'functions/page_header.php'); |
24 | require_once(SM_PATH . 'functions/html.php'); |
142499d4 |
25 | |
95e93571 |
26 | /* These constants are used for folder stuff. */ |
27 | define('SM_BOX_UNCOLLAPSED', 0); |
28 | define('SM_BOX_COLLAPSED', 1); |
a6d2e0de |
29 | |
2d367c68 |
30 | /* --------------------- FUNCTIONS ------------------------- */ |
525b7ae6 |
31 | |
95e93571 |
32 | function formatMailboxName($imapConnection, $box_array) { |
1c52ba77 |
33 | |
90de1755 |
34 | global $folder_prefix, $trash_folder, $sent_folder, |
35 | $color, $move_to_sent, $move_to_trash, |
36 | $unseen_notify, $unseen_type, $collapse_folders, |
37 | $draft_folder, $save_as_draft, |
38 | $use_special_folder_color; |
94f3a73b |
39 | |
95e93571 |
40 | $real_box = $box_array['unformatted']; |
41 | $mailbox = str_replace(' ','',$box_array['formatted']); |
42 | $mailboxURL = urlencode($real_box); |
21c3249f |
43 | |
95e93571 |
44 | /* Strip down the mailbox name. */ |
45 | if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) { |
46 | $mailbox = $regs[2]; |
47 | } |
474fc5fa |
48 | $status = create_unseen_string($real_box, $box_array, $imapConnection); |
49 | if ($status !== false) { |
50 | list($unseen_string, $unseen) = $status; |
51 | } else { |
52 | list($unseen_string, $unseen) = array(_("Not available"),''); |
53 | } |
ffb1a3d9 |
54 | $special_color = ($use_special_folder_color && isSpecialMailbox($real_box)); |
f7b1b3b1 |
55 | |
95e93571 |
56 | /* Start off with a blank line. */ |
57 | $line = ''; |
235a65d5 |
58 | |
95e93571 |
59 | /* If there are unseen message, bold the line. */ |
60 | if ($unseen > 0) { $line .= '<B>'; } |
a6d2e0de |
61 | |
fb0ca797 |
62 | /* Create the link for this folder. */ |
474fc5fa |
63 | if ($status !== false) { |
64 | $line .= '<a href="right_main.php?PG_SHOWALL=0&sort=0&startMessage=1&mailbox='. |
65 | $mailboxURL.'" TARGET="right" STYLE="text-decoration:none">'; |
66 | } |
1c52ba77 |
67 | if ($special_color) { |
3fde693b |
68 | $line .= "<font color=\"$color[11]\">"; |
1c52ba77 |
69 | } |
a551489c |
70 | if ( $mailbox == 'INBOX' ) { |
71 | $line .= _("INBOX"); |
72 | } else { |
73 | $line .= str_replace(' ',' ',$mailbox); |
74 | } |
90de1755 |
75 | if ($special_color == TRUE) |
3fde693b |
76 | $line .= '</font>'; |
474fc5fa |
77 | if ($status !== false) { |
78 | $line .= '</a>'; |
79 | } |
a6d2e0de |
80 | |
95e93571 |
81 | /* If there are unseen message, close bolding. */ |
82 | if ($unseen > 0) { $line .= "</B>"; } |
2d367c68 |
83 | |
95e93571 |
84 | /* Print unseen information. */ |
ffb1a3d9 |
85 | if ($unseen_string != '') { |
95e93571 |
86 | $line .= " <SMALL>$unseen_string</SMALL>"; |
2016e645 |
87 | } |
88 | |
1c52ba77 |
89 | if (($move_to_trash) && ($real_box == $trash_folder)) { |
95e93571 |
90 | if (! isset($numMessages)) { |
91 | $numMessages = sqimap_get_num_messages($imapConnection, $real_box); |
a6d2e0de |
92 | } |
a6d2e0de |
93 | |
95e93571 |
94 | if ($numMessages > 0) { |
95 | $urlMailbox = urlencode($real_box); |
96 | $line .= "\n<small>\n" . |
eb3b5319 |
97 | " (<A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A>)" . |
7fb54066 |
98 | "</small>"; |
a6d2e0de |
99 | } |
100 | } |
a6d2e0de |
101 | |
95e93571 |
102 | /* Return the final product. */ |
103 | return ($line); |
104 | } |
a6d2e0de |
105 | |
95e93571 |
106 | /** |
107 | * Recursive function that computes the collapsed status and parent |
108 | * (or not parent) status of this box, and the visiblity and collapsed |
109 | * status and parent (or not parent) status for all children boxes. |
110 | */ |
111 | function compute_folder_children(&$parbox, $boxcount) { |
112 | global $boxes, $data_dir, $username, $collapse_folders; |
113 | $nextbox = $parbox + 1; |
114 | |
115 | /* Retreive the name for the parent box. */ |
116 | $parbox_name = $boxes[$parbox]['unformatted']; |
117 | |
118 | /* 'Initialize' this parent box to childless. */ |
1c52ba77 |
119 | $boxes[$parbox]['parent'] = FALSE; |
95e93571 |
120 | |
121 | /* Compute the collapse status for this box. */ |
122 | if( isset($collapse_folders) && $collapse_folders ) { |
123 | $collapse = getPref($data_dir, $username, 'collapse_folder_' . $parbox_name); |
124 | $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse); |
125 | } else { |
126 | $collapse = SM_BOX_UNCOLLAPSED; |
a6d2e0de |
127 | } |
95e93571 |
128 | $boxes[$parbox]['collapse'] = $collapse; |
2d367c68 |
129 | |
95e93571 |
130 | /* Otherwise, get the name of the next box. */ |
1c52ba77 |
131 | if (isset($boxes[$nextbox]['unformatted'])) { |
95e93571 |
132 | $nextbox_name = $boxes[$nextbox]['unformatted']; |
1c52ba77 |
133 | } else { |
95e93571 |
134 | $nextbox_name = ''; |
1c52ba77 |
135 | } |
a6d2e0de |
136 | |
95e93571 |
137 | /* Compute any children boxes for this box. */ |
138 | while (($nextbox < $boxcount) && |
139 | (is_parent_box($boxes[$nextbox]['unformatted'], $parbox_name))) { |
a6d2e0de |
140 | |
95e93571 |
141 | /* Note that this 'parent' box has at least one child. */ |
1c52ba77 |
142 | $boxes[$parbox]['parent'] = TRUE; |
a6d2e0de |
143 | |
95e93571 |
144 | /* Compute the visiblity of this box. */ |
1c52ba77 |
145 | $boxes[$nextbox]['visible'] = ($boxes[$parbox]['visible'] && |
146 | ($boxes[$parbox]['collapse'] != SM_BOX_COLLAPSED)); |
a6d2e0de |
147 | |
95e93571 |
148 | /* Compute the visibility of any child boxes. */ |
149 | compute_folder_children($nextbox, $boxcount); |
150 | } |
2d367c68 |
151 | |
95e93571 |
152 | /* Set the parent box to the current next box. */ |
153 | $parbox = $nextbox; |
154 | } |
2d367c68 |
155 | |
95e93571 |
156 | /** |
157 | * Create the link for a parent folder that will allow that |
158 | * parent folder to either be collapsed or expaned, as is |
159 | * currently appropriate. |
160 | */ |
161 | function create_collapse_link($boxnum) { |
70bf5a7f |
162 | global $boxes, $imapConnection, $unseen_notify, $color; |
95e93571 |
163 | $mailbox = urlencode($boxes[$boxnum]['unformatted']); |
70bf5a7f |
164 | |
95e93571 |
165 | /* Create the link for this collapse link. */ |
90de1755 |
166 | $link = '<a target="left" style="text-decoration:none" ' . |
167 | 'href="left_main.php?'; |
95e93571 |
168 | if ($boxes[$boxnum]['collapse'] == SM_BOX_COLLAPSED) { |
ffb1a3d9 |
169 | $link .= "unfold=$mailbox\">+"; |
170 | } else { |
171 | $link .= "fold=$mailbox\">-"; |
172 | } |
173 | $link .= '</a>'; |
174 | |
175 | /* Return the finished product. */ |
176 | return ($link); |
177 | } |
178 | |
179 | /** |
180 | * create_unseen_string: |
181 | * |
182 | * Create unseen and total message count for both this folder and |
183 | * it's subfolders. |
184 | * |
185 | * @param string $boxName name of the current mailbox |
186 | * @param array $boxArray array for the current mailbox |
187 | * @param $imapConnection current imap connection in use |
188 | * @return array[0] unseen message string (for display) |
189 | * @return array[1] unseen message count |
190 | */ |
191 | function create_unseen_string($boxName, $boxArray, $imapConnection) { |
474fc5fa |
192 | global $boxes, $unseen_type, $color, $unseen_cum; |
ffb1a3d9 |
193 | |
194 | /* Initialize the return value. */ |
0210ab4d |
195 | $result = array(0,0); |
ffb1a3d9 |
196 | |
197 | /* Initialize the counts for this folder. */ |
198 | $boxUnseenCount = 0; |
199 | $boxMessageCount = 0; |
200 | $totalUnseenCount = 0; |
201 | $totalMessageCount = 0; |
202 | |
203 | /* Collect the counts for this box alone. */ |
474fc5fa |
204 | $status = sqimap_status_messages($imapConnection, $boxName); |
205 | $boxUnseenCount = $status['UNSEEN']; |
206 | if ($boxUnseenCount === false) { |
207 | return false; |
208 | } |
ffb1a3d9 |
209 | if ($unseen_type == 2) { |
474fc5fa |
210 | $boxMessageCount = $status['MESSAGES']; |
ffb1a3d9 |
211 | } |
70bf5a7f |
212 | |
22986991 |
213 | /* Initialize the total counts. */ |
214 | |
474fc5fa |
215 | if ($boxArray['collapse'] == SM_BOX_COLLAPSED && $unseen_cum) { |
ffb1a3d9 |
216 | /* Collect the counts for this boxes subfolders. */ |
217 | $curBoxLength = strlen($boxName); |
218 | $boxCount = count($boxes); |
22986991 |
219 | |
ffb1a3d9 |
220 | for ($i = 0; $i < $boxCount; ++$i) { |
221 | /* Initialize the counts for this subfolder. */ |
222 | $subUnseenCount = 0; |
223 | $subMessageCount = 0; |
224 | |
225 | /* Collect the counts for this subfolder. */ |
226 | if (($boxName != $boxes[$i]['unformatted']) |
227 | && (substr($boxes[$i]['unformatted'], 0, $curBoxLength) == $boxName) |
228 | && !in_array('noselect', $boxes[$i]['flags'])) { |
474fc5fa |
229 | $status = sqimap_status_messages($imapConnection, $boxes[$i]['unformatted']); |
230 | $subUnseenCount = $status['UNSEEN']; |
ffb1a3d9 |
231 | if ($unseen_type == 2) { |
474fc5fa |
232 | $subMessageCount = $status['MESSAGES'];; |
70bf5a7f |
233 | } |
22986991 |
234 | /* Add the counts for this subfolder to the total. */ |
235 | $totalUnseenCount += $subUnseenCount; |
236 | $totalMessageCount += $subMessageCount; |
237 | } |
70bf5a7f |
238 | } |
22986991 |
239 | |
240 | /* Add the counts for all subfolders to that of the box. */ |
241 | $boxUnseenCount += $totalUnseenCount; |
242 | $boxMessageCount += $totalMessageCount; |
ffb1a3d9 |
243 | } |
244 | |
245 | /* And create the magic unseen count string. */ |
246 | /* Really a lot more then just the unseen count. */ |
247 | if (($unseen_type == 1) && ($boxUnseenCount > 0)) { |
22986991 |
248 | $result[0] = "($boxUnseenCount)"; |
ffb1a3d9 |
249 | } else if ($unseen_type == 2) { |
22986991 |
250 | $result[0] = "($boxUnseenCount/$boxMessageCount)"; |
ffb1a3d9 |
251 | $result[0] = "<font color=\"$color[11]\">$result[0]</font>"; |
70bf5a7f |
252 | } |
ffb1a3d9 |
253 | |
22986991 |
254 | /* Set the unseen count to return to the outside world. */ |
ffb1a3d9 |
255 | $result[1] = $boxUnseenCount; |
2d367c68 |
256 | |
ffb1a3d9 |
257 | /* Return our happy result. */ |
258 | return ($result); |
95e93571 |
259 | } |
260 | |
261 | /** |
262 | * This simple function checks if a box is another box's parent. |
263 | */ |
264 | function is_parent_box($curbox_name, $parbox_name) { |
265 | global $delimiter; |
266 | |
267 | /* Extract the name of the parent of the current box. */ |
268 | $curparts = explode($delimiter, $curbox_name); |
269 | $curname = array_pop($curparts); |
270 | $actual_parname = implode($delimiter, $curparts); |
271 | $actual_parname = substr($actual_parname,0,strlen($parbox_name)); |
272 | |
273 | /* Compare the actual with the given parent name. */ |
274 | return ($parbox_name == $actual_parname); |
275 | } |
276 | |
f23f6a3a |
277 | function listBoxes ($boxes, $j=0 ) { |
278 | global $data_dir, $username, $startmessage, $color, $unseen_notify, $unseen_type, |
279 | $move_to_trash, $trash_folder, $collapse_folders; |
280 | $pre = ''; |
281 | $end = ''; |
282 | $collapse = false; |
283 | if ($boxes) { |
284 | $mailbox = $boxes->mailboxname_full; |
285 | $leader = ''; |
286 | for ($k = 0; $k < $j; $k++) { |
287 | $leader.= '   '; |
288 | } |
289 | $mailboxURL = urlencode($mailbox); |
290 | |
291 | /* get unseen/total messages information */ |
292 | if ($boxes->unseen) { |
293 | $unseen = $boxes->unseen; |
294 | $unseen_string = "($unseen)"; |
295 | if ($unseen>0) $unseen_found = TRUE; |
296 | if ($boxes->total) { |
297 | $numMessages = $boxes->total; |
298 | $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>"; |
299 | } |
300 | } else $unseen = 0; |
301 | |
302 | |
303 | |
304 | if (isset($boxes->mbxs[0]) && $collapse_folders) { |
305 | $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox); |
306 | $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse); |
307 | |
308 | $link = '<a target="left" style="text-decoration:none" ' .'href="left_main.php?'; |
309 | if ($collapse) { |
310 | $link .= "unfold=$mailboxURL\">$leader + "; |
311 | } else { |
312 | $link .= "fold=$mailboxURL\">$leader - "; |
313 | } |
314 | $link .= '</a>'; |
315 | $pre .= $link; |
316 | } else { |
317 | $pre.= $leader . '   '; |
318 | } |
319 | |
320 | |
321 | /* If there are unseen message, bold the line. */ |
322 | if ($unseen > 0) { $pre .= '<B>'; } |
323 | |
324 | if (($move_to_trash) && ($mailbox == $trash_folder)) { |
325 | if (! isset($numMessages)) { |
474fc5fa |
326 | $status = sqimap_status_messages($imapConnection, $mailbox); |
327 | $numMessages = $status['MESSAGES']; |
f23f6a3a |
328 | } |
329 | |
330 | if ($numMessages > 0) { |
331 | $urlMailbox = urlencode($mailbox); |
332 | $pre .= "\n<small>\n" . |
333 | " (<A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A>)" . |
334 | "</small>"; |
335 | } |
336 | } else { |
337 | if (!$boxes->is_noselect) { |
c8fa94cf |
338 | $pre .= "<a HREF=\"right_main.php?PG_SHOWALL=0&sort=0&startMessage=1&mailbox=$mailboxURL\" TARGET=\"right\">"; |
f23f6a3a |
339 | $end .= '</a>'; |
340 | } |
341 | } |
342 | |
343 | /* If there are unseen message, close bolding. */ |
344 | if ($unseen > 0) { $end .= "</B>"; } |
345 | |
346 | /* Print unseen information. */ |
347 | if (isset($unseen_found) && $unseen_found) { |
348 | $end .= " <SMALL>$unseen_string</SMALL>"; |
349 | } |
350 | |
351 | $font = ''; |
352 | $fontend = ''; |
353 | if ($boxes->is_special) { |
354 | $font = "<FONT COLOR=\"$color[11]\">"; |
355 | $fontend = "</FONT>"; |
356 | } |
357 | |
358 | if (!$boxes->is_root) { |
359 | echo "" . $pre .$font. $boxes->mailboxname_sub .$fontend . $end. '<br>'; |
360 | $j++; |
361 | } |
362 | if (!$collapse || $boxes->is_root) { |
363 | for ($i = 0; $i <count($boxes->mbxs); $i++) { |
364 | listBoxes($boxes->mbxs[$i],$j); |
365 | } |
366 | } |
367 | |
368 | } |
369 | } |
370 | |
c8fa94cf |
371 | function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) { |
f23f6a3a |
372 | global $data_dir, $username, $startmessage, $color, $unseen_notify, $unseen_type, |
373 | $move_to_trash, $trash_folder, $collapse_folders; |
374 | |
375 | /* use_folder_images only works if the images exist in ../images */ |
c8fa94cf |
376 | $use_folder_images = true; |
f23f6a3a |
377 | |
378 | $pre = ''; |
379 | $end = ''; |
380 | $collapse = false; |
381 | |
382 | if ($boxes) { |
383 | $mailbox = $boxes->mailboxname_full; |
384 | $mailboxURL = urlencode($mailbox); |
385 | |
386 | /* get unseen/total messages information */ |
387 | if ($boxes->unseen) { |
388 | $unseen = $boxes->unseen; |
389 | $unseen_string = "($unseen)"; |
390 | if ($unseen>0) $unseen_found = TRUE; |
391 | if ($boxes->total) { |
392 | $numMessages = $boxes->total; |
393 | $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>"; |
394 | } |
395 | } else $unseen = 0; |
396 | |
f23f6a3a |
397 | /* If there are unseen message, bold the line. */ |
398 | if ($unseen > 0) { $pre .= '<B>'; } |
399 | |
c8fa94cf |
400 | /* color special boxes */ |
401 | if ($boxes->is_special) { |
402 | $pre .= "<FONT COLOR=\"$color[11]\">"; |
403 | $end .= "</FONT>"; |
404 | } |
405 | |
406 | /* If there are unseen message, close bolding. */ |
407 | if ($unseen > 0) { $end .= "</B>"; } |
408 | |
409 | /* Print unseen information. */ |
410 | if (isset($unseen_found) && $unseen_found) { |
411 | $end .= " $unseen_string"; |
412 | } |
413 | |
f23f6a3a |
414 | if (($move_to_trash) && ($mailbox == $trash_folder)) { |
415 | if (! isset($numMessages)) { |
416 | $numMessages = $boxes->total; |
417 | } |
418 | if ($numMessages > 0) { |
419 | $urlMailbox = urlencode($mailbox); |
420 | $pre .= "\n<small>\n" . |
c8fa94cf |
421 | " (<a class=\"mbx_link\" HREF=\"empty_trash.php\">"._("purge")."</a>)" . |
f23f6a3a |
422 | "</small>"; |
423 | } |
424 | } else { |
425 | if (!$boxes->is_noselect) { /* \Noselect boxes can't be selected */ |
c8fa94cf |
426 | $pre .= "<a class=\"mbx_link\" HREF=\"right_main.php?PG_SHOWALL=0&sort=0&startMessage=1&mailbox=$mailboxURL\" TARGET=\"right\">"; |
f23f6a3a |
427 | $end .= '</a>'; |
428 | } |
429 | } |
430 | |
f23f6a3a |
431 | if (!$boxes->is_root) { |
432 | if ($use_folder_images) { |
433 | if ($boxes->is_inbox) { |
434 | $folder_img = '../images/inbox.gif'; |
435 | } else if ($boxes->is_sent) { |
436 | $folder_img = '../images/senti.gif'; |
437 | } else if ($boxes->is_trash) { |
438 | $folder_img = '../images/delitem.gif'; |
439 | } else if ($boxes->is_draft) { |
440 | $folder_img = '../images/draft.gif'; |
441 | } else $folder_img = '../images/folder.gif'; |
c8fa94cf |
442 | $folder_img = ' <img src="'.$folder_img.'" height="15" valign="center"> '; |
f23f6a3a |
443 | } else $folder_img = ''; |
444 | if (!isset($boxes->mbxs[0])) { |
3fde693b |
445 | echo ' ' . html_tag( 'div', |
c8fa94cf |
446 | $pre . $folder_img . $boxes->mailboxname_sub . $end , |
447 | 'left', '', 'class="mbx_sub" id="' .$j. '"' ) |
3fde693b |
448 | . "\n"; |
f23f6a3a |
449 | } else { |
450 | /* get collapse information */ |
451 | if ($collapse_folders) { |
452 | $link = '<a target="left" style="text-decoration:none" ' .'href="left_main.php?'; |
453 | $form_entry = $j.'F'; |
454 | if (isset($mbx) && isset($mbx[$form_entry])) { |
455 | $collapse = $mbx[$form_entry]; |
456 | if ($collapse) { |
457 | setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full , SM_BOX_COLLAPSED); |
458 | } else { |
459 | setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full , SM_BOX_UNCOLLAPSED); |
460 | } |
461 | } else { |
462 | $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox); |
463 | $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse); |
464 | } |
465 | if ($collapse) { |
599038d5 |
466 | $link = '<a href="javascript:void(0)">'." <img src=\"../images/plus.gif\" border=\"1\" id=$j onclick=\"hidechilds(this)\"></A>"; |
f23f6a3a |
467 | } else { |
599038d5 |
468 | $link = '<a href="javascript:void(0)">'."<img src=\"../images/minus.gif\" border=\"1\" id=$j onclick=\"hidechilds(this)\"></a>"; |
f23f6a3a |
469 | } |
470 | $collapse_link = $link; |
471 | } else $collapse_link=''; |
3fde693b |
472 | echo ' ' . html_tag( 'div', |
c8fa94cf |
473 | $collapse_link . $pre . $folder_img . ' '. $boxes->mailboxname_sub . $end , |
474 | 'left', '', 'class="mbx_par" id="' .$j. 'P"' ) |
3fde693b |
475 | . "\n"; |
c8fa94cf |
476 | echo ' <INPUT TYPE="hidden" name=mbx['.$j. 'F] value="'.$collapse.'" id="mbx['.$j.'F]">'."\n"; |
f23f6a3a |
477 | } |
478 | } |
479 | if ($collapse) { |
480 | $visible = ' STYLE="display:none;"'; |
481 | } else { |
386e556f |
482 | $visible = ' STYLE="display:block;"'; |
f23f6a3a |
483 | } |
484 | |
485 | if (isset($boxes->mbxs[0]) && !$boxes->is_root) /* mailbox contains childs */ |
c8fa94cf |
486 | echo html_tag( 'div', '', 'left', '', 'class="par_area" id='.$j.'.0000 '. $visible ) . "\n"; |
3fde693b |
487 | |
c8fa94cf |
488 | if ($j !='ID.0000') { |
489 | $j = $j .'.0000'; |
f23f6a3a |
490 | } |
491 | for ($i = 0; $i <count($boxes->mbxs); $i++) { |
492 | $j++; |
493 | listAdvancedBoxes($boxes->mbxs[$i],$mbx,$j); |
494 | } |
495 | if (isset($boxes->mbxs[0]) && !$boxes->is_root ) echo '</div>'."\n\n"; |
496 | } |
497 | } |
498 | |
499 | |
500 | |
95e93571 |
501 | |
502 | /* -------------------- MAIN ------------------------ */ |
503 | |
a32985a5 |
504 | $key = $_COOKIE['key']; |
505 | $onetimepad = $_SESSION['onetimepad']; |
506 | $username = $_SESSION['username']; |
507 | $delimiter = $_SESSION['delimiter']; |
508 | |
509 | if (isset($_GET['fold'])) { |
510 | $fold = $_GET['fold']; |
511 | } |
512 | if (isset($_GET['unfold'])) { |
513 | $unfold = $_GET['unfold']; |
514 | } |
95e93571 |
515 | |
516 | // open a connection on the imap port (143) |
517 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output |
518 | |
f43c35f8 |
519 | /** |
520 | * Using stristr since older preferences may contain "None" and "none". |
521 | */ |
522 | if (isset($left_refresh) && ($left_refresh != '') && |
523 | !stristr($left_refresh, "none")){ |
95e93571 |
524 | $xtra = "\n<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n" . |
525 | "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n". |
526 | "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n"; |
527 | } else { |
528 | $xtra = ''; |
529 | } |
530 | |
f23f6a3a |
531 | /** |
532 | * $advanced_tree and $oldway are boolean vars which are default set to default |
533 | * SM behaviour. |
534 | * Setting $oldway to false causes left_main.php to use the new experimental |
535 | * way of getting the mailbox-tree. |
536 | * Setting $advanced tree to true causes SM to display a experimental |
537 | * mailbox-tree with dhtml behaviour. |
538 | * It only works on browsers which supports css and javascript. The used |
539 | * javascript is experimental and doesn't support all browsers. It is tested on |
540 | * IE6 an Konquerer 3.0.0-2. |
541 | * In the function ListAdvancedBoxes there is another var $use_folder_images. |
542 | * setting this to true is only usefull if the images exists in ../images. |
543 | * |
544 | * Feel free to experiment with the code and report bugs and enhancements |
545 | * to marc@its-projects.nl |
546 | **/ |
547 | |
548 | $advanced_tree = false; /* set this to true if you want to see a nicer mailboxtree */ |
549 | $oldway = true; /* default SM behaviour */ |
550 | |
551 | if ($advanced_tree) { |
552 | $xtra .= <<<ECHO |
599038d5 |
553 | <script language="Javascript" TYPE="text/javascript"> |
f23f6a3a |
554 | |
599038d5 |
555 | <!-- |
f23f6a3a |
556 | |
557 | function hidechilds(el) { |
c8fa94cf |
558 | id = el.id+".0000"; |
f23f6a3a |
559 | form_id = "mbx[" + el.id +"F]"; |
560 | if (document.all) { |
561 | ele = document.all[id]; |
599038d5 |
562 | if (ele) { |
563 | if(ele.style.display == "none") { |
564 | ele.style.display = "block"; |
565 | ele.style.visibility = "visible" |
c8fa94cf |
566 | el.src="../images/minus.gif"; |
599038d5 |
567 | document.all[form_id].value=0; |
568 | } else { |
569 | ele.style.display = "none"; |
570 | ele.style.visibility = "hidden" |
c8fa94cf |
571 | el.src="../images/plus.gif"; |
599038d5 |
572 | document.all[form_id].value=1; |
573 | } |
f23f6a3a |
574 | } |
575 | } else if (document.getElementById) { |
f23f6a3a |
576 | ele = document.getElementById(id); |
599038d5 |
577 | if (ele) { |
578 | if(ele.style.display == "none") { |
579 | ele.style.display = "block"; |
580 | ele.style.visibility = "visible" |
c8fa94cf |
581 | el.src="../images/minus.gif"; |
599038d5 |
582 | document.getElementById(form_id).value=0; |
583 | } else { |
584 | ele.style.display = "none"; |
585 | ele.style.visibility = "hidden" |
c8fa94cf |
586 | el.src="../images/plus.gif"; |
599038d5 |
587 | document.getElementById(form_id).value=1; |
588 | } |
589 | } |
f23f6a3a |
590 | } |
591 | } |
592 | |
593 | function preload() { |
594 | if (!document.images) return; |
595 | var ar = new Array(); |
596 | var arguments = preload.arguments; |
597 | for (var i = 0; i<arguments.length; i++) { |
598 | ar[i] = new Image(); |
599 | ar[i].src = arguments[i]; |
600 | } |
601 | } |
602 | |
f23f6a3a |
603 | function buttonover(el,on) { |
604 | if (!on) { |
605 | el.style.borderColor="blue";} |
606 | else { |
607 | el.style.borderColor="orange";} |
608 | } |
609 | |
610 | function buttonclick(el,on) { |
611 | if (!on) { |
612 | el.style.border="groove"} |
613 | else { |
614 | el.style.border="ridge";} |
615 | } |
599038d5 |
616 | |
617 | function hideframe(hide) { |
618 | |
619 | ECHO; |
620 | $xtra .= " left_size = \"$left_size\";\n"; |
621 | $xtra .= <<<ECHO |
622 | if (document.all) { |
623 | masterf = window.parent.document.all["fs1"]; |
624 | leftf = window.parent.document.all["left"]; |
625 | leftcontent = document.all["leftframe"]; |
626 | leftbutton = document.all["showf"]; |
627 | } else if (document.getElementById) { |
628 | masterf = window.parent.document.getElementById("fs1"); |
629 | leftf = window.parent.document.getElementById("left"); |
386e556f |
630 | leftcontent = document.getElementById("leftframe"); |
631 | leftbutton = document.getElementById("showf"); |
599038d5 |
632 | } else { |
633 | return false; |
634 | } |
635 | if(hide) { |
636 | new_col = calc_col("20"); |
637 | masterf.cols = new_col; |
638 | document.body.scrollLeft=0; |
639 | document.body.style.overflow='hidden'; |
640 | leftcontent.style.display = 'none'; |
641 | leftbutton.style.display='block'; |
642 | } else { |
643 | masterf.cols = calc_col(left_size); |
644 | document.body.style.overflow=''; |
645 | leftbutton.style.display='none'; |
646 | leftcontent.style.display='block'; |
647 | |
648 | } |
649 | } |
650 | |
651 | function calc_col(c_w) { |
652 | |
653 | ECHO; |
654 | if ($location_of_bar == 'right') { |
655 | $xtra .= ' right=true;'; |
656 | } else { |
657 | $xtra .= ' right=false;'; |
658 | } |
659 | $xtra .= "\n"; |
660 | $xtra .= <<<ECHO |
661 | if (right) { |
662 | new_col = '*,'+c_w; |
663 | } else { |
664 | new_col = c_w+',*'; |
665 | } |
666 | return new_col; |
667 | } |
668 | |
669 | function resizeframe(direction) { |
670 | if (document.all) { |
671 | masterf = window.parent.document.all["fs1"]; |
672 | } else if (document.getElementById) { |
673 | window.parent.document.getElementById("fs1"); |
674 | } else { |
675 | return false; |
676 | } |
677 | |
678 | ECHO; |
679 | if ($location_of_bar == 'right') { |
680 | $xtra .= ' colPat=/^\*,(\d+)$/;'; |
681 | } else { |
682 | $xtra .= ' colPat=/^(\d+),.*$/;'; |
683 | } |
684 | $xtra .= "\n"; |
685 | |
686 | $xtra .= <<<ECHO |
687 | old_col = masterf.cols; |
688 | colPat.exec(old_col); |
689 | |
690 | if (direction) { |
691 | new_col_width = parseInt(RegExp.$1) + 25; |
692 | |
693 | } else { |
694 | if (parseInt(RegExp.$1) > 35) { |
695 | new_col_width = parseInt(RegExp.$1) - 25; |
696 | } |
697 | } |
698 | masterf.cols = calc_col(new_col_width); |
699 | } |
700 | |
701 | //--> |
f23f6a3a |
702 | |
703 | </script> |
704 | |
705 | ECHO; |
706 | |
707 | /* style definitions */ |
386e556f |
708 | |
f23f6a3a |
709 | $xtra .= <<<ECHO |
710 | |
c8fa94cf |
711 | <STYLE TYPE="text/css"> |
f23f6a3a |
712 | <!-- |
599038d5 |
713 | body { |
714 | margin: 0px 0px 0px 0px; |
715 | padding: 5px 5px 5px 5px; |
716 | } |
c8fa94cf |
717 | |
f23f6a3a |
718 | .button { |
719 | border:outset; |
720 | border-color:blue; |
599038d5 |
721 | background:white; |
f23f6a3a |
722 | width:99%; |
723 | heigth:99%; |
724 | } |
725 | |
726 | .mbx_par { |
f23f6a3a |
727 | font-size:0.8em; |
599038d5 |
728 | margin-left:4px; |
729 | margin-right:0px; |
c8fa94cf |
730 | } |
599038d5 |
731 | |
c8fa94cf |
732 | a.mbx_link { |
733 | text-decoration: none; |
734 | background-color: $color[0]; |
735 | display: inline; |
736 | } |
737 | |
738 | a:hover.mbx_link { |
739 | background-color: $color[9]; |
740 | } |
741 | |
742 | a.mbx_link img { |
743 | border-style: none; |
f23f6a3a |
744 | } |
745 | |
746 | .mbx_sub { |
f23f6a3a |
747 | padding-left:5px; |
599038d5 |
748 | padding-right:0px; |
f23f6a3a |
749 | margin-left:4px; |
599038d5 |
750 | margin-right:0px; |
f23f6a3a |
751 | font-size:0.7em; |
752 | } |
753 | |
754 | .par_area { |
599038d5 |
755 | margin-top:0px; |
756 | margin-left:4px; |
757 | margin-right:0px; |
f23f6a3a |
758 | padding-left:10px; |
599038d5 |
759 | padding-bottom:5px; |
f23f6a3a |
760 | border-left: solid; |
761 | border-left-width:0.1em; |
762 | border-left-color:blue; |
763 | border-bottom: solid; |
764 | border-bottom-width:0.1em; |
765 | border-bottom-color:blue; |
c8fa94cf |
766 | display: block; |
f23f6a3a |
767 | } |
768 | |
769 | .mailboxes { |
f23f6a3a |
770 | padding-bottom:3px; |
599038d5 |
771 | margin-right:4px; |
772 | padding-right:4px; |
773 | margin-left:4px; |
774 | padding-left:4px; |
f23f6a3a |
775 | border: groove; |
776 | border-width:0.1em; |
777 | border-color:green; |
c8fa94cf |
778 | background: $color[0]; |
f23f6a3a |
779 | } |
780 | |
781 | --> |
782 | |
783 | </STYLE> |
784 | |
785 | ECHO; |
786 | |
787 | } |
788 | |
789 | |
790 | |
791 | |
95e93571 |
792 | displayHtmlHeader( 'SquirrelMail', $xtra ); |
793 | |
794 | /* If requested and not yet complete, attempt to autocreate folders. */ |
795 | if ($auto_create_special && !isset($auto_create_done)) { |
a3439b27 |
796 | $autocreate = array($sent_folder, $trash_folder, $draft_folder); |
95e93571 |
797 | foreach( $autocreate as $folder ) { |
a3439b27 |
798 | if (($folder != '') && ($folder != 'none')) { |
95e93571 |
799 | if ( !sqimap_mailbox_exists($imapConnection, $folder)) { |
800 | sqimap_mailbox_create($imapConnection, $folder, ''); |
a3439b27 |
801 | } else if (!sqimap_mailbox_is_subscribed($imapConnection, $folder)) { |
95e93571 |
802 | sqimap_subscribe($imapConnection, $folder); |
2d367c68 |
803 | } |
ebf18afa |
804 | } |
2d367c68 |
805 | } |
a6d2e0de |
806 | |
95e93571 |
807 | /* Let the world know that autocreation is complete! Hurrah! */ |
90de1755 |
808 | $auto_create_done = TRUE; |
a32985a5 |
809 | sqsession_register($auto_create_done, 'auto_create_done'); |
95e93571 |
810 | } |
a6d2e0de |
811 | |
95e93571 |
812 | echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n"; |
a6d2e0de |
813 | |
95e93571 |
814 | do_hook('left_main_before'); |
1053f1e5 |
815 | if ($advanced_tree) { |
599038d5 |
816 | /* nice future feature, needs layout !! volunteers? */ |
817 | $right_pos = $left_size - 20; |
818 | echo '<div style="position:absolute;top:0;border=solid;border-width:0.1em;border-color:blue;"><div ID="hidef" style="width=20;font-size:12"><A HREF="javascript:hideframe(true)"><b><<</b></a></div>'; |
819 | echo '<div ID="showf" style="width=20;font-size:12;display:none;"><A HREF="javascript:hideframe(false)"><b>>></b></a></div>'; |
820 | echo '<div ID="incrf" style="width=20;font-size:12"><A HREF="javascript:resizeframe(true)"><b>></b></a></div>'; |
821 | echo '<div ID="decrf" style="width=20;font-size:12"><A HREF="javascript:resizeframe(false)"><b><</b></a></div></div>'; |
822 | echo '<div ID="leftframe"><br><br>'; |
823 | } |
2d367c68 |
824 | |
ee5b92f2 |
825 | echo "\n\n" . html_tag( 'table', '', 'left', '', 'border="0" cellspacing="0" cellpadding="0" width="99%"' ) . |
3fde693b |
826 | html_tag( 'tr' ) . |
827 | html_tag( 'td', '', 'left' ) . |
828 | '<center><font size="4"><b>'. _("Folders") . "</b><br></font>\n\n"; |
a6d2e0de |
829 | |
95e93571 |
830 | if ($date_format != 6) { |
831 | /* First, display the clock. */ |
832 | if ($hour_format == 1) { |
833 | $hr = 'G:i'; |
834 | if ($date_format == 4) { |
835 | $hr .= ':s'; |
a6d2e0de |
836 | } |
95e93571 |
837 | } else { |
838 | if ($date_format == 4) { |
839 | $hr = 'g:i:s a'; |
840 | } else { |
841 | $hr = 'g:i a'; |
2d367c68 |
842 | } |
843 | } |
844 | |
95e93571 |
845 | switch( $date_format ) { |
846 | case 1: |
847 | $clk = date('m/d/y '.$hr, time()); |
848 | break; |
849 | case 2: |
850 | $clk = date('d/m/y '.$hr, time()); |
851 | break; |
852 | case 4: |
853 | case 5: |
854 | $clk = date($hr, time()); |
855 | break; |
856 | default: |
fc6f062a |
857 | $clk = substr( getDayName( date( 'w', time() ) ), 0, 3 ) . date( ', ' . $hr, time() ); |
2d367c68 |
858 | } |
95e93571 |
859 | $clk = str_replace(' ',' ',$clk); |
860 | |
3fde693b |
861 | echo '<center><small>' . str_replace(' ',' ',_("Last Refresh")) . |
862 | ": $clk</small></center>"; |
95e93571 |
863 | } |
864 | |
865 | /* Next, display the refresh button. */ |
3fde693b |
866 | echo '<small>(<a href="../src/left_main.php" target="left">'. |
867 | _("refresh folder list") . '</a>)</small></center><br>'; |
95e93571 |
868 | |
869 | /* Lastly, display the folder list. */ |
870 | if ( $collapse_folders ) { |
871 | /* If directed, collapse or uncollapse a folder. */ |
872 | if (isset($fold)) { |
873 | setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED); |
874 | } else if (isset($unfold)) { |
875 | setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED); |
876 | } |
877 | } |
878 | |
f23f6a3a |
879 | if ($oldway) { /* normal behaviour SM */ |
880 | |
881 | $boxes = sqimap_mailbox_list($imapConnection); |
95e93571 |
882 | /* Prepare do do out collapsedness and visibility computation. */ |
883 | $curbox = 0; |
884 | $boxcount = count($boxes); |
885 | |
886 | /* Compute the collapsedness and visibility of each box. */ |
90de1755 |
887 | |
95e93571 |
888 | while ($curbox < $boxcount) { |
889 | $boxes[$curbox]['visible'] = TRUE; |
890 | compute_folder_children($curbox, $boxcount); |
891 | } |
892 | |
90de1755 |
893 | |
1c52ba77 |
894 | for ($i = 0; $i < count($boxes); $i++) { |
95e93571 |
895 | if ( $boxes[$i]['visible'] ) { |
896 | $mailbox = $boxes[$i]['formatted']; |
897 | $mblevel = substr_count($boxes[$i]['unformatted'], $delimiter) + 1; |
898 | |
899 | /* Create the prefix for the folder name and link. */ |
900 | $prefix = str_repeat(' ',$mblevel); |
901 | if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) { |
902 | $prefix = str_replace(' ',' ',substr($prefix,0,strlen($prefix)-2)). |
903 | create_collapse_link($i) . ' '; |
904 | } else { |
905 | $prefix = str_replace(' ',' ',$prefix); |
906 | } |
907 | $line = "<NOBR><TT>$prefix</TT>"; |
908 | |
909 | /* Add the folder name and link. */ |
1c52ba77 |
910 | if (! isset($color[15])) { |
05611cba |
911 | $color[15] = $color[6]; |
1c52ba77 |
912 | } |
90de1755 |
913 | |
95e93571 |
914 | if (in_array('noselect', $boxes[$i]['flags'])) { |
1c52ba77 |
915 | if( isSpecialMailbox( $boxes[$i]['unformatted']) ) { |
916 | $line .= "<FONT COLOR=\"$color[11]\">"; |
917 | } else { |
918 | $line .= "<FONT COLOR=\"$color[15]\">"; |
919 | } |
95e93571 |
920 | if (ereg("^( *)([^ ]*)", $mailbox, $regs)) { |
921 | $mailbox = str_replace(' ','',$mailbox); |
922 | $line .= str_replace(' ', ' ', $mailbox); |
2d367c68 |
923 | } |
95e93571 |
924 | $line .= '</FONT>'; |
925 | } else { |
926 | $line .= formatMailboxName($imapConnection, $boxes[$i]); |
927 | } |
2d367c68 |
928 | |
95e93571 |
929 | /* Put the final touches on our folder line. */ |
930 | $line .= "</NOBR><BR>\n"; |
2d367c68 |
931 | |
95e93571 |
932 | /* Output the line for this folder. */ |
933 | echo $line; |
2d367c68 |
934 | } |
95e93571 |
935 | } |
f23f6a3a |
936 | } else { /* expiremental code */ |
937 | $boxes = sqimap_mailbox_tree($imapConnection); |
938 | if (isset($advanced_tree) && $advanced_tree) { |
939 | echo '<FORM name=collapse action="left_main.php" METHOD=POST' . |
940 | 'ENCTYPE="multipart/form-data"'."\n"; |
941 | echo '<small><button type="submit" class="button" onmouseover="buttonover(this,true)" onmouseout="buttonover(this,false)" onmousedown="buttonclick(this,true)" onmouseup="buttonclick(this,false)">'. _("Save folder tree") .'</button><br><br>'; |
942 | echo '<DIV ID=mailboxes CLASS=mailboxes>'."\n\n"; |
943 | if (!isset($mbx)) $mbx=NULL; |
944 | ListAdvancedBoxes($boxes, $mbx); |
945 | echo '</div></small>'."\n"; |
946 | echo '</FORM>'."\n"; |
947 | } else { |
948 | ListBoxes($boxes); |
949 | } |
950 | } /* if ($oldway) else ... */ |
95e93571 |
951 | do_hook('left_main_after'); |
76b684a5 |
952 | sqimap_logout($imapConnection); |
2d367c68 |
953 | |
3fde693b |
954 | echo '</td></tr></table>' . "\n". |
955 | "</div></body></html>\n"; |
2d367c68 |
956 | |
7fb54066 |
957 | ?> |