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