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