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/i18n.php");
15 include("../functions/strings.php");
16 include("../config/config.php");
17 include("../functions/array.php");
18 include("../functions/imap.php");
19 include("../functions/page_header.php");
20 include("../functions/plugin.php");
21 include("../src/load_prefs.php");
23 // open a connection on the imap port (143)
24 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
28 function formatMailboxName($imapConnection, $box_array, $delimeter) {
29 global $folder_prefix, $trash_folder, $sent_folder;
30 global $color, $move_to_sent, $move_to_trash;
31 global $unseen_notify, $unseen_type, $collapse_folders;
33 $real_box = $box_array['unformatted'];
34 $mailbox = $box_array['formatted'];
35 $mailboxURL = urlencode($real_box);
39 if (($unseen_notify == 2 && $real_box == "INBOX") ||
40 $unseen_notify == 3) {
41 $unseen = sqimap_unseen_messages($imapConnection, $numUnseen, $real_box);
42 if ($unseen_type == 1 && $unseen > 0) {
43 $unseen_string = "($unseen)";
45 } else if ($unseen_type == 2) {
46 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
47 $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
52 $special_color = false;
53 if ((strtolower($real_box) == "inbox") ||
54 (($real_box == $trash_folder) && ($move_to_trash)) ||
55 (($real_box == $sent_folder) && ($move_to_sent)))
56 $special_color = true;
60 if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
67 $line .= str_replace(' ', ' ', $spaces);
69 if ($collapse_folders) {
70 if (isset($box_array['parent']))
71 $line .= FoldLink($box_array['unformatted'], $box_array['parent']);
73 $line .= '<tt> </tt> ';
76 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
77 if ($special_color == true)
78 $line .= "<FONT COLOR=\"$color[11]\">";
79 $line .= str_replace(' ', ' ', $mailbox);
80 if ($special_color == true)
87 if (isset($unseen_found) && $unseen_found) {
88 $line .= " <small>$unseen_string</small>";
91 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
92 if (! isset($numMessages))
93 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
97 $urlMailbox = urlencode($real_box);
98 $line .= "\n<small>\n";
99 $line .= " (<B><A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A></B>)";
100 $line .= "\n</small>\n";
107 if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) {
108 echo "<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n";
109 echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";
110 echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n";
113 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
115 do_hook("left_main_before");
117 $boxes = sqimap_mailbox_list($imapConnection);
119 echo "<CENTER><FONT SIZE=4><B>";
120 echo _("Folders") . "</B><BR></FONT>\n\n";
122 echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">";
123 echo _("refresh folder list");
124 echo "</A>)</small></CENTER><BR>";
125 $delimeter = sqimap_get_delimiter($imapConnection);
127 if (isset($collapse_folders) && $collapse_folders) {
129 setPref($data_dir, $username, 'collapse_folder_' . $fold, 1);
131 setPref($data_dir, $username, 'collapse_folder_' . $unfold, 0);
132 $IAmAParent = array();
133 for ($i = 0; $i < count($boxes); $i ++
) {
134 $parts = explode($delimeter, $boxes[$i]['unformatted']);
135 $box_name = array_pop($parts);
136 $box_parent = implode($delimeter, $parts);
138 if (isset($box_parent)) {
139 $hidden = getPref($data_dir, $username,
140 'collapse_folder_' . $box_parent);
141 $IAmAParent[$box_parent] = $hidden;
143 $boxes[$i]['folded'] = $hidden;
147 for ($i = 0;$i < count($boxes); $i++
) {
148 if (! isset($boxes[$i]['folded']) ||
! $boxes[$i]['folded'])
151 $mailbox = $boxes[$i]["formatted"];
153 if (isset($collapse_folders) && $collapse_folders && isset($IAmAParent[$boxes[$i]['unformatted']])) {
154 $boxes[$i]['parent'] = $IAmAParent[$boxes[$i]['unformatted']];
157 if (in_array('noselect', $boxes[$i]['flags'])) {
158 $line .= "<FONT COLOR=\"$color[10]\">";
159 if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
160 $line .= str_replace(' ', ' ', $regs[1]);
161 if (isset($boxes[$i]['parent']))
162 $line .= FoldLink($boxes[$i]['unformatted'],
163 $boxes[$i]['parent']);
164 elseif ($collapse_folders)
165 $line .= '<tt> </tt> ';
166 $line .= str_replace(' ', ' ', $regs[2]);
170 $line .= formatMailboxName($imapConnection, $boxes[$i], $delimeter);
175 sqimap_logout($imapConnection);
176 do_hook("left_main_after");
178 function FoldLink($mailbox, $folded) {
179 $mailbox = urlencode($mailbox);
180 echo '<tt><a target="left" style="text-decoration:none" ';
181 echo 'href="left_main.php?';
183 echo "unfold=$mailbox\">+";
185 echo "fold=$mailbox\">-";
186 echo '</a></tt> ';