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