reconstructed the left folder list
[squirrelmail.git] / functions / mailbox_display.php
1 <?
2
3 /**
4 ** mailbox_display.php
5 **
6 ** This contains functions that display mailbox information, such as the
7 ** table row that has sender, date, subject, etc...
8 **
9 **/
10
11 function printMessageInfo($imapConnection, $t, $i, $from, $subject, $dateString, $answered, $seen, $mailbox, $sort, $startMessage) {
12 $senderName = getSenderName($from);
13 $urlMailbox = urlencode($mailbox);
14 $subject = trim($subject);
15 echo "<TR>\n";
16 if ($seen == false) {
17 echo " <TD><FONT FACE=\"Arial,Helvetica\"><nobr><B><input type=checkbox name=\"msg[$t]\" value=$i></B></nobr></FONT></TD>\n";
18 echo " <TD><FONT FACE=\"Arial,Helvetica\"><B>$senderName</B></FONT></TD>\n";
19 echo " <TD><CENTER><B><FONT FACE=\"Arial,Helvetica\">$dateString</FONT></B></CENTER></TD>\n";
20 echo " <TD><FONT FACE=\"Arial,Helvetica\"><B><A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$i&sort=$sort&startMessage=$startMessage&show_more=0\">$subject</A></B></FONT></TD>\n";
21 } else {
22 echo " <TD><FONT FACE=\"Arial,Helvetica\"><nobr><input type=checkbox name=\"msg[$t]\" value=$i></nobr></FONT></TD>\n";
23 echo " <TD><FONT FACE=\"Arial,Helvetica\">$senderName</FONT></TD>\n";
24 echo " <TD><FONT FACE=\"Arial,Helvetica\"><CENTER>$dateString</CENTER></FONT></TD>\n";
25 echo " <TD><FONT FACE=\"Arial,Helvetica\"><A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$i&sort=$sort&startMessage=$startMessage&show_more=0\">$subject</A></FONT></TD>\n";
26 }
27 echo "</TR>\n";
28 }
29
30 /**
31 ** This function loops through a group of messages in the mailbox and shows them
32 **/
33 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort) {
34 include("../config/config.php");
35
36 if (1 <= $numMessages) {
37 getMessageHeaders($imapConnection, 1, $numMessages, $from, $subject, $date);
38 }
39
40 $j = 0;
41 while ($j < $numMessages) {
42 $date[$j] = ereg_replace(" ", " ", $date[$j]);
43 $tmpdate = explode(" ", trim($date[$j]));
44
45 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
46 $messages[$j]["DATE_STRING"] = getDateString($tmpdate);
47 $messages[$j]["ID"] = $j+1;
48 $messages[$j]["FROM"] = getSenderName($from[$j]);
49 $messages[$j]["SUBJECT"] = $subject[$j];
50 $messages[$j]["FLAG_DELETED"] = false;
51 $messages[$j]["FLAG_ANSWERED"] = false;
52 $messages[$j]["FLAG_SEEN"] = false;
53
54 $num = 0;
55 getMessageFlags($imapConnection, $j+1, $flags);
56 while ($num < count($flags)) {
57 if ($flags[$num] == "Deleted") {
58 $messages[$j]["FLAG_DELETED"] = true;
59 }
60 else if ($flags[$num] == "Answered") {
61 $messages[$j]["FLAG_ANSWERED"] = true;
62 }
63 else if ($flags[$num] == "Seen") {
64 $messages[$j]["FLAG_SEEN"] = true;
65 }
66 $num++;
67 }
68 $j++;
69 }
70
71 /** Find and remove the ones that are deleted */
72 $i = 0;
73 $j = 0;
74 while ($j < $numMessages) {
75 if ($messages[$j]["FLAG_DELETED"] == true) {
76 $j++;
77 continue;
78 }
79 $msgs[$i]["TIME_STAMP"] = $messages[$j]["TIME_STAMP"];
80 $msgs[$i]["DATE_STRING"] = $messages[$j]["DATE_STRING"];
81 $msgs[$i]["ID"] = $messages[$j]["ID"];
82 $msgs[$i]["FROM"] = $messages[$j]["FROM"];
83 $msgs[$i]["SUBJECT"] = $messages[$j]["SUBJECT"];
84 $msgs[$i]["FLAG_DELETED"] = $messages[$j]["FLAG_DELETED"];
85 $msgs[$i]["FLAG_ANSWERED"] = $messages[$j]["FLAG_ANSWERED"];
86 $msgs[$i]["FLAG_SEEN"] = $messages[$j]["FLAG_SEEN"];
87
88 $i++;
89 $j++;
90 }
91
92 $numMessages = $i;
93
94 // There's gotta be messages in the array for it to sort them.
95 if ($numMessages > 0) {
96 /** 0 = Date (up) 4 = Subject (up)
97 ** 1 = Date (dn) 5 = Subject (dn)
98 ** 2 = Name (up)
99 ** 3 = Name (dn)
100 **/
101 if ($sort == 0)
102 $msgs = ary_sort($msgs, "TIME_STAMP", -1);
103 else if ($sort == 1)
104 $msgs = ary_sort($msgs, "TIME_STAMP", 1);
105 else {
106 $original = $msgs;
107 $i = 0;
108 while ($i < count($msgs)) {
109 $msgs[$i]["FROM"] = strtolower($msgs[$i]["FROM"]);
110 $msgs[$i]["SUBJECT"] = strtolower($msgs[$i]["SUBJECT"]);
111 $i++;
112 }
113
114 if ($sort == 2)
115 $msgs = ary_sort($msgs, "FROM", -1);
116 else if ($sort == 3)
117 $msgs = ary_sort($msgs, "FROM", 1);
118 else if ($sort == 4)
119 $msgs = ary_sort($msgs, "SUBJECT", -1);
120 else if ($sort == 5)
121 $msgs = ary_sort($msgs, "SUBJECT", 1);
122 else
123 $msgs = ary_sort($msgs, "TIME_STAMP", -1);
124
125 $i = 0;
126 while ($i < count($msgs)) {
127 $j = 0;
128 while ($j < count($original)) {
129 if ($msgs[$i]["ID"] == $original[$j]["ID"]) {
130 $msgs[$i]["FROM"] = $original[$j]["FROM"];
131 $msgs[$i]["SUBJECT"] = $original[$j]["SUBJECT"];
132 }
133 $j++;
134 }
135 $i++;
136 }
137 }
138 }
139
140 // $j = 0;
141 // while ($j < $numMessages) {
142 // $sub = $msgs[$j]["SUBJECT"];
143 // $id = $msgs[$j]["ID"];
144 // echo "$id -- $sub<BR>";
145 // $j++;
146 // }
147 //exit;
148
149 if ($startMessage + 24 < $numMessages) {
150 $endMessage = $startMessage + 24;
151 } else {
152 $endMessage = $numMessages;
153 }
154
155 $nextGroup = $startMessage + 25;
156 $prevGroup = $startMessage - 25;
157 $urlMailbox = urlencode($mailbox);
158
159
160 /** This is the beginning of the message list table. It wraps around all messages */
161 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1>";
162
163 if ($startMessage < $endMessage) {
164 echo "<TR BGCOLOR=FFFFFF><TD>";
165 echo "<CENTER><FONT FACE=\"Arial,Helvetica\">Viewing messages <B>$startMessage</B> to <B>$endMessage</B> ($numMessages total)</FONT></CENTER>\n";
166 echo "</TD></TR>\n";
167 } else if ($startMessage == $endMessage) {
168 echo "<TR BGCOLOR=FFFFFF><TD>";
169 echo "<CENTER><FONT FACE=\"Arial,Helvetica\">Viewing message <B>$startMessage</B> ($numMessages total)</FONT></CENTER>\n";
170 echo "</TD></TR>\n";
171 }
172
173 echo "<TR BGCOLOR=FFFFFF><TD>";
174 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
175 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
176 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
177 }
178 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
179 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
180 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=ACACAC>Next</FONT>\n";
181 }
182 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
183 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=ACACAC>Previous</FONT>\n";
184 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
185 }
186 echo "</TD></TR>\n";
187
188 /** The delete and move options */
189 echo "<TR><TD BGCOLOR=$color_lgray>";
190
191 echo "\n\n\n<FORM name=messageList method=post action=\"move_messages.php?msg=$msg&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage\">";
192 echo "<TABLE BGCOLOR=$color_lgray>\n";
193 echo " <TR>\n";
194 echo " <TD WIDTH=30% ALIGN=LEFT>\n";
195 echo " <NOBR><FONT FACE=\"Arial,Helvetica\" SIZE=2><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"Move to:\">\n";
196 echo " <SELECT NAME=\"targetMailbox\">\n";
197 getFolderList($imapConnection, $boxesFormatted, $boxesUnformatted);
198 for ($i = 0; $i < count($boxesUnformatted); $i++) {
199 $use_folder = true;
200 for ($p = 0; $p < count($special_folders); $p++) {
201 // don't allow moving messages to any special folder EXCEPT for INBOX.
202 if (($boxesUnformatted[$i] == $special_folders[$p]) && ($boxesUnformatted[$i] != "INBOX")) {
203 $use_folder = false;
204 } else if (substr($boxesUnformatted[$i], 0, strlen($trash_folder)) == $trash_folder) {
205 $use_folder = false;
206 }
207 }
208 if ($use_folder == true)
209 echo " <OPTION VALUE=\"$boxesUnformatted[$i]\">$boxesUnformatted[$i]\n";
210 }
211 echo " </SELECT></NOBR></FONT>\n";
212
213 echo " </TD>\n";
214 echo " <TD WIDTH=70% ALIGN=RIGHT>\n";
215 echo " <NOBR><FONT FACE=\"Arial,Helvetica\" SIZE=2><INPUT TYPE=SUBMIT VALUE=\"Delete\">&nbsp;checked messages</FONT></NOBR>\n";
216 echo " </TD>";
217 echo " </TR>\n";
218
219 echo "</TABLE>\n\n\n";
220 echo "</TD></TR>";
221
222 echo "<TR><TD BGCOLOR=$color_lgray>";
223 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=FFFFFF>";
224 echo "<TR BGCOLOR=FFFFCC ALIGN=\"center\">";
225 echo " <TD WIDTH=5%><FONT FACE=\"Arial,Helvetica\"><B>Num</B></FONT></TD>";
226 /** FROM HEADER **/
227 echo " <TD WIDTH=25%><FONT FACE=\"Arial,Helvetica\"><B>From</B></FONT>";
228 if ($sort == 2)
229 echo " <A HREF=\"right_main.php?sort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
230 else if ($sort == 3)
231 echo " <A HREF=\"right_main.php?sort=2&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
232 else
233 echo " <A HREF=\"right_main.php?sort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
234 /** DATE HEADER **/
235 echo " <TD WIDTH=15%><FONT FACE=\"Arial,Helvetica\"><B>Date</B></FONT>";
236 if ($sort == 0)
237 echo " <A HREF=\"right_main.php?sort=1&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
238 else if ($sort == 1)
239 echo " <A HREF=\"right_main.php?sort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
240 else
241 echo " <A HREF=\"right_main.php?sort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
242 /** SUBJECT HEADER **/
243 echo " <TD WIDTH=*><FONT FACE=\"Arial,Helvetica\"><B>Subject</B></FONT>\n";
244 if ($sort == 4)
245 echo " <A HREF=\"right_main.php?sort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
246 else if ($sort == 5)
247 echo " <A HREF=\"right_main.php?sort=4&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
248 else
249 echo " <A HREF=\"right_main.php?sort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
250 echo "</TR>";
251
252 // loop through and display the info for each message.
253 $t = 0; // $t is used for the checkbox number
254 if ($numMessages == 0) { // if there's no messages in this folder
255 echo "<TR><TD BGCOLOR=FFFFFF COLSPAN=4><CENTER><BR><B>THIS FOLDER IS EMPTY</B><BR>&nbsp</CENTER></TD></TR>";
256 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
257 $i = $startMessage - 1;
258 printMessageInfo($imapConnection, $t, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"], $mailbox, $sort, $startMessage);
259 } else {
260 for ($i = $startMessage - 1;$i <= $endMessage - 1; $i++) {
261 printMessageInfo($imapConnection, $t, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"], $mailbox, $sort, $startMessage);
262 $t++;
263 }
264 }
265 echo "</FORM></TABLE>";
266
267 echo "</TABLE>\n";
268 echo "</TD></TR>\n";
269
270 echo "<TR BGCOLOR=FFFFFF><TD>";
271 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
272 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
273 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
274 }
275 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
276 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
277 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=ACACAC>Next</FONT>\n";
278 }
279 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
280 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=ACACAC>Previous</FONT>\n";
281 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
282 }
283 echo "</TD></TR></TABLE>"; /** End of message-list table */
284 }
285 ?>