a674eaaf75f793a1bbc545f825bd3deaeb3244fd
[squirrelmail.git] / src / left_main.php
1 <?
2 /**
3 ** left_main.php
4 **
5 ** This is the code for the left bar. The left bar shows the folders
6 ** available, and has cookie information.
7 **
8 **/
9
10 if(!isset($username)) {
11 echo "You need a valid user and password to access this page!";
12 exit;
13 }
14 ?>
15 <HTML>
16 <?
17 include("../config/config.php");
18 include("../functions/array.php");
19 include("../functions/strings.php");
20 include("../functions/imap.php");
21
22 function formatMailboxName($imapConnection, $mailbox, $real_box, $delimeter, $color, $move_to_trash) {
23 require ("../config/config.php");
24
25 $mailboxURL = urlencode($real_box);
26 sqimap_mailbox_select ($imapConnection, $real_box);
27 $unseen = sqimap_unseen_messages($imapConnection, $numUnseen);
28
29 echo "<NOBR>";
30 if ($unseen)
31 $line .= "<B>";
32
33 $special_color = false;
34 for ($i = 0; $i < count($special_folders); $i++) {
35 if (($special_folders[$i] == $real_box) && ($use_special_folder_color == true))
36 $special_color = true;
37 }
38
39 if ($special_color == true) {
40 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\"><FONT FACE=\"Arial,Helvetica\" COLOR=\"$color[11]\">";
41 $line .= replace_spaces($mailbox);
42 $line .= "</font></a>";
43 } else {
44 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\"><FONT FACE=\"Arial,Helvetica\">";
45 $line .= replace_spaces($mailbox);
46 $line .= "</font></a>";
47 }
48
49 if ($unseen)
50 $line .= "</B>";
51
52 if ($numUnseen > 0) {
53 $line .= "&nbsp;<FONT FACE=\"Arial,Helvetica\" SIZE=2>($numUnseen)</FONT>";
54 }
55
56 if (($move_to_trash == true) && (trim($real_box) == $trash_folder)) {
57 $urlMailbox = urlencode($real_box);
58 $line .= "<FONT FACE=\"Arial,Helvetica\" SIZE=2>";
59 $line .= "&nbsp;&nbsp;&nbsp;&nbsp;(<B><A HREF=\"empty_trash.php?numMessages=$numMessages&mailbox=$urlMailbox\" TARGET=right style=\"text-decoration:none\">empty me</A></B>)";
60 $line .= "</FONT></a>\n";
61 }
62
63 echo "</NOBR>";
64 return $line;
65 }
66
67 // open a connection on the imap port (143)
68 $imapConnection = sqimap_login($username, $key, $imapServerAddress, 10); // the 10 is to hide the output
69
70 /** If it was a successful login, lets load their preferences **/
71 include("../src/load_prefs.php");
72 if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) {
73 echo "<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">";
74 echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">";
75 echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">";
76 }
77
78 echo "<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">";
79 echo "<FONT FACE=\"Arial,Helvetica\">";
80
81 $boxes = sqimap_mailbox_list($imapConnection);
82
83 echo "<FONT FACE=\"Arial,Helvetica\" SIZE=4><B><CENTER>";
84 echo _("Folders") . "</B><BR></FONT>";
85
86 echo "<FONT FACE=\"Arial,Helvetica\" SIZE=2>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">";
87 echo _("refresh folder list");
88 echo "</A>)</FONT></CENTER><BR>";
89 echo "<FONT FACE=\"Arial,Helvetica\">\n";
90 $delimeter = sqimap_get_delimiter($imapConnection);
91
92 for ($i = 0;$i < count($boxes); $i++) {
93 $line = "";
94 $mailbox = $boxes[$i]["formatted"];
95
96 if ($boxes[$i]["flags"]) {
97 $noselect = false;
98 for ($h = 0; $h < count($boxes[$i]["flags"]); $h++) {
99 if (strtolower($boxes[$i]["flags"][$h]) == "noselect")
100 $noselect = true;
101 }
102 if ($noselect == true) {
103 $line .= "<FONT COLOR=\"$color[10]\" FACE=\"Arial,Helvetica\">";
104 $line .= replace_spaces(readShortMailboxName($mailbox, $delimeter));
105 $line .= "</FONT><FONT FACE=\"Arial,Helvetica\">";
106 } else {
107 $line .= formatMailboxName($imapConnection, $mailbox, $boxes[$i]["unformatted"], $delimeter, $color, $move_to_trash);
108 }
109 } else {
110 $line .= formatMailboxName($imapConnection, $mailbox, $boxes[$i]["unformatted"], $delimeter, $color, $move_to_trash);
111 }
112 echo "$line<BR>";
113 }
114
115 echo "</FONT>";
116
117 fclose($imapConnection);
118
119 ?>
120 </FONT></BODY></HTML>