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