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