729460ebde622357beadab1b9cadeb8421d272f4
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 $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, "");
29 sqimap_subscribe($imapConnection, $sent_folder);
32 if (isset ($trash_folder) && $trash_folder != "none") {
33 if (!sqimap_mailbox_exists ($imapConnection, $trash_folder)) {
34 sqimap_mailbox_create ($imapConnection, $trash_folder, "");
36 sqimap_subscribe($imapConnection, $trash_folder);
39 $auto_create_done = true;
40 session_register('auto_create_done');
41 setPref($data_dir, $username, 'auto_create_done', TRUE);
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;
49 $real_box = $box_array['unformatted'];
50 $mailbox = $box_array['formatted'];
51 $mailboxURL = urlencode($real_box);
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)";
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>";
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;
76 if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
83 $line .= str_replace(' ', ' ', $spaces);
85 if ($collapse_folders) {
86 if (isset($box_array['parent']))
87 $line .= FoldLink($box_array['unformatted'], $box_array['parent']);
89 $line .= '<tt> </tt> ';
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(' ', ' ', $mailbox);
96 if ($special_color == true)
103 if (isset($unseen_found) && $unseen_found) {
104 $line .= " <small>$unseen_string</small>";
107 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
108 if (! isset($numMessages))
109 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
111 if ($numMessages > 0)
113 $urlMailbox = urlencode($real_box);
114 $line .= "\n<small>\n";
115 $line .= " (<B><A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A></B>)";
116 $line .= "\n</small>\n";
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";
129 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
131 do_hook("left_main_before");
133 $boxes = sqimap_mailbox_list($imapConnection);
135 echo "<CENTER><FONT SIZE=4><B>";
136 echo _("Folders") . "</B><BR></FONT>\n\n";
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);
143 if (isset($collapse_folders) && $collapse_folders) {
145 setPref($data_dir, $username, 'collapse_folder_' . $fold, 1);
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);
154 if (isset($box_parent)) {
155 $hidden = getPref($data_dir, $username,
156 'collapse_folder_' . $box_parent);
157 $IAmAParent[$box_parent] = $hidden;
159 $boxes[$i]['folded'] = $hidden;
163 for ($i = 0;$i < count($boxes); $i++
) {
164 if (! isset($boxes[$i]['folded']) ||
! $boxes[$i]['folded'])
167 $mailbox = $boxes[$i]["formatted"];
169 if (isset($collapse_folders) && $collapse_folders && isset($IAmAParent[$boxes[$i]['unformatted']])) {
170 $boxes[$i]['parent'] = $IAmAParent[$boxes[$i]['unformatted']];
173 if (in_array('noselect', $boxes[$i]['flags'])) {
174 $line .= "<FONT COLOR=\"$color[10]\">";
175 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
176 $line .= str_replace(' ', ' ', $mailbox);
177 if (isset($boxes[$i]['parent']))
178 $line .= FoldLink($boxes[$i]['unformatted'], $boxes[$i]['parent']);
179 elseif ($collapse_folders)
180 $line .= '<tt> </tt> ';
184 $line .= formatMailboxName($imapConnection, $boxes[$i], $delimeter);
189 sqimap_logout($imapConnection);
190 do_hook("left_main_after");
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?';
197 echo "unfold=$mailbox\">+";
199 echo "fold=$mailbox\">-";
200 echo '</a></tt> ';