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