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