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