b224497b55887402220e834898c8001245af11a4
[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 include("../functions/mailbox.php");
22
23 function formatMailboxName($imapConnection, $mailbox, $delimeter) {
24 require ("../config/config.php");
25
26 $mailboxURL = urlencode($mailbox);
27 selectMailbox($imapConnection, $mailbox, $numNessages);
28 $unseen = unseenMessages($imapConnection, $numUnseen);
29
30 if ($unseen)
31 $line .= "<B>";
32
33 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\"><FONT FACE=\"Arial,Helvetica\">";
34 $line .= readShortMailboxName($mailbox, $delimeter);
35 if (($move_to_trash == true) && (trim($mailbox) == $trash_folder)) {
36 $urlMailbox = urlencode($mailbox);
37 $line .= "</A>&nbsp;&nbsp;&nbsp;&nbsp;(<B><A HREF=\"empty_trash.php?numMessages=$numMessages&mailbox=$urlMailbox\" TARGET=right style=\"text-decoration:none\">empty</A></B>)";
38 }
39 $line .= "</FONT></a>\n";
40 if ($numUnseen > 0) {
41 $line .= "</B>&nbsp;</FONT><FONT FACE=\"Arial,Helvetica\" SIZE=2>($numUnseen)</FONT>";
42 }
43 return $line;
44 }
45
46 echo "<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">";
47 echo "<FONT FACE=\"Arial,Helvetica\">";
48 // open a connection on the imap port (143)
49 $imapConnection = loginToImapServer($username, $key, $imapServerAddress, 10); // the 10 is to hide the output
50
51 fputs($imapConnection, "1 list \"\" *\n");
52 $str = imapReadData($imapConnection, "1", true, $response, $message);
53
54 echo "<FONT FACE=\"Arial,Helvetica\" SIZE=4><B><CENTER>";
55 echo "Folders</B><BR></FONT>";
56 echo "<FONT FACE=\"Arial,Helvetica\" SIZE=2>(<A HREF=\"../src/left_main.php\" TARGET=left>refresh folder list</A>)</FONT></CENTER><BR>";
57 echo "<FONT FACE=\"Arial,Helvetica\">\n";
58 $delimeter = findMailboxDelimeter($imapConnection);
59 for ($i = 0;$i < count($str); $i++) {
60 $mailbox = Chop($str[$i]);
61 $boxFlags = getMailboxFlags($mailbox);
62 $mailbox = findMailboxName($mailbox);
63
64 $boxCount = countCharInString($mailbox, $delimeter);
65
66 $line = "";
67 // indent the correct number of spaces.
68 for ($j = 0;$j < $boxCount;$j++)
69 $line .= "&nbsp;&nbsp;";
70
71 if (trim($boxFlags[0]) != "") {
72 for ($h = 0; $h < count($boxFlags); $h++) {
73 if (strtolower($boxFlags[$h]) == "noselect") {
74 $line .= "<FONT COLOR=\"$color[10]\" FACE=\"Arial,Helvetica\">";
75 $line .= readShortMailboxName($mailbox, $delimeter);
76 $line .= "</FONT><FONT FACE=\"Arial,Helvetica\">";
77 } else {
78 $line .= formatMailboxName($imapConnection, $mailbox, $delimeter);
79 }
80 }
81 } else {
82 $line .= formatMailboxName($imapConnection, $mailbox, $delimeter);
83 }
84 $folder_list[$i]["FORMATTED"] = trim($line);
85 $folder_list[$i]["PLAIN"] = trim($mailbox);
86 $folder_list[$i]["ID"] = $i;
87 }
88
89 /** Alphebetize the folders */
90 $original = $folder_list;
91
92 for ($i = 0; $i < count($original); $i++) {
93 $folder_list[$i]["PLAIN"] = strtolower($folder_list[$i]["PLAIN"]);
94 }
95
96 $folder_list = ary_sort($folder_list, "PLAIN", 1);
97
98 for ($i = 0; $i < count($original); $i++) {
99 for ($j = 0; $j < count($original); $j++) {
100 if ($folder_list[$i]["ID"] == $original[$j]["ID"]) {
101 $folder_list[$i]["PLAIN"] = $original[$j]["PLAIN"];
102 $folder_list[$i]["FORMATTED"] = $original[$j]["FORMATTED"];
103 }
104 }
105 }
106
107 /** If it is the inbox, list it first **/
108 for ($i = 0; $i < count($folder_list); $i++) {
109 if ($folder_list[$i]["PLAIN"] == $special_folders[0]) {
110 echo "<FONT FACE=\"Arial,Helvetica\">";
111 echo trim($folder_list[$i]["FORMATTED"]);
112 echo "</FONT><BR>";
113 $folder_list[$i]["USED"] = true;
114 }
115 }
116 /** Now the other special folders **/
117 if ($list_special_folders_first == true) {
118 for ($i = 0; $i < count($folder_list); $i++) {
119 for ($j = 1; $j < count($special_folders); $j++) {
120 if (substr($folder_list[$i]["PLAIN"], 0, strlen($special_folders[$j])) == $special_folders[$j]) {
121 echo "<FONT FACE=\"Arial,Helvetica\">";
122 echo trim($folder_list[$i]["FORMATTED"]);
123 echo "</FONT><BR>";
124 $folder_list[$i]["USED"] = true;
125 }
126 }
127 }
128 }
129 /** Then list all the other ones (not equal to INBOX) **/
130 /** NOTE: .mailboxlist is a netscape thing.. just ignore it **/
131 for ($i = 0; $i < count($folder_list); $i++) {
132 if (($folder_list[$i]["PLAIN"] != $special_folders[0]) &&
133 ($folder_list[$i]["PLAIN"] != ".mailboxlist") &&
134 ($folder_list[$i]["USED"] == false)) {
135 echo "<FONT FACE=\"Arial,Helvetica\">";
136 echo trim($folder_list[$i]["FORMATTED"]);
137 echo "</FONT><BR>";
138 }
139 }
140
141 echo "</FONT>";
142
143 fclose($imapConnection);
144
145 ?>
146 </FONT></BODY></HTML>