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