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 function formatMailboxName($imapConnection, $box_array, $delimeter) {
24 global $folder_prefix, $trash_folder, $sent_folder;
25 global $color, $move_to_sent, $move_to_trash;
26 global $unseen_notify, $unseen_type, $collapse_folders;
28 $real_box = $box_array['unformatted'];
29 $mailbox = $box_array['formatted'];
30 $mailboxURL = urlencode($real_box);
34 if (($unseen_notify == 2 && $real_box == "INBOX") ||
35 $unseen_notify == 3) {
36 $unseen = sqimap_unseen_messages($imapConnection, $real_box);
37 if ($unseen_type == 1 && $unseen > 0) {
38 $unseen_string = "($unseen)";
40 } else if ($unseen_type == 2) {
41 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
42 $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
47 $special_color = false;
48 if ((strtolower($real_box) == "inbox") ||
49 (($real_box == $trash_folder) && ($move_to_trash)) ||
50 (($real_box == $sent_folder) && ($move_to_sent)))
51 $special_color = true;
55 if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
62 $line .= str_replace(' ', ' ', $spaces);
64 if ($collapse_folders) {
65 if (isset($box_array['parent']))
66 $line .= FoldLink($box_array['unformatted'], $box_array['parent']);
68 $line .= '<tt> </tt> ';
71 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
72 if ($special_color == true)
73 $line .= "<FONT COLOR=\"$color[11]\">";
74 $line .= str_replace(' ', ' ', $mailbox);
75 if ($special_color == true)
82 if (isset($unseen_found) && $unseen_found) {
83 $line .= " <small>$unseen_string</small>";
86 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
87 if (! isset($numMessages))
88 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
92 $urlMailbox = urlencode($real_box);
93 $line .= "\n<small>\n";
94 $line .= " (<B><A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A></B>)";
95 $line .= "\n</small>\n";
102 if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) {
103 echo "<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n";
104 echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";
105 echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n";
108 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
110 do_hook("left_main_before");
112 $boxes = sqimap_mailbox_list($imapConnection);
114 echo "<CENTER><FONT SIZE=4><B>";
115 echo _("Folders") . "</B><BR></FONT>\n\n";
117 echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">";
118 echo _("refresh folder list");
119 echo "</A>)</small></CENTER><BR>";
120 $delimeter = sqimap_get_delimiter($imapConnection);
122 if (isset($collapse_folders) && $collapse_folders) {
124 setPref($data_dir, $username, 'collapse_folder_' . $fold, 1);
126 setPref($data_dir, $username, 'collapse_folder_' . $unfold, 0);
127 $IAmAParent = array();
128 for ($i = 0; $i < count($boxes); $i ++
) {
129 $parts = explode($delimeter, $boxes[$i]['unformatted']);
130 $box_name = array_pop($parts);
131 $box_parent = implode($delimeter, $parts);
133 if (isset($box_parent)) {
134 $hidden = getPref($data_dir, $username,
135 'collapse_folder_' . $box_parent);
136 $IAmAParent[$box_parent] = $hidden;
138 $boxes[$i]['folded'] = $hidden;
142 for ($i = 0;$i < count($boxes); $i++
) {
143 if (! isset($boxes[$i]['folded']) ||
! $boxes[$i]['folded'])
146 $mailbox = $boxes[$i]["formatted"];
148 if (isset($collapse_folders) && $collapse_folders && isset($IAmAParent[$boxes[$i]['unformatted']])) {
149 $boxes[$i]['parent'] = $IAmAParent[$boxes[$i]['unformatted']];
152 if (in_array('noselect', $boxes[$i]['flags'])) {
153 $line .= "<FONT COLOR=\"$color[10]\">";
154 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
155 $line .= str_replace(' ', ' ', $mailbox);
156 if (isset($boxes[$i]['parent']))
157 $line .= FoldLink($boxes[$i]['unformatted'], $boxes[$i]['parent']);
158 elseif ($collapse_folders)
159 $line .= '<tt> </tt> ';
163 $line .= formatMailboxName($imapConnection, $boxes[$i], $delimeter);
168 sqimap_logout($imapConnection);
169 do_hook("left_main_after");
171 function FoldLink($mailbox, $folded) {
172 $mailbox = urlencode($mailbox);
173 echo '<tt><a target="left" style="text-decoration:none" ';
174 echo 'href="left_main.php?';
176 echo "unfold=$mailbox\">+";
178 echo "fold=$mailbox\">-";
179 echo '</a></tt> ';