Assigned myself to add the option of how many messages to display on the index
[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
7151188f 13 function printMessageInfo($imapConnection, $t, $msg, $mailbox, $sort, $startMessage) {
14 //require ("../config/config.php");
9f2215a1 15 global $color;
d92b6f31 16
7151188f 17 $senderName = $msg["FROM"];
05207a68 18 $urlMailbox = urlencode($mailbox);
7151188f 19 $subject = trim(stripslashes($msg["SUBJECT"]));
926da13e 20 echo "<TR>\n";
7151188f 21
22 if ($msg["FLAG_FLAGGED"] == true) { $flag = "<font color=$color[2]>"; $flag_end = "</font>"; }
23 if ($msg["FLAG_SEEN"] == false) { $bold = "<b>"; $bold_end = "</b>"; }
24 if ($msg["FLAG_ANSWERED"] == true) { $ans = "&nbsp;[A]"; }
25
26 echo " <td width=1% align=center><input type=checkbox name=\"msg[$t]\" value=$i></TD>\n";
27 echo " <td>$bold$flag$senderName$flag_end$bold_end</td>\n";
28 echo " <td nowrap width=1%><center>$bold$flag".$msg["DATE_STRING"]."$flag_end$bold_end</center></td>\n";
9f2215a1 29 echo " <td>$bold<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&sort=$sort&startMessage=$startMessage&show_more=0\">$flag$subject$flag_end</a>$ans$bold_end</td>\n";
7151188f 30
31 echo "</tr>\n";
926da13e 32 }
33
34 /**
35 ** This function loops through a group of messages in the mailbox and shows them
36 **/
d3cdb279 37 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color) {
7ce342dc 38 include ("../config/config.php");
61a4ac35 39
d29aac0e 40 if ($numMessages >= 1) {
41 for ($q = 0; $q < $numMessages; $q++) {
42 sqimap_get_small_header ($imapConnection, $q+1, $f, $s, $d);
43 $from[$q] = $f;
44 $date[$q] = $d;
45 $subject[$q] = $s;
e5b8fc82 46 $flags[$q] = sqimap_get_flags ($imapConnection, $q+1);
d29aac0e 47 }
3e054c43 48 }
49
50 $j = 0;
51 while ($j < $numMessages) {
0e919368 52 $date[$j] = ereg_replace(" ", " ", $date[$j]);
53 $tmpdate = explode(" ", trim($date[$j]));
54
55 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
0f1835f3 56 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
3e054c43 57 $messages[$j]["ID"] = $j+1;
2e434774 58 $messages[$j]["FROM"] = decodeHeader($from[$j]);
59 $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
926da13e 60
3e054c43 61 $num = 0;
5e90d34a 62 while ($num < count($flags[$j])) {
63 if ($flags[$j][$num] == "Deleted") {
5b10f02a 64 $messages[$j]["FLAG_DELETED"] = true;
65 }
5e90d34a 66 else if ($flags[$j][$num] == "Answered") {
5b10f02a 67 $messages[$j]["FLAG_ANSWERED"] = true;
68 }
5e90d34a 69 else if ($flags[$j][$num] == "Seen") {
5b10f02a 70 $messages[$j]["FLAG_SEEN"] = true;
71 }
7151188f 72 else if ($flags[$j][$num] == "Flagged") {
73 $messages[$j]["FLAG_FLAGGED"] = true;
74 }
3e054c43 75 $num++;
3302d0d4 76 }
5b10f02a 77 $j++;
78 }
79
80 /** Find and remove the ones that are deleted */
3e054c43 81 $i = 0;
82 $j = 0;
83 while ($j < $numMessages) {
5b10f02a 84 if ($messages[$j]["FLAG_DELETED"] == true) {
85 $j++;
86 continue;
87 }
7151188f 88 $msgs[$i] = $messages[$j];
e550d551 89
5b10f02a 90 $i++;
3302d0d4 91 $j++;
92 }
93
3e054c43 94 $numMessages = $i;
926da13e 95
4c2d69ac 96 // There's gotta be messages in the array for it to sort them.
97 if ($numMessages > 0) {
0e919368 98 /** 0 = Date (up) 4 = Subject (up)
99 ** 1 = Date (dn) 5 = Subject (dn)
100 ** 2 = Name (up)
101 ** 3 = Name (dn)
102 **/
5e90d34a 103
4c2d69ac 104 if ($sort == 0)
105 $msgs = ary_sort($msgs, "TIME_STAMP", -1);
0e919368 106 else if ($sort == 1)
4c2d69ac 107 $msgs = ary_sort($msgs, "TIME_STAMP", 1);
0e919368 108 else {
5e90d34a 109
0e919368 110 $original = $msgs;
111 $i = 0;
112 while ($i < count($msgs)) {
113 $msgs[$i]["FROM"] = strtolower($msgs[$i]["FROM"]);
114 $msgs[$i]["SUBJECT"] = strtolower($msgs[$i]["SUBJECT"]);
115 $i++;
116 }
117
118 if ($sort == 2)
119 $msgs = ary_sort($msgs, "FROM", -1);
120 else if ($sort == 3)
121 $msgs = ary_sort($msgs, "FROM", 1);
122 else if ($sort == 4)
123 $msgs = ary_sort($msgs, "SUBJECT", -1);
124 else if ($sort == 5)
125 $msgs = ary_sort($msgs, "SUBJECT", 1);
126 else
127 $msgs = ary_sort($msgs, "TIME_STAMP", -1);
128
129 $i = 0;
130 while ($i < count($msgs)) {
131 $j = 0;
5e90d34a 132 $loop = true;
0e919368 133 while ($j < count($original)) {
134 if ($msgs[$i]["ID"] == $original[$j]["ID"]) {
135 $msgs[$i]["FROM"] = $original[$j]["FROM"];
136 $msgs[$i]["SUBJECT"] = $original[$j]["SUBJECT"];
5e90d34a 137
138 // exit out of this loop if we find the thing.
139 $j = count($original) + 1;
0e919368 140 }
141 $j++;
142 }
143 $i++;
144 }
145 }
4c2d69ac 146 }
926da13e 147
9f2215a1 148// session_register("messages");
149// $messages = serialize($msgs);
150
151 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $mailbox, $sort, $color);
152 }
153
154 // generic function to convert the msgs array into an HTML table
155 function displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $mailbox, $sort, $color) {
156 // do a check to see if the config stuff has already been included or not
157 if (!isset($imapServerAddress))
158 include("../config/config.php");
159
160 // if cache isn't already set, do it now
161// if (!session_is_registered("messages"))
162// session_register("messages");
163
926da13e 164 if ($startMessage + 24 < $numMessages) {
926da13e 165 $endMessage = $startMessage + 24;
166 } else {
926da13e 167 $endMessage = $numMessages;
168 }
169
5b10f02a 170 $nextGroup = $startMessage + 25;
926da13e 171 $prevGroup = $startMessage - 25;
20db5033 172 $urlMailbox = urlencode($mailbox);
926da13e 173
20db5033 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>";
926da13e 176
0d1b4832 177 if ($startMessage < $endMessage) {
f8f9bed9 178 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
aae41ae9 179 echo "<CENTER>". _("Viewing messages ") ."<B>$startMessage</B>". _(" to ") ."<B>$endMessage</B> ($numMessages total)</CENTER>\n";
0d1b4832 180 echo "</TD></TR>\n";
181 } else if ($startMessage == $endMessage) {
f8f9bed9 182 echo "<TR BGCOLOR=\"$color[4]>\"TD>";
aae41ae9 183 echo "<CENTER>". _("Viewing message ") ."<B>$startMessage</B> ($numMessages ". _("total") .")</CENTER>\n";
0d1b4832 184 echo "</TD></TR>\n";
185 }
26b6c99c 186
f8f9bed9 187 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
5b10f02a 188 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
9f2215a1 189 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A>\n";
190 echo "<A HREF=\"right_main.php?use_mailbox_cache=1sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
926da13e 191 }
5b10f02a 192 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
9f2215a1 193 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A>\n";
aae41ae9 194 echo "<FONT COLOR=\"$color[9]\">Next</FONT>\n";
3302d0d4 195 }
5b10f02a 196 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
aae41ae9 197 echo "<FONT COLOR=\"$color[9]\">Previous</FONT>\n";
9f2215a1 198 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
926da13e 199 }
20db5033 200 echo "</TD></TR>\n";
926da13e 201
68347a84 202 /** The delete and move options */
f8f9bed9 203 echo "<TR><TD BGCOLOR=\"$color[0]\">";
ed4332d1 204
9f2215a1 205 echo "\n\n\n<FORM name=messageList method=post action=\"move_messages.php?msg=$msg&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage\">";
7ce342dc 206 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0>\n";
ed4332d1 207 echo " <TR>\n";
7ce342dc 208 echo " <TD WIDTH=60% ALIGN=LEFT>\n";
aae41ae9 209 echo " <NOBR><SMALL>". _("Move selected to:") ."</SMALL>";
7ce342dc 210 echo " <TT><SMALL><SELECT NAME=\"targetMailbox\">";
211
9f2215a1 212 $boxes = sqimap_mailbox_list($imapConnection);
7ce342dc 213 for ($i = 0; $i < count($boxes); $i++) {
dd88d31f 214 $use_folder = true;
215 for ($p = 0; $p < count($special_folders); $p++) {
d29aac0e 216 if ($boxes[$i]["unformatted"] == $special_folders[0]) {
7ce342dc 217 $use_folder = true;
d29aac0e 218 } else if ($boxes[$i]["unformatted"] == $special_folders[$p]) {
dd88d31f 219 $use_folder = false;
d29aac0e 220 } else if (substr($boxes[$i]["unformatted"], 0, strlen($trash_folder)) == $trash_folder) {
dd88d31f 221 $use_folder = false;
222 }
223 }
7ce342dc 224 if ($use_folder == true) {
d29aac0e 225 $box = $boxes[$i]["unformatted"];
226 $box2 = replace_spaces($boxes[$i]["formatted"]);
7ce342dc 227 echo " <OPTION VALUE=\"$box\">$box2\n";
228 }
dd88d31f 229 }
7ce342dc 230 echo " </SELECT></SMALL></TT>";
aae41ae9 231 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"". _("Move") ."\"></SMALL></NOBR>\n";
ed4332d1 232
233 echo " </TD>\n";
7ce342dc 234 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
aae41ae9 235 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\">&nbsp;". _("checked messages") ."</SMALL></NOBR>\n";
ed4332d1 236 echo " </TD>";
237 echo " </TR>\n";
238
ed4332d1 239 echo "</TABLE>\n\n\n";
aa4c3749 240 echo "</TD></TR>";
241
f8f9bed9 242 echo "<TR><TD BGCOLOR=\"$color[0]\">";
243 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[4]\">";
244 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
aae41ae9 245 echo " <TD WIDTH=5%><B>&nbsp;</B></TD>";
0e919368 246 /** FROM HEADER **/
aae41ae9 247 echo " <TD WIDTH=25%><B>". _("From") ."</B>";
0e919368 248 if ($sort == 2)
9f2215a1 249 echo " <A HREF=\"right_main.php?sort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
0e919368 250 else if ($sort == 3)
9f2215a1 251 echo " <A HREF=\"right_main.php?sort=2&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
0e919368 252 else
9f2215a1 253 echo " <A HREF=\"right_main.php?sort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
0e919368 254 /** DATE HEADER **/
aae41ae9 255 echo " <TD WIDTH=15%><B>". _("Date") ."</B>";
926da13e 256 if ($sort == 0)
9f2215a1 257 echo " <A HREF=\"right_main.php?sort=1&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
0e919368 258 else if ($sort == 1)
9f2215a1 259 echo " <A HREF=\"right_main.php?sort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
0e919368 260 else
9f2215a1 261 echo " <A HREF=\"right_main.php?sort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
0e919368 262 /** SUBJECT HEADER **/
aae41ae9 263 echo " <TD WIDTH=%><B>". _("Subject") ."</B>\n";
0e919368 264 if ($sort == 4)
9f2215a1 265 echo " <A HREF=\"right_main.php?sort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
0e919368 266 else if ($sort == 5)
9f2215a1 267 echo " <A HREF=\"right_main.php?sort=4&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
0e919368 268 else
9f2215a1 269 echo " <A HREF=\"right_main.php?sort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
926da13e 270 echo "</TR>";
271
d29aac0e 272
926da13e 273 // loop through and display the info for each message.
aa4c3749 274 $t = 0; // $t is used for the checkbox number
4c2d69ac 275 if ($numMessages == 0) { // if there's no messages in this folder
d29aac0e 276 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=4><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp</CENTER></TD></TR>";
4c2d69ac 277 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
3e054c43 278 $i = $startMessage - 1;
7151188f 279 printMessageInfo($imapConnection, $t, $msgs[$i], $mailbox, $sort, $startMessage);
4c2d69ac 280 } else {
281 for ($i = $startMessage - 1;$i <= $endMessage - 1; $i++) {
7151188f 282 printMessageInfo($imapConnection, $t, $msgs[$i], $mailbox, $sort, $startMessage);
4c2d69ac 283 $t++;
284 }
926da13e 285 }
68347a84 286 echo "</FORM></TABLE>";
aa4c3749 287
68347a84 288 echo "</TABLE>\n";
4c2d69ac 289 echo "</TD></TR>\n";
290
f8f9bed9 291 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
20db5033 292 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
9f2215a1 293 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Previous") . "</A>\n";
294 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Next") . "</A>\n";
20db5033 295 }
296 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
9f2215a1 297 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Previous") . "</A>\n";
aae41ae9 298 echo "<FONT COLOR=\"$color[9]\">" . _("Next") . "</FONT>\n";
20db5033 299 }
300 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
aae41ae9 301 echo "<FONT COLOR=\"$color[9]\">Previous</FONT>\n";
9f2215a1 302 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Next") . "</A>\n";
20db5033 303 }
926da13e 304 echo "</TD></TR></TABLE>"; /** End of message-list table */
3302d0d4 305 }
26b6c99c 306?>