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 | |
15 | require_once('../src/validate.php'); |
16 | require_once('../functions/array.php'); |
17 | require_once('../functions/imap.php'); |
18 | require_once('../functions/plugin.php'); |
19 | require_once('../functions/page_header.php'); |
142499d4 |
20 | |
95e93571 |
21 | /* These constants are used for folder stuff. */ |
22 | define('SM_BOX_UNCOLLAPSED', 0); |
23 | define('SM_BOX_COLLAPSED', 1); |
a6d2e0de |
24 | |
2d367c68 |
25 | /* --------------------- FUNCTIONS ------------------------- */ |
525b7ae6 |
26 | |
95e93571 |
27 | function formatMailboxName($imapConnection, $box_array) { |
1c52ba77 |
28 | |
90de1755 |
29 | global $folder_prefix, $trash_folder, $sent_folder, |
30 | $color, $move_to_sent, $move_to_trash, |
31 | $unseen_notify, $unseen_type, $collapse_folders, |
32 | $draft_folder, $save_as_draft, |
33 | $use_special_folder_color; |
94f3a73b |
34 | |
95e93571 |
35 | $real_box = $box_array['unformatted']; |
36 | $mailbox = str_replace(' ','',$box_array['formatted']); |
37 | $mailboxURL = urlencode($real_box); |
21c3249f |
38 | |
95e93571 |
39 | /* Strip down the mailbox name. */ |
40 | if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) { |
41 | $mailbox = $regs[2]; |
42 | } |
94f3a73b |
43 | |
95e93571 |
44 | $unseen = 0; |
45 | |
46 | if (($unseen_notify == 2 && $real_box == 'INBOX') || |
47 | $unseen_notify == 3) { |
48 | $unseen = sqimap_unseen_messages($imapConnection, $real_box); |
49 | if ($unseen_type == 1 && $unseen > 0) { |
50 | $unseen_string = "($unseen)"; |
90de1755 |
51 | $unseen_found = TRUE; |
95e93571 |
52 | } else if ($unseen_type == 2) { |
53 | $numMessages = sqimap_get_num_messages($imapConnection, $real_box); |
54 | $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>"; |
90de1755 |
55 | $unseen_found = TRUE; |
94f3a73b |
56 | } |
95e93571 |
57 | } |
94f3a73b |
58 | |
1c52ba77 |
59 | $special_color = ($use_special_folder_color && isSpecialMailbox( $real_box ) ); |
f7b1b3b1 |
60 | |
95e93571 |
61 | /* Start off with a blank line. */ |
62 | $line = ''; |
235a65d5 |
63 | |
95e93571 |
64 | /* If there are unseen message, bold the line. */ |
65 | if ($unseen > 0) { $line .= '<B>'; } |
a6d2e0de |
66 | |
95e93571 |
67 | /* Crate the link for this folder. */ |
68 | $line .= "<A HREF=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" TARGET=\"right\" STYLE=\"text-decoration:none\">"; |
1c52ba77 |
69 | if ($special_color) { |
95e93571 |
70 | $line .= "<FONT COLOR=\"$color[11]\">"; |
1c52ba77 |
71 | } |
95e93571 |
72 | $line .= str_replace(' ',' ',$mailbox); |
90de1755 |
73 | if ($special_color == TRUE) |
95e93571 |
74 | $line .= "</FONT>"; |
75 | $line .= '</A>'; |
a6d2e0de |
76 | |
95e93571 |
77 | /* If there are unseen message, close bolding. */ |
78 | if ($unseen > 0) { $line .= "</B>"; } |
2d367c68 |
79 | |
95e93571 |
80 | /* Print unseen information. */ |
81 | if (isset($unseen_found) && $unseen_found) { |
82 | $line .= " <SMALL>$unseen_string</SMALL>"; |
2016e645 |
83 | } |
84 | |
1c52ba77 |
85 | if (($move_to_trash) && ($real_box == $trash_folder)) { |
95e93571 |
86 | if (! isset($numMessages)) { |
87 | $numMessages = sqimap_get_num_messages($imapConnection, $real_box); |
a6d2e0de |
88 | } |
a6d2e0de |
89 | |
95e93571 |
90 | if ($numMessages > 0) { |
91 | $urlMailbox = urlencode($real_box); |
92 | $line .= "\n<small>\n" . |
93 | " (<A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("empty")."</A>)" . |
7fb54066 |
94 | "</small>"; |
a6d2e0de |
95 | } |
96 | } |
a6d2e0de |
97 | |
95e93571 |
98 | /* Return the final product. */ |
99 | return ($line); |
100 | } |
a6d2e0de |
101 | |
95e93571 |
102 | /** |
103 | * Recursive function that computes the collapsed status and parent |
104 | * (or not parent) status of this box, and the visiblity and collapsed |
105 | * status and parent (or not parent) status for all children boxes. |
106 | */ |
107 | function compute_folder_children(&$parbox, $boxcount) { |
108 | global $boxes, $data_dir, $username, $collapse_folders; |
109 | $nextbox = $parbox + 1; |
110 | |
111 | /* Retreive the name for the parent box. */ |
112 | $parbox_name = $boxes[$parbox]['unformatted']; |
113 | |
114 | /* 'Initialize' this parent box to childless. */ |
1c52ba77 |
115 | $boxes[$parbox]['parent'] = FALSE; |
95e93571 |
116 | |
117 | /* Compute the collapse status for this box. */ |
118 | if( isset($collapse_folders) && $collapse_folders ) { |
119 | $collapse = getPref($data_dir, $username, 'collapse_folder_' . $parbox_name); |
120 | $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse); |
121 | } else { |
122 | $collapse = SM_BOX_UNCOLLAPSED; |
a6d2e0de |
123 | } |
95e93571 |
124 | $boxes[$parbox]['collapse'] = $collapse; |
2d367c68 |
125 | |
95e93571 |
126 | /* Otherwise, get the name of the next box. */ |
1c52ba77 |
127 | if (isset($boxes[$nextbox]['unformatted'])) { |
95e93571 |
128 | $nextbox_name = $boxes[$nextbox]['unformatted']; |
1c52ba77 |
129 | } else { |
95e93571 |
130 | $nextbox_name = ''; |
1c52ba77 |
131 | } |
a6d2e0de |
132 | |
95e93571 |
133 | /* Compute any children boxes for this box. */ |
134 | while (($nextbox < $boxcount) && |
135 | (is_parent_box($boxes[$nextbox]['unformatted'], $parbox_name))) { |
a6d2e0de |
136 | |
95e93571 |
137 | /* Note that this 'parent' box has at least one child. */ |
1c52ba77 |
138 | $boxes[$parbox]['parent'] = TRUE; |
a6d2e0de |
139 | |
95e93571 |
140 | /* Compute the visiblity of this box. */ |
1c52ba77 |
141 | $boxes[$nextbox]['visible'] = ($boxes[$parbox]['visible'] && |
142 | ($boxes[$parbox]['collapse'] != SM_BOX_COLLAPSED)); |
a6d2e0de |
143 | |
95e93571 |
144 | /* Compute the visibility of any child boxes. */ |
145 | compute_folder_children($nextbox, $boxcount); |
146 | } |
2d367c68 |
147 | |
95e93571 |
148 | /* Set the parent box to the current next box. */ |
149 | $parbox = $nextbox; |
150 | } |
2d367c68 |
151 | |
95e93571 |
152 | /** |
153 | * Create the link for a parent folder that will allow that |
154 | * parent folder to either be collapsed or expaned, as is |
155 | * currently appropriate. |
156 | */ |
157 | function create_collapse_link($boxnum) { |
158 | global $boxes; |
159 | $mailbox = urlencode($boxes[$boxnum]['unformatted']); |
160 | |
161 | /* Create the link for this collapse link. */ |
90de1755 |
162 | $link = '<a target="left" style="text-decoration:none" ' . |
163 | 'href="left_main.php?'; |
95e93571 |
164 | if ($boxes[$boxnum]['collapse'] == SM_BOX_COLLAPSED) { |
165 | $link .= "unfold=$mailbox\">+"; |
2d367c68 |
166 | } else { |
95e93571 |
167 | $link .= "fold=$mailbox\">-"; |
2d367c68 |
168 | } |
95e93571 |
169 | $link .= '</a>'; |
2d367c68 |
170 | |
95e93571 |
171 | /* Return the finished product. */ |
172 | return ($link); |
173 | } |
174 | |
175 | /** |
176 | * This simple function checks if a box is another box's parent. |
177 | */ |
178 | function is_parent_box($curbox_name, $parbox_name) { |
179 | global $delimiter; |
180 | |
181 | /* Extract the name of the parent of the current box. */ |
182 | $curparts = explode($delimiter, $curbox_name); |
183 | $curname = array_pop($curparts); |
184 | $actual_parname = implode($delimiter, $curparts); |
185 | $actual_parname = substr($actual_parname,0,strlen($parbox_name)); |
186 | |
187 | /* Compare the actual with the given parent name. */ |
188 | return ($parbox_name == $actual_parname); |
189 | } |
190 | |
191 | |
192 | /* -------------------- MAIN ------------------------ */ |
193 | |
194 | global $delimiter, $default_folder_prefix; |
195 | |
196 | // open a connection on the imap port (143) |
197 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output |
198 | |
199 | |
200 | if (isset($left_refresh) && ($left_refresh != 'none') && ($left_refresh != '')) { |
201 | $xtra = "\n<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n" . |
202 | "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n". |
203 | "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n"; |
204 | } else { |
205 | $xtra = ''; |
206 | } |
207 | |
208 | displayHtmlHeader( 'SquirrelMail', $xtra ); |
209 | |
210 | /* If requested and not yet complete, attempt to autocreate folders. */ |
211 | if ($auto_create_special && !isset($auto_create_done)) { |
a3439b27 |
212 | $autocreate = array($sent_folder, $trash_folder, $draft_folder); |
95e93571 |
213 | foreach( $autocreate as $folder ) { |
a3439b27 |
214 | if (($folder != '') && ($folder != 'none')) { |
95e93571 |
215 | if ( !sqimap_mailbox_exists($imapConnection, $folder)) { |
216 | sqimap_mailbox_create($imapConnection, $folder, ''); |
a3439b27 |
217 | } else if (!sqimap_mailbox_is_subscribed($imapConnection, $folder)) { |
95e93571 |
218 | sqimap_subscribe($imapConnection, $folder); |
2d367c68 |
219 | } |
ebf18afa |
220 | } |
2d367c68 |
221 | } |
a6d2e0de |
222 | |
95e93571 |
223 | /* Let the world know that autocreation is complete! Hurrah! */ |
90de1755 |
224 | $auto_create_done = TRUE; |
95e93571 |
225 | session_register('auto_create_done'); |
226 | } |
a6d2e0de |
227 | |
95e93571 |
228 | echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n"; |
a6d2e0de |
229 | |
95e93571 |
230 | do_hook('left_main_before'); |
2d367c68 |
231 | |
95e93571 |
232 | $boxes = sqimap_mailbox_list($imapConnection); |
2d367c68 |
233 | |
95e93571 |
234 | echo '<CENTER><FONT SIZE=4><B>'. _("Folders") . "</B><BR></FONT>\n\n"; |
a6d2e0de |
235 | |
95e93571 |
236 | if ($date_format != 6) { |
237 | /* First, display the clock. */ |
238 | if ($hour_format == 1) { |
239 | $hr = 'G:i'; |
240 | if ($date_format == 4) { |
241 | $hr .= ':s'; |
a6d2e0de |
242 | } |
95e93571 |
243 | } else { |
244 | if ($date_format == 4) { |
245 | $hr = 'g:i:s a'; |
246 | } else { |
247 | $hr = 'g:i a'; |
2d367c68 |
248 | } |
249 | } |
250 | |
95e93571 |
251 | switch( $date_format ) { |
252 | case 1: |
253 | $clk = date('m/d/y '.$hr, time()); |
254 | break; |
255 | case 2: |
256 | $clk = date('d/m/y '.$hr, time()); |
257 | break; |
258 | case 4: |
259 | case 5: |
260 | $clk = date($hr, time()); |
261 | break; |
262 | default: |
fc6f062a |
263 | $clk = substr( getDayName( date( 'w', time() ) ), 0, 3 ) . date( ', ' . $hr, time() ); |
2d367c68 |
264 | } |
95e93571 |
265 | $clk = str_replace(' ',' ',$clk); |
266 | |
267 | echo '<CENTER><SMALL>' . str_replace(' ',' ',_("Last Refresh")) . |
268 | ": $clk</SMALL></CENTER>"; |
269 | } |
270 | |
271 | /* Next, display the refresh button. */ |
272 | echo '<SMALL>(<A HREF="../src/left_main.php" TARGET="left">'. |
273 | _("refresh folder list") . '</A>)</SMALL></CENTER><BR>'; |
274 | |
275 | /* Lastly, display the folder list. */ |
276 | if ( $collapse_folders ) { |
277 | /* If directed, collapse or uncollapse a folder. */ |
278 | if (isset($fold)) { |
279 | setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED); |
280 | } else if (isset($unfold)) { |
281 | setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED); |
282 | } |
283 | } |
284 | |
285 | /* Prepare do do out collapsedness and visibility computation. */ |
286 | $curbox = 0; |
287 | $boxcount = count($boxes); |
288 | |
289 | /* Compute the collapsedness and visibility of each box. */ |
90de1755 |
290 | |
95e93571 |
291 | while ($curbox < $boxcount) { |
292 | $boxes[$curbox]['visible'] = TRUE; |
293 | compute_folder_children($curbox, $boxcount); |
294 | } |
295 | |
90de1755 |
296 | |
1c52ba77 |
297 | for ($i = 0; $i < count($boxes); $i++) { |
95e93571 |
298 | if ( $boxes[$i]['visible'] ) { |
299 | $mailbox = $boxes[$i]['formatted']; |
300 | $mblevel = substr_count($boxes[$i]['unformatted'], $delimiter) + 1; |
301 | |
302 | /* Create the prefix for the folder name and link. */ |
303 | $prefix = str_repeat(' ',$mblevel); |
304 | if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) { |
305 | $prefix = str_replace(' ',' ',substr($prefix,0,strlen($prefix)-2)). |
306 | create_collapse_link($i) . ' '; |
307 | } else { |
308 | $prefix = str_replace(' ',' ',$prefix); |
309 | } |
310 | $line = "<NOBR><TT>$prefix</TT>"; |
311 | |
312 | /* Add the folder name and link. */ |
1c52ba77 |
313 | if (! isset($color[15])) { |
05611cba |
314 | $color[15] = $color[6]; |
1c52ba77 |
315 | } |
90de1755 |
316 | |
95e93571 |
317 | if (in_array('noselect', $boxes[$i]['flags'])) { |
1c52ba77 |
318 | if( isSpecialMailbox( $boxes[$i]['unformatted']) ) { |
319 | $line .= "<FONT COLOR=\"$color[11]\">"; |
320 | } else { |
321 | $line .= "<FONT COLOR=\"$color[15]\">"; |
322 | } |
95e93571 |
323 | if (ereg("^( *)([^ ]*)", $mailbox, $regs)) { |
324 | $mailbox = str_replace(' ','',$mailbox); |
325 | $line .= str_replace(' ', ' ', $mailbox); |
2d367c68 |
326 | } |
95e93571 |
327 | $line .= '</FONT>'; |
328 | } else { |
329 | $line .= formatMailboxName($imapConnection, $boxes[$i]); |
330 | } |
2d367c68 |
331 | |
95e93571 |
332 | /* Put the final touches on our folder line. */ |
333 | $line .= "</NOBR><BR>\n"; |
2d367c68 |
334 | |
95e93571 |
335 | /* Output the line for this folder. */ |
336 | echo $line; |
2d367c68 |
337 | } |
95e93571 |
338 | } |
2d367c68 |
339 | |
95e93571 |
340 | sqimap_logout($imapConnection); |
341 | do_hook('left_main_after'); |
2d367c68 |
342 | |
95e93571 |
343 | echo "</BODY></HTML>\n"; |
2d367c68 |
344 | |
7fb54066 |
345 | ?> |