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