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