59177427 |
1 | <?php |
21c3249f |
2 | /** |
a09387f4 |
3 | ** left_main.php |
ef870322 |
4 | ** Copyright (c) 1999-2000 The SquirrelMail development team |
5 | ** Licensed under the GNU GPL. For full terms see the file COPYING. |
21c3249f |
6 | ** |
7 | ** This is the code for the left bar. The left bar shows the folders |
8 | ** available, and has cookie information. |
9 | ** |
245a6892 |
10 | ** $Id$ |
21c3249f |
11 | **/ |
12 | |
f740c049 |
13 | include('../src/validate.php'); |
f740c049 |
14 | include("../functions/array.php"); |
15 | include("../functions/imap.php"); |
f740c049 |
16 | include("../functions/plugin.php"); |
142499d4 |
17 | |
99ab0367 |
18 | // open a connection on the imap port (143) |
19 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output |
f7bfc9de |
20 | |
2a833d72 |
21 | displayHtmlHeader(); |
21c3249f |
22 | |
7a906c8e |
23 | if ($auto_create_special && ! isset($auto_create_done)) { |
f7bfc9de |
24 | if (isset ($sent_folder) && $sent_folder != "none") { |
25 | if (!sqimap_mailbox_exists ($imapConnection, $sent_folder)) { |
26 | sqimap_mailbox_create ($imapConnection, $sent_folder, ""); |
27 | } |
28 | } |
29 | if (isset ($trash_folder) && $trash_folder != "none") { |
30 | if (!sqimap_mailbox_exists ($imapConnection, $trash_folder)) { |
31 | sqimap_mailbox_create ($imapConnection, $trash_folder, ""); |
32 | } |
33 | } |
7a906c8e |
34 | $auto_create_done = true; |
35 | session_register('auto_create_done'); |
f7bfc9de |
36 | } |
37 | |
235a65d5 |
38 | function formatMailboxName($imapConnection, $box_array, $delimeter) { |
5bdd7223 |
39 | global $folder_prefix, $trash_folder, $sent_folder; |
40 | global $color, $move_to_sent, $move_to_trash; |
235a65d5 |
41 | global $unseen_notify, $unseen_type, $collapse_folders; |
42 | |
43 | $real_box = $box_array['unformatted']; |
44 | $mailbox = $box_array['formatted']; |
5c42b0dd |
45 | $mailboxURL = urlencode($real_box); |
0cd84d75 |
46 | |
235a65d5 |
47 | $unseen = 0; |
4d2c01e3 |
48 | |
235a65d5 |
49 | if (($unseen_notify == 2 && $real_box == "INBOX") || |
50 | $unseen_notify == 3) { |
4d2c01e3 |
51 | $unseen = sqimap_unseen_messages($imapConnection, $real_box); |
24fc5dd2 |
52 | if ($unseen_type == 1 && $unseen > 0) { |
53 | $unseen_string = "($unseen)"; |
54 | $unseen_found = true; |
55 | } else if ($unseen_type == 2) { |
56 | $numMessages = sqimap_get_num_messages($imapConnection, $real_box); |
57 | $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>"; |
58 | $unseen_found = true; |
59 | } |
60 | } |
5bdd7223 |
61 | |
7ce342dc |
62 | $special_color = false; |
508ca2d3 |
63 | if ((strtolower($real_box) == "inbox") || |
235a65d5 |
64 | (($real_box == $trash_folder) && ($move_to_trash)) || |
65 | (($real_box == $sent_folder) && ($move_to_sent))) |
66 | $special_color = true; |
67 | |
68 | $spaces = ''; |
69 | $line = "<NOBR>"; |
70 | if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) { |
71 | $spaces = $regs[1]; |
72 | $mailbox = $regs[2]; |
73 | } |
5bdd7223 |
74 | |
235a65d5 |
75 | if ($unseen > 0) |
76 | $line .= "<B>"; |
77 | $line .= str_replace(' ', ' ', $spaces); |
78 | |
79 | if ($collapse_folders) { |
80 | if (isset($box_array['parent'])) |
81 | $line .= FoldLink($box_array['unformatted'], $box_array['parent']); |
82 | else |
83 | $line .= '<tt> </tt> '; |
d92b6f31 |
84 | } |
235a65d5 |
85 | |
86 | $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">"; |
87 | if ($special_color == true) |
88 | $line .= "<FONT COLOR=\"$color[11]\">"; |
89 | $line .= str_replace(' ', ' ', $mailbox); |
90 | if ($special_color == true) |
91 | $line .= "</font>"; |
92 | $line .= "</a>"; |
7ce342dc |
93 | |
d1941f35 |
94 | if ($unseen > 0) |
7ce342dc |
95 | $line .= "</B>"; |
235a65d5 |
96 | |
245a6892 |
97 | if (isset($unseen_found) && $unseen_found) { |
24fc5dd2 |
98 | $line .= " <small>$unseen_string</small>"; |
7ce342dc |
99 | } |
100 | |
1e0628fb |
101 | if (($move_to_trash == true) && ($real_box == $trash_folder)) { |
b4cf620b |
102 | if (! isset($numMessages)) |
103 | $numMessages = sqimap_get_num_messages($imapConnection, $real_box); |
104 | |
105 | if ($numMessages > 0) |
12d61439 |
106 | { |
b4cf620b |
107 | $urlMailbox = urlencode($real_box); |
108 | $line .= "\n<small>\n"; |
109 | $line .= " (<B><A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A></B>)"; |
110 | $line .= "\n</small>\n"; |
12d61439 |
111 | } |
d92b6f31 |
112 | } |
1d4fe45e |
113 | $line .= "</NOBR>"; |
d92b6f31 |
114 | return $line; |
115 | } |
116 | |
4c34dac5 |
117 | if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) { |
1d4fe45e |
118 | echo "<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n"; |
119 | echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"; |
120 | echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n"; |
469eb37b |
121 | } |
813eba2f |
122 | |
04632dbc |
123 | echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n"; |
f3d17401 |
124 | |
9d0c7bee |
125 | do_hook("left_main_before"); |
126 | |
813eba2f |
127 | $boxes = sqimap_mailbox_list($imapConnection); |
21c3249f |
128 | |
1d4fe45e |
129 | echo "<CENTER><FONT SIZE=4><B>"; |
130 | echo _("Folders") . "</B><BR></FONT>\n\n"; |
97afcee9 |
131 | |
9f2215a1 |
132 | echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">"; |
ad6f805c |
133 | echo _("refresh folder list"); |
aae41ae9 |
134 | echo "</A>)</small></CENTER><BR>"; |
813eba2f |
135 | $delimeter = sqimap_get_delimiter($imapConnection); |
4c34dac5 |
136 | |
235a65d5 |
137 | if (isset($collapse_folders) && $collapse_folders) { |
138 | if (isset($fold)) |
139 | setPref($data_dir, $username, 'collapse_folder_' . $fold, 1); |
140 | if (isset($unfold)) |
141 | setPref($data_dir, $username, 'collapse_folder_' . $unfold, 0); |
142 | $IAmAParent = array(); |
143 | for ($i = 0; $i < count($boxes); $i ++) { |
144 | $parts = explode($delimeter, $boxes[$i]['unformatted']); |
145 | $box_name = array_pop($parts); |
146 | $box_parent = implode($delimeter, $parts); |
147 | $hidden = 0; |
148 | if (isset($box_parent)) { |
149 | $hidden = getPref($data_dir, $username, |
150 | 'collapse_folder_' . $box_parent); |
151 | $IAmAParent[$box_parent] = $hidden; |
152 | } |
153 | $boxes[$i]['folded'] = $hidden; |
154 | } |
155 | } |
156 | |
7ce342dc |
157 | for ($i = 0;$i < count($boxes); $i++) { |
235a65d5 |
158 | if (! isset($boxes[$i]['folded']) || ! $boxes[$i]['folded']) |
159 | { |
160 | $line = ""; |
161 | $mailbox = $boxes[$i]["formatted"]; |
162 | |
163 | if (isset($collapse_folders) && $collapse_folders && isset($IAmAParent[$boxes[$i]['unformatted']])) { |
164 | $boxes[$i]['parent'] = $IAmAParent[$boxes[$i]['unformatted']]; |
165 | } |
166 | |
167 | if (in_array('noselect', $boxes[$i]['flags'])) { |
168 | $line .= "<FONT COLOR=\"$color[10]\">"; |
12d61439 |
169 | if (ereg("^( *)([^ ]*)", $mailbox, $regs)) { |
170 | $line .= str_replace(' ', ' ', $mailbox); |
7161db62 |
171 | if (isset($boxes[$i]['parent'])) |
12d61439 |
172 | $line .= FoldLink($boxes[$i]['unformatted'], $boxes[$i]['parent']); |
7161db62 |
173 | elseif ($collapse_folders) |
174 | $line .= '<tt> </tt> '; |
235a65d5 |
175 | } |
176 | $line .= '</FONT>'; |
177 | } else { |
178 | $line .= formatMailboxName($imapConnection, $boxes[$i], $delimeter); |
179 | } |
180 | echo "$line<BR>\n"; |
d92b6f31 |
181 | } |
d92b6f31 |
182 | } |
1195c340 |
183 | sqimap_logout($imapConnection); |
6b638171 |
184 | do_hook("left_main_after"); |
235a65d5 |
185 | |
186 | function FoldLink($mailbox, $folded) { |
187 | $mailbox = urlencode($mailbox); |
188 | echo '<tt><a target="left" style="text-decoration:none" '; |
189 | echo 'href="left_main.php?'; |
190 | if ($folded) |
191 | echo "unfold=$mailbox\">+"; |
192 | else |
193 | echo "fold=$mailbox\">-"; |
194 | echo '</a></tt> '; |
195 | } |
196 | |
21c3249f |
197 | ?> |
aae41ae9 |
198 | </BODY></HTML> |