* Added much better support for the mailto stuff
[squirrelmail.git] / src / left_main.php
1 <?php
2 /**
3 ** left_main.php
4 ** Copyright (c) 1999-2000 The SquirrelMail development team
5 ** Licensed under the GNU GPL. For full terms see the file COPYING.
6 **
7 ** This is the code for the left bar. The left bar shows the folders
8 ** available, and has cookie information.
9 **
10 ** $Id$
11 **/
12
13 include('../src/validate.php');
14 include("../functions/array.php");
15 include("../functions/imap.php");
16 include("../functions/plugin.php");
17
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
20
21 displayHtmlHeader();
22
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 }
28 }
29 if (isset ($trash_folder) && $trash_folder != "none") {
30 if (!sqimap_mailbox_exists ($imapConnection, $trash_folder)) {
31 sqimap_mailbox_create ($imapConnection, $trash_folder, "");
32 }
33 }
34 $auto_create_done = true;
35 session_register('auto_create_done');
36 }
37
38 function formatMailboxName($imapConnection, $box_array, $delimeter) {
39 global $folder_prefix, $trash_folder, $sent_folder;
40 global $color, $move_to_sent, $move_to_trash;
41 global $unseen_notify, $unseen_type, $collapse_folders;
42
43 $real_box = $box_array['unformatted'];
44 $mailbox = $box_array['formatted'];
45 $mailboxURL = urlencode($real_box);
46
47 $unseen = 0;
48
49 if (($unseen_notify == 2 && $real_box == "INBOX") ||
50 $unseen_notify == 3) {
51 $unseen = sqimap_unseen_messages($imapConnection, $real_box);
52 if ($unseen_type == 1 && $unseen > 0) {
53 $unseen_string = "($unseen)";
54 $unseen_found = true;
55 } else if ($unseen_type == 2) {
56 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
57 $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
58 $unseen_found = true;
59 }
60 }
61
62 $special_color = false;
63 if ((strtolower($real_box) == "inbox") ||
64 (($real_box == $trash_folder) && ($move_to_trash)) ||
65 (($real_box == $sent_folder) && ($move_to_sent)))
66 $special_color = true;
67
68 $spaces = '';
69 $line = "<NOBR>";
70 if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
71 $spaces = $regs[1];
72 $mailbox = $regs[2];
73 }
74
75 if ($unseen > 0)
76 $line .= "<B>";
77 $line .= str_replace(' ', '&nbsp;', $spaces);
78
79 if ($collapse_folders) {
80 if (isset($box_array['parent']))
81 $line .= FoldLink($box_array['unformatted'], $box_array['parent']);
82 else
83 $line .= '<tt>&nbsp;</tt>&nbsp;';
84 }
85
86 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
87 if ($special_color == true)
88 $line .= "<FONT COLOR=\"$color[11]\">";
89 $line .= str_replace(' ', '&nbsp;', $mailbox);
90 if ($special_color == true)
91 $line .= "</font>";
92 $line .= "</a>";
93
94 if ($unseen > 0)
95 $line .= "</B>";
96
97 if (isset($unseen_found) && $unseen_found) {
98 $line .= "&nbsp;<small>$unseen_string</small>";
99 }
100
101 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
102 if (! isset($numMessages))
103 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
104
105 if ($numMessages > 0)
106 {
107 $urlMailbox = urlencode($real_box);
108 $line .= "\n<small>\n";
109 $line .= " &nbsp; (<B><A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A></B>)";
110 $line .= "\n</small>\n";
111 }
112 }
113 $line .= "</NOBR>";
114 return $line;
115 }
116
117 if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) {
118 echo "<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n";
119 echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";
120 echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n";
121 }
122
123 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
124
125 do_hook("left_main_before");
126
127 $boxes = sqimap_mailbox_list($imapConnection);
128
129 echo "<CENTER><FONT SIZE=4><B>";
130 echo _("Folders") . "</B><BR></FONT>\n\n";
131
132 echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">";
133 echo _("refresh folder list");
134 echo "</A>)</small></CENTER><BR>";
135 $delimeter = sqimap_get_delimiter($imapConnection);
136
137 if (isset($collapse_folders) && $collapse_folders) {
138 if (isset($fold))
139 setPref($data_dir, $username, 'collapse_folder_' . $fold, 1);
140 if (isset($unfold))
141 setPref($data_dir, $username, 'collapse_folder_' . $unfold, 0);
142 $IAmAParent = array();
143 for ($i = 0; $i < count($boxes); $i ++) {
144 $parts = explode($delimeter, $boxes[$i]['unformatted']);
145 $box_name = array_pop($parts);
146 $box_parent = implode($delimeter, $parts);
147 $hidden = 0;
148 if (isset($box_parent)) {
149 $hidden = getPref($data_dir, $username,
150 'collapse_folder_' . $box_parent);
151 $IAmAParent[$box_parent] = $hidden;
152 }
153 $boxes[$i]['folded'] = $hidden;
154 }
155 }
156
157 for ($i = 0;$i < count($boxes); $i++) {
158 if (! isset($boxes[$i]['folded']) || ! $boxes[$i]['folded'])
159 {
160 $line = "";
161 $mailbox = $boxes[$i]["formatted"];
162
163 if (isset($collapse_folders) && $collapse_folders && isset($IAmAParent[$boxes[$i]['unformatted']])) {
164 $boxes[$i]['parent'] = $IAmAParent[$boxes[$i]['unformatted']];
165 }
166
167 if (in_array('noselect', $boxes[$i]['flags'])) {
168 $line .= "<FONT COLOR=\"$color[10]\">";
169 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
170 $line .= str_replace(' ', '&nbsp;', $mailbox);
171 if (isset($boxes[$i]['parent']))
172 $line .= FoldLink($boxes[$i]['unformatted'], $boxes[$i]['parent']);
173 elseif ($collapse_folders)
174 $line .= '<tt>&nbsp;</tt>&nbsp;';
175 }
176 $line .= '</FONT>';
177 } else {
178 $line .= formatMailboxName($imapConnection, $boxes[$i], $delimeter);
179 }
180 echo "$line<BR>\n";
181 }
182 }
183 sqimap_logout($imapConnection);
184 do_hook("left_main_after");
185
186 function FoldLink($mailbox, $folded) {
187 $mailbox = urlencode($mailbox);
188 echo '<tt><a target="left" style="text-decoration:none" ';
189 echo 'href="left_main.php?';
190 if ($folded)
191 echo "unfold=$mailbox\">+";
192 else
193 echo "fold=$mailbox\">-";
194 echo '</a></tt>&nbsp;';
195 }
196
197 ?>
198 </BODY></HTML>