Minor HTML change to make Opera see the message list like Netscape
[squirrelmail.git] / functions / mailbox_display.php
1 <?php
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 $mailbox_display_php = true;
12
13 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, $where, $what) {
14 global $color, $msgs, $msort;
15 global $sent_folder;
16 global $message_highlight_list;
17
18 $msg = $msgs[$key];
19
20 $senderName = sqimap_find_displayable_name($msg["FROM"]);
21 $urlMailbox = urlencode($mailbox);
22 $subject = trim($msg["SUBJECT"]);
23 if ($subject == "")
24 $subject = _("(no subject)");
25
26 echo "<TR>\n";
27
28 if ($msg["FLAG_FLAGGED"] == true) { $flag = "<font color=$color[2]>"; $flag_end = "</font>"; }
29 if ($msg["FLAG_SEEN"] == false) { $bold = "<b>"; $bold_end = "</b>"; }
30 if ($mailbox == $sent_folder) { $italic = "<i>"; $italic_end = "</i>"; }
31
32 for ($i=0; $i < count($message_highlight_list); $i++) {
33 if (trim($message_highlight_list[$i]["value"]) != "") {
34 if ($message_highlight_list[$i]["match_type"] == "to_cc") {
35 if (strpos("^^".strtolower($msg["TO"]), strtolower($message_highlight_list[$i]["value"])) || strpos("^^".strtolower($msg["CC"]), strtolower($message_highlight_list[$i]["value"]))) {
36 $hlt_color = $message_highlight_list[$i]["color"];
37 continue;
38 }
39 } else if (strpos("^^".strtolower($msg[strtoupper($message_highlight_list[$i]["match_type"])]),strtolower($message_highlight_list[$i]["value"]))) {
40 $hlt_color = $message_highlight_list[$i]["color"];
41 continue;
42 }
43 }
44 }
45
46 if (!$hlt_color)
47 $hlt_color = $color[4];
48
49 if ($where && $what) {
50 $search_stuff = "&where=".urlencode($where)."&what=".urlencode($what);
51 }
52
53 echo " <td width=1% bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
54 echo " <td width=30% bgcolor=$hlt_color>$italic$bold$flag$senderName$flag_end$bold_end$italic_end</td>\n";
55 echo " <td nowrap width=1% bgcolor=$hlt_color><center>$bold$flag".$msg["DATE_STRING"]."$flag_end$bold_end</center></td>\n";
56
57 if ($msg["FLAG_ANSWERED"] == true) echo " <td bgcolor=$hlt_color width=1%><b><small>A</small></b></td>\n";
58 elseif (ereg("(1|2)",substr($msg["PRIORITY"],0,1))) echo " <td bgcolor=$hlt_color width=1%><b><small><font color=$color[1]>!</font></small></b></td>\n";
59 else echo " <td bgcolor=$hlt_color width=1%>&nbsp;</td>\n";
60 echo " <td bgcolor=$hlt_color>$bold<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$startMessage&show_more=0$search_stuff\">$flag$subject$flag_end</a>$bold_end</td>\n";
61
62 echo "</tr>\n";
63 }
64
65 /**
66 ** This function loops through a group of messages in the mailbox and shows them
67 **/
68 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
69 global $msgs, $msort;
70 global $sent_folder;
71 global $message_highlight_list;
72 global $auto_expunge;
73
74 if ($auto_expunge) {
75 sqimap_mailbox_expunge($imapConnection, $mailbox);
76 sqimap_mailbox_select($imapConnection, $mailbox);
77 }
78
79 if (!$use_cache) {
80 if ($numMessages >= 1) {
81 for ($q = 0; $q < $numMessages; $q++) {
82 if ($mailbox == $sent_folder)
83 $hdr = sqimap_get_small_header ($imapConnection, $q+1, true);
84 else
85 $hdr = sqimap_get_small_header ($imapConnection, $q+1, false);
86
87 $from[$q] = $hdr->from;
88 $date[$q] = $hdr->date;
89 $subject[$q] = $hdr->subject;
90 $to[$q] = $hdr->to;
91 $priority[$q] = $hdr->priority;
92 $cc[$q] = $hdr->cc;
93
94 $flags[$q] = sqimap_get_flags ($imapConnection, $q+1);
95 }
96 }
97
98 $j = 0;
99 while ($j < $numMessages) {
100 $date[$j] = ereg_replace(" ", " ", $date[$j]);
101 $tmpdate = explode(" ", trim($date[$j]));
102
103 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
104 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
105 $messages[$j]["ID"] = $j+1;
106 $messages[$j]["FROM"] = decodeHeader($from[$j]);
107 $messages[$j]["FROM-SORT"] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
108 $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
109 $messages[$j]["SUBJECT-SORT"] = strtolower(decodeHeader($subject[$j]));
110 $messages[$j]["TO"] = decodeHeader($to[$j]);
111 $messages[$j]["PRIORITY"] = $priority[$j];
112 $messages[$j]["CC"] = $cc[$j];
113
114 # fix SUBJECT-SORT to remove Re:
115 if (substr($messages[$j]["SUBJECT-SORT"], 0, 3) == "re:" ||
116 substr($messages[$j]["SUBJECT-SORT"], 0, 3) == "aw:")
117 $messages[$j]["SUBJECT-SORT"] = trim(substr($messages[$j]["SUBJECT-SORT"], 3));
118
119 $num = 0;
120 while ($num < count($flags[$j])) {
121 if ($flags[$j][$num] == "Deleted") {
122 $messages[$j]["FLAG_DELETED"] = true;
123 }
124 else if ($flags[$j][$num] == "Answered") {
125 $messages[$j]["FLAG_ANSWERED"] = true;
126 }
127 else if ($flags[$j][$num] == "Seen") {
128 $messages[$j]["FLAG_SEEN"] = true;
129 }
130 else if ($flags[$j][$num] == "Flagged") {
131 $messages[$j]["FLAG_FLAGGED"] = true;
132 }
133 $num++;
134 }
135 $j++;
136 }
137
138 /** Find and remove the ones that are deleted */
139 $i = 0;
140 $j = 0;
141 while ($j < $numMessages) {
142 if ($messages[$j]["FLAG_DELETED"] == true) {
143 $j++;
144 continue;
145 }
146 $msgs[$i] = $messages[$j];
147
148 $i++;
149 $j++;
150 }
151 $numMessages = $i;
152 }
153
154 // There's gotta be messages in the array for it to sort them.
155 if (($numMessages > 0) && (!$use_cache)) {
156 /** 0 = Date (up) 4 = Subject (up)
157 ** 1 = Date (dn) 5 = Subject (dn)
158 ** 2 = Name (up)
159 ** 3 = Name (dn)
160 **/
161 session_unregister("msgs");
162 if (($sort == 0) || ($sort == 1))
163 $msort = array_cleave ($msgs, "TIME_STAMP");
164 if (($sort == 2) || ($sort == 3))
165 $msort = array_cleave ($msgs, "FROM-SORT");
166 if (($sort == 4) || ($sort == 5))
167 $msort = array_cleave ($msgs, "SUBJECT-SORT");
168
169 if(($sort % 2) == 1) {
170 asort($msort);
171 } else {
172 arsort($msort);
173 }
174 session_register("msort");
175 }
176 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
177 session_register("msgs");
178 }
179
180 // generic function to convert the msgs array into an HTML table
181 function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
182 global $folder_prefix, $sent_folder;
183 global $imapServerAddress;
184
185 // if cache isn't already set, do it now
186 if (!session_is_registered("msgs"))
187 session_register("msgs");
188 if (!session_is_registered("msort"))
189 session_register("msort");
190
191
192 if ($startMessage + ($show_num - 1) < $numMessages) {
193 $endMessage = $startMessage + ($show_num-1);
194 } else {
195 $endMessage = $numMessages;
196 }
197
198 if ($endMessage < $startMessage) {
199 $startMessage = $startMessage - $show_num;
200 if ($startMessage < 1)
201 $startMessage = 1;
202 }
203
204 $nextGroup = $startMessage + $show_num;
205 $prevGroup = $startMessage - $show_num;
206 $urlMailbox = urlencode($mailbox);
207
208 do_hook("mailbox_index_before");
209 /** This is the beginning of the message list table. It wraps around all messages */
210 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0>";
211
212 if ($startMessage < $endMessage) {
213 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
214 echo "<CENTER>". _("Viewing messages") ." <B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")</CENTER>\n";
215 echo "</TD></TR>\n";
216 } else if ($startMessage == $endMessage) {
217 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
218 echo "<CENTER>". _("Viewing message") ." <B>$startMessage</B> ($numMessages " . _("total") . ")</CENTER>\n";
219 echo "</TD></TR>\n";
220 }
221
222 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
223 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
224 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
225 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
226 }
227 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
228 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
229 echo "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
230 }
231 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
232 echo "<FONT COLOR=\"$color[9]\">"._("Previous")."</FONT> | \n";
233 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
234 }
235 echo "</TD></TR>\n";
236
237 /** The delete and move options */
238 echo "<TR><TD BGCOLOR=\"$color[0]\">";
239
240 echo "\n\n\n<FORM name=messageList method=post action=\"move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage\">";
241 do_hook("mailbox_form_before");
242 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
243 echo " <TR>\n";
244 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
245 echo " <NOBR><SMALL>". _("Move selected to:") ."</SMALL>";
246 echo " <TT><SMALL><SELECT NAME=\"targetMailbox\">";
247
248 $boxes = sqimap_mailbox_list($imapConnection);
249 for ($i = 0; $i < count($boxes); $i++) {
250 if ($boxes[$i]["flags"][0] != "noselect" && $boxes[$i]["flags"][1] != "noselect" && $boxes[$i]["flags"][2] != "noselect") {
251 $box = $boxes[$i]["unformatted"];
252 $box2 = replace_spaces($boxes[$i]["formatted"]);
253 echo " <OPTION VALUE=\"$box\">$box2\n";
254 }
255 }
256 echo " </SELECT></SMALL></TT>";
257 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"". _("Move") ."\"></SMALL></NOBR>\n";
258
259 echo " </TD>\n";
260 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
261 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\">&nbsp;". _("checked messages") ."</SMALL></NOBR>\n";
262 echo " </TD>";
263 echo " </TR>\n";
264
265 echo "</TABLE>\n\n\n";
266 echo "</TD></TR>";
267
268 echo "<TR><TD BGCOLOR=\"$color[0]\">";
269 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[0]\">";
270 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
271 echo " <TD WIDTH=1%><B>&nbsp;</B></TD>";
272 /** FROM HEADER **/
273 if ($mailbox == $sent_folder)
274 echo " <TD WIDTH=30%><B>". _("To") ."</B>";
275 else
276 echo " <TD WIDTH=30%><B>". _("From") ."</B>";
277
278 if ($sort == 2)
279 echo " <A HREF=\"right_main.php?newsort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
280 else if ($sort == 3)
281 echo " <A HREF=\"right_main.php?newsort=2&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
282 else
283 echo " <A HREF=\"right_main.php?newsort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
284 /** DATE HEADER **/
285 echo " <TD nowrap WIDTH=1%><B>". _("Date") ."</B>";
286 if ($sort == 0)
287 echo " <A HREF=\"right_main.php?newsort=1&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
288 else if ($sort == 1)
289 echo " <A HREF=\"right_main.php?newsort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
290 else
291 echo " <A HREF=\"right_main.php?newsort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
292 echo " <TD WIDTH=1%>&nbsp;</TD>\n";
293 /** SUBJECT HEADER **/
294 echo " <TD WIDTH=%><B>". _("Subject") ."</B>\n";
295 if ($sort == 4)
296 echo " <A HREF=\"right_main.php?newsort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
297 else if ($sort == 5)
298 echo " <A HREF=\"right_main.php?newsort=4&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
299 else
300 echo " <A HREF=\"right_main.php?newsort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
301
302 echo "</TR>";
303
304
305 // loop through and display the info for each message.
306 $t = 0; // $t is used for the checkbox number
307 if ($numMessages == 0) { // if there's no messages in this folder
308 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=5><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp;</CENTER></TD></TR>";
309 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
310 $i = $startMessage;
311 reset($msort);
312 do {
313 $key = key($msort);
314 next($msort);
315 $k++;
316 } while (isset ($key) && ($k < $i));
317 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, 0, 0);
318 } else {
319 $i = $startMessage;
320 reset($msort);
321 do {
322 $key = key($msort);
323 next($msort);
324 $k++;
325 } while (isset ($key) && ($k < $i));
326
327 do {
328 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, 0, 0);
329 $key = key($msort);
330 $t++;
331 $i++;
332 next($msort);
333 } while ($i < ($endMessage+1));
334 }
335 echo "</FORM></TABLE>";
336
337 echo "</TABLE>\n";
338 echo "</TD></TR>\n";
339
340 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
341 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
342 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Previous") . "</A> | \n";
343 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Next") . "</A>\n";
344 }
345 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
346 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Previous") . "</A> | \n";
347 echo "<FONT COLOR=\"$color[9]\">" . _("Next") . "</FONT>\n";
348 }
349 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
350 echo "<FONT COLOR=\"$color[9]\">" . _("Previous"). "</FONT> | \n";
351 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Next") . "</A>\n";
352 }
353 echo "</TD></TR></table>"; /** End of message-list table */
354
355 do_hook("mailbox_index_after");
356 }
357 ?>