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