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