Added the 'login_top' hook (was missing) (login.php)
[squirrelmail.git] / functions / mailbox_display.php
CommitLineData
59177427 1<?php
7c1b84d9 2
3302d0d4 3 /**
a09387f4 4 ** mailbox_display.php
3302d0d4 5 **
6 ** This contains functions that display mailbox information, such as the
7 ** table row that has sender, date, subject, etc...
8 **
9 **/
a4c2cd49 10
266fe275 11 $mailbox_display_php = true;
d068c0ec 12
1809bad8 13 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, $where, $what) {
af9404d7 14 global $color, $msgs, $msort;
cbdc5621 15 global $sent_folder;
9d157cec 16 global $message_highlight_list;
8e265988 17 global $index_order;
cbdc5621 18
af9404d7 19 $msg = $msgs[$key];
d92b6f31 20
c36ed9cf 21 $senderName = sqimap_find_displayable_name($msg["FROM"]);
05207a68 22 $urlMailbox = urlencode($mailbox);
7aaa81fc 23 $subject = trim($msg["SUBJECT"]);
8fca0a65 24 if ($subject == "")
25 $subject = _("(no subject)");
26
926da13e 27 echo "<TR>\n";
7151188f 28
29 if ($msg["FLAG_FLAGGED"] == true) { $flag = "<font color=$color[2]>"; $flag_end = "</font>"; }
30 if ($msg["FLAG_SEEN"] == false) { $bold = "<b>"; $bold_end = "</b>"; }
cbdc5621 31 if ($mailbox == $sent_folder) { $italic = "<i>"; $italic_end = "</i>"; }
7151188f 32
9d157cec 33 for ($i=0; $i < count($message_highlight_list); $i++) {
d059be8f 34 if (trim($message_highlight_list[$i]["value"]) != "") {
35 if ($message_highlight_list[$i]["match_type"] == "to_cc") {
a2790a61 36 if (strpos("^^".strtolower($msg["TO"]), strtolower($message_highlight_list[$i]["value"])) || strpos("^^".strtolower($msg["CC"]), strtolower($message_highlight_list[$i]["value"]))) {
d059be8f 37 $hlt_color = $message_highlight_list[$i]["color"];
38 continue;
39 }
a2790a61 40 } else if (strpos("^^".strtolower($msg[strtoupper($message_highlight_list[$i]["match_type"])]),strtolower($message_highlight_list[$i]["value"]))) {
1195c340 41 $hlt_color = $message_highlight_list[$i]["color"];
42 continue;
d059be8f 43 }
44 }
9d157cec 45 }
623332f3 46
9d157cec 47 if (!$hlt_color)
48 $hlt_color = $color[4];
1809bad8 49
50 if ($where && $what) {
51 $search_stuff = "&where=".urlencode($where)."&what=".urlencode($what);
52 }
d76f6440 53
8e265988 54 for ($i=1; $i <= count($index_order); $i++) {
55 switch ($index_order[$i]) {
56 case 1: # checkbox
57 echo " <td width=1% bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
58 break;
59 case 2: # from
60 echo " <td width=30% bgcolor=$hlt_color>$italic$bold$flag$senderName$flag_end$bold_end$italic_end</td>\n";
61 break;
62 case 3: # date
63 echo " <td nowrap width=1% bgcolor=$hlt_color><center>$bold$flag".$msg["DATE_STRING"]."$flag_end$bold_end</center></td>\n";
64 break;
65 case 4: # subject
66 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";
67 break;
68 case 5: # flags
69 if ($msg["FLAG_ANSWERED"] == true) echo " <td bgcolor=$hlt_color width=1%><b><small>A</small></b></td>\n";
70 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";
71 else echo " <td bgcolor=$hlt_color width=1%>&nbsp;</td>\n";
72 break;
73 case 6: # size
6e7468f6 74 echo " <td bgcolor=$hlt_color width=1%>$bold".show_readable_size($msg['SIZE'])."$bold_end</td>\n";
8e265988 75 break;
76 }
77 }
78
7151188f 79
80 echo "</tr>\n";
926da13e 81 }
82
83 /**
84 ** This function loops through a group of messages in the mailbox and shows them
85 **/
5b6ae78a 86 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
87 global $msgs, $msort;
cbdc5621 88 global $sent_folder;
9d157cec 89 global $message_highlight_list;
a3432f47 90 global $auto_expunge;
91
92 if ($auto_expunge) {
93 sqimap_mailbox_expunge($imapConnection, $mailbox);
94 sqimap_mailbox_select($imapConnection, $mailbox);
95 }
61a4ac35 96
5b6ae78a 97 if (!$use_cache) {
98 if ($numMessages >= 1) {
15a9cd31 99 for ($q = 0; $q < $numMessages; $q++) {
4bbba0d8 100 if ($mailbox == $sent_folder)
101 $hdr = sqimap_get_small_header ($imapConnection, $q+1, true);
102 else
103 $hdr = sqimap_get_small_header ($imapConnection, $q+1, false);
104
105 $from[$q] = $hdr->from;
106 $date[$q] = $hdr->date;
107 $subject[$q] = $hdr->subject;
3e69e88b 108 $to[$q] = $hdr->to;
266fe275 109 $priority[$q] = $hdr->priority;
1195c340 110 $cc[$q] = $hdr->cc;
fde32e3f 111 $size[$q] = $hdr->size;
15a9cd31 112
5b6ae78a 113 $flags[$q] = sqimap_get_flags ($imapConnection, $q+1);
5b10f02a 114 }
5b6ae78a 115 }
116
117 $j = 0;
118 while ($j < $numMessages) {
119 $date[$j] = ereg_replace(" ", " ", $date[$j]);
120 $tmpdate = explode(" ", trim($date[$j]));
121
122 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
123 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
124 $messages[$j]["ID"] = $j+1;
125 $messages[$j]["FROM"] = decodeHeader($from[$j]);
e9f8ea4e 126 $messages[$j]["FROM-SORT"] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
5b6ae78a 127 $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
e9f8ea4e 128 $messages[$j]["SUBJECT-SORT"] = strtolower(decodeHeader($subject[$j]));
3e69e88b 129 $messages[$j]["TO"] = decodeHeader($to[$j]);
266fe275 130 $messages[$j]["PRIORITY"] = $priority[$j];
1195c340 131 $messages[$j]["CC"] = $cc[$j];
fde32e3f 132 $messages[$j]["SIZE"] = $size[$j];
e9f8ea4e 133
134 # fix SUBJECT-SORT to remove Re:
135 if (substr($messages[$j]["SUBJECT-SORT"], 0, 3) == "re:" ||
136 substr($messages[$j]["SUBJECT-SORT"], 0, 3) == "aw:")
137 $messages[$j]["SUBJECT-SORT"] = trim(substr($messages[$j]["SUBJECT-SORT"], 3));
5b6ae78a 138
139 $num = 0;
140 while ($num < count($flags[$j])) {
141 if ($flags[$j][$num] == "Deleted") {
142 $messages[$j]["FLAG_DELETED"] = true;
143 }
144 else if ($flags[$j][$num] == "Answered") {
145 $messages[$j]["FLAG_ANSWERED"] = true;
146 }
147 else if ($flags[$j][$num] == "Seen") {
148 $messages[$j]["FLAG_SEEN"] = true;
149 }
150 else if ($flags[$j][$num] == "Flagged") {
151 $messages[$j]["FLAG_FLAGGED"] = true;
152 }
153 $num++;
7151188f 154 }
5b6ae78a 155 $j++;
3302d0d4 156 }
5b6ae78a 157
158 /** Find and remove the ones that are deleted */
159 $i = 0;
160 $j = 0;
161 while ($j < $numMessages) {
162 if ($messages[$j]["FLAG_DELETED"] == true) {
163 $j++;
164 continue;
165 }
166 $msgs[$i] = $messages[$j];
167
168 $i++;
5b10f02a 169 $j++;
5b10f02a 170 }
5b6ae78a 171 $numMessages = $i;
172 }
926da13e 173
4c2d69ac 174 // There's gotta be messages in the array for it to sort them.
5b6ae78a 175 if (($numMessages > 0) && (!$use_cache)) {
0e919368 176 /** 0 = Date (up) 4 = Subject (up)
177 ** 1 = Date (dn) 5 = Subject (dn)
178 ** 2 = Name (up)
179 ** 3 = Name (dn)
180 **/
09856735 181 session_unregister("msgs");
1c292c82 182 if (($sort == 0) || ($sort == 1))
183 $msort = array_cleave ($msgs, "TIME_STAMP");
184 if (($sort == 2) || ($sort == 3))
e9f8ea4e 185 $msort = array_cleave ($msgs, "FROM-SORT");
1c292c82 186 if (($sort == 4) || ($sort == 5))
e9f8ea4e 187 $msort = array_cleave ($msgs, "SUBJECT-SORT");
1c292c82 188
5b6ae78a 189 if(($sort % 2) == 1) {
190 asort($msort);
191 } else {
192 arsort($msort);
0e919368 193 }
5b6ae78a 194 session_register("msort");
4c2d69ac 195 }
5b6ae78a 196 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
09856735 197 session_register("msgs");
9f2215a1 198 }
199
200 // generic function to convert the msgs array into an HTML table
5b6ae78a 201 function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
cbdc5621 202 global $folder_prefix, $sent_folder;
203 global $imapServerAddress;
8e265988 204 global $index_order;
8e9e8afa 205
9f2215a1 206 // if cache isn't already set, do it now
90033b64 207 if (!session_is_registered("msgs"))
208 session_register("msgs");
5b6ae78a 209 if (!session_is_registered("msort"))
210 session_register("msort");
90033b64 211
8442ac08 212
9c83f905 213 if ($startMessage + ($show_num - 1) < $numMessages) {
214 $endMessage = $startMessage + ($show_num-1);
926da13e 215 } else {
926da13e 216 $endMessage = $numMessages;
217 }
8442ac08 218
219 if ($endMessage < $startMessage) {
220 $startMessage = $startMessage - $show_num;
221 if ($startMessage < 1)
222 $startMessage = 1;
223 }
224
9c83f905 225 $nextGroup = $startMessage + $show_num;
226 $prevGroup = $startMessage - $show_num;
20db5033 227 $urlMailbox = urlencode($mailbox);
926da13e 228
6b638171 229 do_hook("mailbox_index_before");
20db5033 230 /** This is the beginning of the message list table. It wraps around all messages */
623332f3 231 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0>";
926da13e 232
0d1b4832 233 if ($startMessage < $endMessage) {
f8f9bed9 234 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
7e343a7d 235 echo "<CENTER>". _("Viewing messages") ." <B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")</CENTER>\n";
0d1b4832 236 echo "</TD></TR>\n";
237 } else if ($startMessage == $endMessage) {
5cd6702a 238 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
7e343a7d 239 echo "<CENTER>". _("Viewing message") ." <B>$startMessage</B> ($numMessages " . _("total") . ")</CENTER>\n";
0d1b4832 240 echo "</TD></TR>\n";
241 }
26b6c99c 242
f8f9bed9 243 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
5b10f02a 244 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
88c81396 245 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
e452ce9b 246 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
926da13e 247 }
5b10f02a 248 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
88c81396 249 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
250 echo "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
3302d0d4 251 }
5b10f02a 252 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
88c81396 253 echo "<FONT COLOR=\"$color[9]\">"._("Previous")."</FONT> | \n";
e452ce9b 254 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
926da13e 255 }
20db5033 256 echo "</TD></TR>\n";
926da13e 257
68347a84 258 /** The delete and move options */
f8f9bed9 259 echo "<TR><TD BGCOLOR=\"$color[0]\">";
ed4332d1 260
e452ce9b 261 echo "\n\n\n<FORM name=messageList method=post action=\"move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage\">";
3751dc7f 262 do_hook("mailbox_form_before");
4f313fcf 263 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
ed4332d1 264 echo " <TR>\n";
98fe1e9f 265 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
aae41ae9 266 echo " <NOBR><SMALL>". _("Move selected to:") ."</SMALL>";
7ce342dc 267 echo " <TT><SMALL><SELECT NAME=\"targetMailbox\">";
268
9f2215a1 269 $boxes = sqimap_mailbox_list($imapConnection);
7ce342dc 270 for ($i = 0; $i < count($boxes); $i++) {
349ca9f7 271 if ($boxes[$i]["flags"][0] != "noselect" && $boxes[$i]["flags"][1] != "noselect" && $boxes[$i]["flags"][2] != "noselect") {
272 $box = $boxes[$i]["unformatted"];
273 $box2 = replace_spaces($boxes[$i]["formatted"]);
274 echo " <OPTION VALUE=\"$box\">$box2\n";
275 }
dd88d31f 276 }
7ce342dc 277 echo " </SELECT></SMALL></TT>";
aae41ae9 278 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"". _("Move") ."\"></SMALL></NOBR>\n";
ed4332d1 279
280 echo " </TD>\n";
7ce342dc 281 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
aae41ae9 282 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\">&nbsp;". _("checked messages") ."</SMALL></NOBR>\n";
ed4332d1 283 echo " </TD>";
284 echo " </TR>\n";
285
ed4332d1 286 echo "</TABLE>\n\n\n";
aa4c3749 287 echo "</TD></TR>";
288
f8f9bed9 289 echo "<TR><TD BGCOLOR=\"$color[0]\">";
98fe1e9f 290 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[0]\">";
f8f9bed9 291 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
be8e07f8 292
8e265988 293 for ($i=1; $i <= count($index_order); $i++) {
294 switch ($index_order[$i]) {
295 case 1: # checkbox
296 echo " <TD WIDTH=1%><B>&nbsp;</B></TD>";
297 break;
298 case 2: # from
299 if ($mailbox == $sent_folder)
300 echo " <TD WIDTH=30%><B>". _("To") ."</B>";
301 else
302 echo " <TD WIDTH=30%><B>". _("From") ."</B>";
303
304 if ($sort == 2)
305 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";
306 else if ($sort == 3)
307 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";
308 else
309 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";
310 break;
311 case 3: # date
312 echo " <TD nowrap WIDTH=1%><B>". _("Date") ."</B>";
313 if ($sort == 0)
314 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";
315 else if ($sort == 1)
316 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";
317 else
318 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";
319 break;
320 case 4: # subject
321 echo " <TD WIDTH=%><B>". _("Subject") ."</B>\n";
322 if ($sort == 4)
323 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";
324 else if ($sort == 5)
325 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";
326 else
327 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";
328 break;
329 case 5: # flags
330 echo " <TD WIDTH=1%>&nbsp;</TD>\n";
331 break;
332 case 6: # size
fde32e3f 333 echo " <TD WIDTH=1%><b>" . _("Size")."</b></TD>\n";
8e265988 334 break;
335 }
336 }
926da13e 337 echo "</TR>";
338
8e265988 339
d29aac0e 340
926da13e 341 // loop through and display the info for each message.
aa4c3749 342 $t = 0; // $t is used for the checkbox number
4c2d69ac 343 if ($numMessages == 0) { // if there's no messages in this folder
9988d19e 344 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=5><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp;</CENTER></TD></TR>";
4c2d69ac 345 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
a37f3771 346 $i = $startMessage;
af9404d7 347 reset($msort);
348 do {
349 $key = key($msort);
350 next($msort);
351 $k++;
352 } while (isset ($key) && ($k < $i));
1809bad8 353 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, 0, 0);
4c2d69ac 354 } else {
5b6ae78a 355 $i = $startMessage;
356 reset($msort);
357 do {
358 $key = key($msort);
359 next($msort);
360 $k++;
361 } while (isset ($key) && ($k < $i));
362
363 do {
1809bad8 364 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, 0, 0);
5b6ae78a 365 $key = key($msort);
4c2d69ac 366 $t++;
5b6ae78a 367 $i++;
368 next($msort);
369 } while ($i < ($endMessage+1));
926da13e 370 }
68347a84 371 echo "</FORM></TABLE>";
aa4c3749 372
68347a84 373 echo "</TABLE>\n";
4c2d69ac 374 echo "</TD></TR>\n";
375
f8f9bed9 376 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
20db5033 377 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
88c81396 378 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Previous") . "</A> | \n";
e452ce9b 379 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Next") . "</A>\n";
20db5033 380 }
381 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
88c81396 382 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Previous") . "</A> | \n";
aae41ae9 383 echo "<FONT COLOR=\"$color[9]\">" . _("Next") . "</FONT>\n";
20db5033 384 }
385 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
88c81396 386 echo "<FONT COLOR=\"$color[9]\">" . _("Previous"). "</FONT> | \n";
e452ce9b 387 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Next") . "</A>\n";
20db5033 388 }
623332f3 389 echo "</TD></TR></table>"; /** End of message-list table */
6b638171 390
391 do_hook("mailbox_index_after");
3302d0d4 392 }
26b6c99c 393?>