Rewrote multipart/* algorithm to be recursive
[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 echo "<NOBR>";
31 if ($unseen)
32 $line .= "<B>";
33
34 $special_color = false;
35 for ($i = 0; $i < count($special_folders); $i++) {
36 if (($special_folders[$i] == $mailbox) && ($use_special_folder_color == true))
37 $special_color = true;
38 }
39
40 if ($special_color == true) {
41 $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]\">";
42 $line .= readShortMailboxName($mailbox, $delimeter);
43 $line .= "</font></a>";
44 } else {
45 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\"><FONT FACE=\"Arial,Helvetica\">";
46 $line .= readShortMailboxName($mailbox, $delimeter);
47 $line .= "</font></a>";
48 }
49
50 if ($unseen)
51 $line .= "</B>";
52
53 if ($numUnseen > 0) {
54 $line .= "&nbsp;<FONT FACE=\"Arial,Helvetica\" SIZE=2>($numUnseen)</FONT>";
55 }
56
57 if (($move_to_trash == true) && (trim($mailbox) == $trash_folder)) {
58 $urlMailbox = urlencode($mailbox);
59 $line .= "<FONT FACE=\"Arial,Helvetica\" SIZE=2>";
60 $line .= "&nbsp;&nbsp;&nbsp;&nbsp;(<B><A HREF=\"empty_trash.php?numMessages=$numMessages&mailbox=$urlMailbox\" TARGET=right style=\"text-decoration:none\">empty</A></B>)";
61 $line .= "</FONT></a>\n";
62 }
63
64 echo "</NOBR>";
65 return $line;
66 }
67
68 echo "<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">";
69 echo "<FONT FACE=\"Arial,Helvetica\">";
70 // open a connection on the imap port (143)
71 $imapConnection = loginToImapServer($username, $key, $imapServerAddress, 10); // the 10 is to hide the output
72
73 getFolderList($imapConnection, $boxes);
74
75 echo "<FONT FACE=\"Arial,Helvetica\" SIZE=4><B><CENTER>";
76 echo "Folders</B><BR></FONT>";
77
78 echo "<FONT FACE=\"Arial,Helvetica\" SIZE=2>(<A HREF=\"../src/left_main.php\" TARGET=left>refresh folder list</A>)</FONT></CENTER><BR>";
79 echo "<FONT FACE=\"Arial,Helvetica\">\n";
80 $delimeter = findMailboxDelimeter($imapConnection);
81 for ($i = 0;$i < count($boxes); $i++) {
82 $mailbox = $boxes[$i]["UNFORMATTED"];
83 $boxFlags = getMailboxFlags($boxes[$i]["RAW"]);
84
85 $boxCount = countCharInString($mailbox, $delimeter);
86
87 $line = "";
88 // indent the correct number of spaces.
89 for ($j = 0;$j < $boxCount;$j++)
90 $line .= "&nbsp;&nbsp;";
91
92 if (trim($boxFlags[0]) != "") {
93 $noselect = false;
94 for ($h = 0; $h < count($boxFlags); $h++) {
95 if (strtolower($boxFlags[$h]) == "noselect")
96 $noselect = true;
97 }
98
99 if ($noselect == true) {
100 $line .= "<FONT COLOR=\"$color[10]\" FACE=\"Arial,Helvetica\">";
101 $line .= readShortMailboxName($mailbox, $delimeter);
102 $line .= "</FONT><FONT FACE=\"Arial,Helvetica\">";
103 } else {
104 $line .= formatMailboxName($imapConnection, $mailbox, $delimeter);
105 }
106 } else {
107 $line .= formatMailboxName($imapConnection, $mailbox, $delimeter);
108 }
109 echo "$line<BR>";
110 }
111
112 echo "</FONT>";
113
114 fclose($imapConnection);
115
116 ?>
117 </FONT></BODY></HTML>