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, "");
27 } else if (! sqimap_mailbox_is_subscribed($imapConnection, $sent_folder)) {
28 sqimap_subscribe($imapConnection, $sent_folder);
31 if (isset ($trash_folder) && $trash_folder != "none") {
32 if (!sqimap_mailbox_exists ($imapConnection, $trash_folder)) {
33 sqimap_mailbox_create ($imapConnection, $trash_folder, "");
34 } else if (! sqimap_mailbox_is_subscribed($imapConnection, $trash_folder)) {
35 sqimap_subscribe($imapConnection, $trash_folder);
38 $auto_create_done = true;
39 session_register('auto_create_done');
42 function formatMailboxName($imapConnection, $box_array, $delimeter) {
43 global $folder_prefix, $trash_folder, $sent_folder;
44 global $color, $move_to_sent, $move_to_trash;
45 global $unseen_notify, $unseen_type, $collapse_folders;
47 $real_box = $box_array['unformatted'];
48 $mailbox = $box_array['formatted'];
49 $mailboxURL = urlencode($real_box);
53 if (($unseen_notify == 2 && $real_box == "INBOX") ||
54 $unseen_notify == 3) {
55 $unseen = sqimap_unseen_messages($imapConnection, $real_box);
56 if ($unseen_type == 1 && $unseen > 0) {
57 $unseen_string = "($unseen)";
59 } else if ($unseen_type == 2) {
60 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
61 $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
66 $special_color = false;
67 if ((strtolower($real_box) == "inbox") ||
68 (($real_box == $trash_folder) && ($move_to_trash)) ||
69 (($real_box == $sent_folder) && ($move_to_sent)))
70 $special_color = true;
74 if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
81 $line .= str_replace(' ', ' ', $spaces);
83 if ($collapse_folders) {
84 if (isset($box_array['parent']))
85 $line .= FoldLink($box_array['unformatted'], $box_array['parent']);
87 $line .= '<tt> </tt> ';
90 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
91 if ($special_color == true)
92 $line .= "<FONT COLOR=\"$color[11]\">";
93 $line .= str_replace(' ', ' ', $mailbox);
94 if ($special_color == true)
101 if (isset($unseen_found) && $unseen_found) {
102 $line .= " <small>$unseen_string</small>";
105 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
106 if (! isset($numMessages))
107 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
109 if ($numMessages > 0)
111 $urlMailbox = urlencode($real_box);
112 $line .= "\n<small>\n";
113 $line .= " (<B><A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A></B>)";
114 $line .= "\n</small>\n";
121 if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) {
122 echo "<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n";
123 echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";
124 echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n";
127 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
129 do_hook("left_main_before");
131 $boxes = sqimap_mailbox_list($imapConnection);
133 echo "<CENTER><FONT SIZE=4><B>";
134 echo _("Folders") . "</B><BR></FONT>\n\n";
136 echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">";
137 echo _("refresh folder list");
138 echo "</A>)</small></CENTER><BR>";
139 $delimeter = sqimap_get_delimiter($imapConnection);
141 if (isset($collapse_folders) && $collapse_folders) {
143 setPref($data_dir, $username, 'collapse_folder_' . $fold, 1);
145 setPref($data_dir, $username, 'collapse_folder_' . $unfold, 0);
146 $IAmAParent = array();
147 for ($i = 0; $i < count($boxes); $i ++
) {
148 $parts = explode($delimeter, $boxes[$i]['unformatted']);
149 $box_name = array_pop($parts);
150 $box_parent = implode($delimeter, $parts);
152 if (isset($box_parent)) {
153 $hidden = getPref($data_dir, $username,
154 'collapse_folder_' . $box_parent);
155 $IAmAParent[$box_parent] = $hidden;
157 $boxes[$i]['folded'] = $hidden;
161 for ($i = 0;$i < count($boxes); $i++
) {
162 if (! isset($boxes[$i]['folded']) ||
! $boxes[$i]['folded'])
165 $mailbox = $boxes[$i]["formatted"];
167 if (isset($collapse_folders) && $collapse_folders && isset($IAmAParent[$boxes[$i]['unformatted']])) {
168 $boxes[$i]['parent'] = $IAmAParent[$boxes[$i]['unformatted']];
171 if (in_array('noselect', $boxes[$i]['flags'])) {
172 $line .= "<FONT COLOR=\"$color[10]\">";
173 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
174 $line .= str_replace(' ', ' ', $mailbox);
175 if (isset($boxes[$i]['parent']))
176 $line .= FoldLink($boxes[$i]['unformatted'], $boxes[$i]['parent']);
177 elseif ($collapse_folders)
178 $line .= '<tt> </tt> ';
182 $line .= formatMailboxName($imapConnection, $boxes[$i], $delimeter);
187 sqimap_logout($imapConnection);
188 do_hook("left_main_after");
190 function FoldLink($mailbox, $folded) {
191 $mailbox = urlencode($mailbox);
192 echo '<tt><a target="left" style="text-decoration:none" ';
193 echo 'href="left_main.php?';
195 echo "unfold=$mailbox\">+";
197 echo "fold=$mailbox\">-";
198 echo '</a></tt> ';