729460ebde622357beadab1b9cadeb8421d272f4
[squirrelmail.git] / src / left_main.php
1 <?php
2 /**
3 ** left_main.php
4 ** Copyright (c) 1999-2000 The SquirrelMail development team
5 ** Licensed under the GNU GPL. For full terms see the file COPYING.
6 **
7 ** This is the code for the left bar. The left bar shows the folders
8 ** available, and has cookie information.
9 **
10 ** $Id$
11 **/
12
13 include('../src/validate.php');
14 include("../functions/array.php");
15 include("../functions/imap.php");
16 include("../functions/plugin.php");
17
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
20
21 displayHtmlHeader();
22
23 $auto_create_done = getPref($data_dir, $username, 'auto_create_done');
24 if ($auto_create_special && ! isset($auto_create_done)) {
25 if (isset ($sent_folder) && $sent_folder != "none") {
26 if (!sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
27 sqimap_mailbox_create ($imapConnection, $sent_folder, "");
28 } else {
29 sqimap_subscribe($imapConnection, $sent_folder);
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, "");
35 } else {
36 sqimap_subscribe($imapConnection, $trash_folder);
37 }
38 }
39 $auto_create_done = true;
40 session_register('auto_create_done');
41 setPref($data_dir, $username, 'auto_create_done', TRUE);
42 }
43
44 function formatMailboxName($imapConnection, $box_array, $delimeter) {
45 global $folder_prefix, $trash_folder, $sent_folder;
46 global $color, $move_to_sent, $move_to_trash;
47 global $unseen_notify, $unseen_type, $collapse_folders;
48
49 $real_box = $box_array['unformatted'];
50 $mailbox = $box_array['formatted'];
51 $mailboxURL = urlencode($real_box);
52
53 $unseen = 0;
54
55 if (($unseen_notify == 2 && $real_box == "INBOX") ||
56 $unseen_notify == 3) {
57 $unseen = sqimap_unseen_messages($imapConnection, $real_box);
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 }
67
68 $special_color = false;
69 if ((strtolower($real_box) == "inbox") ||
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 }
80
81 if ($unseen > 0)
82 $line .= "<B>";
83 $line .= str_replace(' ', '&nbsp;', $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>&nbsp;</tt>&nbsp;';
90 }
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(' ', '&nbsp;', $mailbox);
96 if ($special_color == true)
97 $line .= "</font>";
98 $line .= "</a>";
99
100 if ($unseen > 0)
101 $line .= "</B>";
102
103 if (isset($unseen_found) && $unseen_found) {
104 $line .= "&nbsp;<small>$unseen_string</small>";
105 }
106
107 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
108 if (! isset($numMessages))
109 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
110
111 if ($numMessages > 0)
112 {
113 $urlMailbox = urlencode($real_box);
114 $line .= "\n<small>\n";
115 $line .= " &nbsp; (<B><A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A></B>)";
116 $line .= "\n</small>\n";
117 }
118 }
119 $line .= "</NOBR>";
120 return $line;
121 }
122
123 if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) {
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";
127 }
128
129 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
130
131 do_hook("left_main_before");
132
133 $boxes = sqimap_mailbox_list($imapConnection);
134
135 echo "<CENTER><FONT SIZE=4><B>";
136 echo _("Folders") . "</B><BR></FONT>\n\n";
137
138 echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">";
139 echo _("refresh folder list");
140 echo "</A>)</small></CENTER><BR>";
141 $delimeter = sqimap_get_delimiter($imapConnection);
142
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
163 for ($i = 0;$i < count($boxes); $i++) {
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]\">";
175 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
176 $line .= str_replace(' ', '&nbsp;', $mailbox);
177 if (isset($boxes[$i]['parent']))
178 $line .= FoldLink($boxes[$i]['unformatted'], $boxes[$i]['parent']);
179 elseif ($collapse_folders)
180 $line .= '<tt>&nbsp;</tt>&nbsp;';
181 }
182 $line .= '</FONT>';
183 } else {
184 $line .= formatMailboxName($imapConnection, $boxes[$i], $delimeter);
185 }
186 echo "$line<BR>\n";
187 }
188 }
189 sqimap_logout($imapConnection);
190 do_hook("left_main_after");
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>&nbsp;';
201 }
202
203 ?>
204 </BODY></HTML>