4 ** Copyright (c) 1999-2000 The SquirrelMail development team
5 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 ** This is the code for the left bar. The left bar shows the folders
8 ** available, and has cookie information.
13 include('../src/validate.php');
14 include("../functions/array.php");
15 include("../functions/imap.php");
16 include("../functions/plugin.php");
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
23 if ($auto_create_special && ! isset($auto_create_done)) {
24 if (isset ($sent_folder) && $sent_folder != "none") {
25 if (!sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
26 sqimap_mailbox_create ($imapConnection, $sent_folder, "");
29 if (isset ($trash_folder) && $trash_folder != "none") {
30 if (!sqimap_mailbox_exists ($imapConnection, $trash_folder)) {
31 sqimap_mailbox_create ($imapConnection, $trash_folder, "");
34 $auto_create_done = true;
35 session_register('auto_create_done');
38 function formatMailboxName($imapConnection, $box_array, $delimeter) {
39 global $folder_prefix, $trash_folder, $sent_folder;
40 global $color, $move_to_sent, $move_to_trash;
41 global $unseen_notify, $unseen_type, $collapse_folders;
43 $real_box = $box_array['unformatted'];
44 $mailbox = $box_array['formatted'];
45 $mailboxURL = urlencode($real_box);
49 if (($unseen_notify == 2 && $real_box == "INBOX") ||
50 $unseen_notify == 3) {
51 $unseen = sqimap_unseen_messages($imapConnection, $real_box);
52 if ($unseen_type == 1 && $unseen > 0) {
53 $unseen_string = "($unseen)";
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>";
62 $special_color = false;
63 if ((strtolower($real_box) == "inbox") ||
64 (($real_box == $trash_folder) && ($move_to_trash)) ||
65 (($real_box == $sent_folder) && ($move_to_sent)))
66 $special_color = true;
70 if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
77 $line .= str_replace(' ', ' ', $spaces);
79 if ($collapse_folders) {
80 if (isset($box_array['parent']))
81 $line .= FoldLink($box_array['unformatted'], $box_array['parent']);
83 $line .= '<tt> </tt> ';
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)
97 if (isset($unseen_found) && $unseen_found) {
98 $line .= " <small>$unseen_string</small>";
101 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
102 if (! isset($numMessages))
103 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
105 if ($numMessages > 0)
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";
117 if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) {
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";
123 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
125 do_hook("left_main_before");
127 $boxes = sqimap_mailbox_list($imapConnection);
129 echo "<CENTER><FONT SIZE=4><B>";
130 echo _("Folders") . "</B><BR></FONT>\n\n";
132 echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">";
133 echo _("refresh folder list");
134 echo "</A>)</small></CENTER><BR>";
135 $delimeter = sqimap_get_delimiter($imapConnection);
137 if (isset($collapse_folders) && $collapse_folders) {
139 setPref($data_dir, $username, 'collapse_folder_' . $fold, 1);
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);
148 if (isset($box_parent)) {
149 $hidden = getPref($data_dir, $username,
150 'collapse_folder_' . $box_parent);
151 $IAmAParent[$box_parent] = $hidden;
153 $boxes[$i]['folded'] = $hidden;
157 for ($i = 0;$i < count($boxes); $i++
) {
158 if (! isset($boxes[$i]['folded']) ||
! $boxes[$i]['folded'])
161 $mailbox = $boxes[$i]["formatted"];
163 if (isset($collapse_folders) && $collapse_folders && isset($IAmAParent[$boxes[$i]['unformatted']])) {
164 $boxes[$i]['parent'] = $IAmAParent[$boxes[$i]['unformatted']];
167 if (in_array('noselect', $boxes[$i]['flags'])) {
168 $line .= "<FONT COLOR=\"$color[10]\">";
169 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
170 $line .= str_replace(' ', ' ', $mailbox);
171 if (isset($boxes[$i]['parent']))
172 $line .= FoldLink($boxes[$i]['unformatted'], $boxes[$i]['parent']);
173 elseif ($collapse_folders)
174 $line .= '<tt> </tt> ';
178 $line .= formatMailboxName($imapConnection, $boxes[$i], $delimeter);
183 sqimap_logout($imapConnection);
184 do_hook("left_main_after");
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?';
191 echo "unfold=$mailbox\">+";
193 echo "fold=$mailbox\">-";
194 echo '</a></tt> ';