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