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/page_header.php");
17 include("../functions/plugin.php");
18 include("../src/load_prefs.php");
20 // open a connection on the imap port (143)
21 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
25 function formatMailboxName($imapConnection, $box_array, $delimeter) {
26 global $folder_prefix, $trash_folder, $sent_folder;
27 global $color, $move_to_sent, $move_to_trash;
28 global $unseen_notify, $unseen_type, $collapse_folders;
30 $real_box = $box_array['unformatted'];
31 $mailbox = $box_array['formatted'];
32 $mailboxURL = urlencode($real_box);
36 if (($unseen_notify == 2 && $real_box == "INBOX") ||
37 $unseen_notify == 3) {
38 $unseen = sqimap_unseen_messages($imapConnection, $real_box);
39 if ($unseen_type == 1 && $unseen > 0) {
40 $unseen_string = "($unseen)";
42 } else if ($unseen_type == 2) {
43 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
44 $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
49 $special_color = false;
50 if ((strtolower($real_box) == "inbox") ||
51 (($real_box == $trash_folder) && ($move_to_trash)) ||
52 (($real_box == $sent_folder) && ($move_to_sent)))
53 $special_color = true;
57 if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
64 $line .= str_replace(' ', ' ', $spaces);
66 if ($collapse_folders) {
67 if (isset($box_array['parent']))
68 $line .= FoldLink($box_array['unformatted'], $box_array['parent']);
70 $line .= '<tt> </tt> ';
73 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
74 if ($special_color == true)
75 $line .= "<FONT COLOR=\"$color[11]\">";
76 $line .= str_replace(' ', ' ', $mailbox);
77 if ($special_color == true)
84 if (isset($unseen_found) && $unseen_found) {
85 $line .= " <small>$unseen_string</small>";
88 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
89 if (! isset($numMessages))
90 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
94 $urlMailbox = urlencode($real_box);
95 $line .= "\n<small>\n";
96 $line .= " (<B><A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A></B>)";
97 $line .= "\n</small>\n";
104 if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) {
105 echo "<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n";
106 echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";
107 echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n";
110 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
112 do_hook("left_main_before");
114 $boxes = sqimap_mailbox_list($imapConnection);
116 echo "<CENTER><FONT SIZE=4><B>";
117 echo _("Folders") . "</B><BR></FONT>\n\n";
119 echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">";
120 echo _("refresh folder list");
121 echo "</A>)</small></CENTER><BR>";
122 $delimeter = sqimap_get_delimiter($imapConnection);
124 if (isset($collapse_folders) && $collapse_folders) {
126 setPref($data_dir, $username, 'collapse_folder_' . $fold, 1);
128 setPref($data_dir, $username, 'collapse_folder_' . $unfold, 0);
129 $IAmAParent = array();
130 for ($i = 0; $i < count($boxes); $i ++
) {
131 $parts = explode($delimeter, $boxes[$i]['unformatted']);
132 $box_name = array_pop($parts);
133 $box_parent = implode($delimeter, $parts);
135 if (isset($box_parent)) {
136 $hidden = getPref($data_dir, $username,
137 'collapse_folder_' . $box_parent);
138 $IAmAParent[$box_parent] = $hidden;
140 $boxes[$i]['folded'] = $hidden;
144 for ($i = 0;$i < count($boxes); $i++
) {
145 if (! isset($boxes[$i]['folded']) ||
! $boxes[$i]['folded'])
148 $mailbox = $boxes[$i]["formatted"];
150 if (isset($collapse_folders) && $collapse_folders && isset($IAmAParent[$boxes[$i]['unformatted']])) {
151 $boxes[$i]['parent'] = $IAmAParent[$boxes[$i]['unformatted']];
154 if (in_array('noselect', $boxes[$i]['flags'])) {
155 $line .= "<FONT COLOR=\"$color[10]\">";
156 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
157 $line .= str_replace(' ', ' ', $mailbox);
158 if (isset($boxes[$i]['parent']))
159 $line .= FoldLink($boxes[$i]['unformatted'], $boxes[$i]['parent']);
160 elseif ($collapse_folders)
161 $line .= '<tt> </tt> ';
165 $line .= formatMailboxName($imapConnection, $boxes[$i], $delimeter);
170 sqimap_logout($imapConnection);
171 do_hook("left_main_after");
173 function FoldLink($mailbox, $folded) {
174 $mailbox = urlencode($mailbox);
175 echo '<tt><a target="left" style="text-decoration:none" ';
176 echo 'href="left_main.php?';
178 echo "unfold=$mailbox\">+";
180 echo "fold=$mailbox\">-";
181 echo '</a></tt> ';