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