added step for copying config_default.php to config.php
[squirrelmail.git] / functions / mailbox_display.php
CommitLineData
3302d0d4 1<?
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 **/
10
8467bf00 11 function printMessageInfo($imapConnection, $t, $i, $from, $subject, $dateString, $answered, $seen, $mailbox, $sort, $startMessage) {
d92b6f31 12 require ("../config/config.php");
13
3302d0d4 14 $senderName = getSenderName($from);
05207a68 15 $urlMailbox = urlencode($mailbox);
e39d73e5 16 $subject = trim(stripslashes($subject));
926da13e 17 echo "<TR>\n";
18 if ($seen == false) {
4c2d69ac 19 echo " <TD><FONT FACE=\"Arial,Helvetica\"><nobr><B><input type=checkbox name=\"msg[$t]\" value=$i></B></nobr></FONT></TD>\n";
926da13e 20 echo " <TD><FONT FACE=\"Arial,Helvetica\"><B>$senderName</B></FONT></TD>\n";
21 echo " <TD><CENTER><B><FONT FACE=\"Arial,Helvetica\">$dateString</FONT></B></CENTER></TD>\n";
2844086d 22 echo " <TD><FONT FACE=\"Arial,Helvetica\"><B><A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$i&sort=$sort&startMessage=$startMessage&show_more=0\">$subject</A></B></FONT></TD>\n";
926da13e 23 } else {
4c2d69ac 24 echo " <TD><FONT FACE=\"Arial,Helvetica\"><nobr><input type=checkbox name=\"msg[$t]\" value=$i></nobr></FONT></TD>\n";
926da13e 25 echo " <TD><FONT FACE=\"Arial,Helvetica\">$senderName</FONT></TD>\n";
26 echo " <TD><FONT FACE=\"Arial,Helvetica\"><CENTER>$dateString</CENTER></FONT></TD>\n";
2844086d 27 echo " <TD><FONT FACE=\"Arial,Helvetica\"><A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$i&sort=$sort&startMessage=$startMessage&show_more=0\">$subject</A></FONT></TD>\n";
926da13e 28 }
29 echo "</TR>\n";
30 }
31
32 /**
33 ** This function loops through a group of messages in the mailbox and shows them
34 **/
d3cdb279 35 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color) {
7ce342dc 36 include ("../config/config.php");
61a4ac35 37
3e054c43 38 if (1 <= $numMessages) {
39 getMessageHeaders($imapConnection, 1, $numMessages, $from, $subject, $date);
40 }
41
42 $j = 0;
43 while ($j < $numMessages) {
0e919368 44 $date[$j] = ereg_replace(" ", " ", $date[$j]);
45 $tmpdate = explode(" ", trim($date[$j]));
46
47 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
0f1835f3 48 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
3e054c43 49 $messages[$j]["ID"] = $j+1;
0e919368 50 $messages[$j]["FROM"] = getSenderName($from[$j]);
3e054c43 51 $messages[$j]["SUBJECT"] = $subject[$j];
5b10f02a 52 $messages[$j]["FLAG_DELETED"] = false;
53 $messages[$j]["FLAG_ANSWERED"] = false;
54 $messages[$j]["FLAG_SEEN"] = false;
926da13e 55
3e054c43 56 $num = 0;
57 getMessageFlags($imapConnection, $j+1, $flags);
58 while ($num < count($flags)) {
59 if ($flags[$num] == "Deleted") {
5b10f02a 60 $messages[$j]["FLAG_DELETED"] = true;
61 }
3e054c43 62 else if ($flags[$num] == "Answered") {
5b10f02a 63 $messages[$j]["FLAG_ANSWERED"] = true;
64 }
3e054c43 65 else if ($flags[$num] == "Seen") {
5b10f02a 66 $messages[$j]["FLAG_SEEN"] = true;
67 }
3e054c43 68 $num++;
3302d0d4 69 }
5b10f02a 70 $j++;
71 }
72
73 /** Find and remove the ones that are deleted */
3e054c43 74 $i = 0;
75 $j = 0;
76 while ($j < $numMessages) {
5b10f02a 77 if ($messages[$j]["FLAG_DELETED"] == true) {
78 $j++;
79 continue;
80 }
81 $msgs[$i]["TIME_STAMP"] = $messages[$j]["TIME_STAMP"];
82 $msgs[$i]["DATE_STRING"] = $messages[$j]["DATE_STRING"];
83 $msgs[$i]["ID"] = $messages[$j]["ID"];
84 $msgs[$i]["FROM"] = $messages[$j]["FROM"];
85 $msgs[$i]["SUBJECT"] = $messages[$j]["SUBJECT"];
86 $msgs[$i]["FLAG_DELETED"] = $messages[$j]["FLAG_DELETED"];
87 $msgs[$i]["FLAG_ANSWERED"] = $messages[$j]["FLAG_ANSWERED"];
88 $msgs[$i]["FLAG_SEEN"] = $messages[$j]["FLAG_SEEN"];
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 **/
4c2d69ac 103 if ($sort == 0)
104 $msgs = ary_sort($msgs, "TIME_STAMP", -1);
0e919368 105 else if ($sort == 1)
4c2d69ac 106 $msgs = ary_sort($msgs, "TIME_STAMP", 1);
0e919368 107 else {
108 $original = $msgs;
109 $i = 0;
110 while ($i < count($msgs)) {
111 $msgs[$i]["FROM"] = strtolower($msgs[$i]["FROM"]);
112 $msgs[$i]["SUBJECT"] = strtolower($msgs[$i]["SUBJECT"]);
113 $i++;
114 }
115
116 if ($sort == 2)
117 $msgs = ary_sort($msgs, "FROM", -1);
118 else if ($sort == 3)
119 $msgs = ary_sort($msgs, "FROM", 1);
120 else if ($sort == 4)
121 $msgs = ary_sort($msgs, "SUBJECT", -1);
122 else if ($sort == 5)
123 $msgs = ary_sort($msgs, "SUBJECT", 1);
124 else
125 $msgs = ary_sort($msgs, "TIME_STAMP", -1);
126
127 $i = 0;
128 while ($i < count($msgs)) {
129 $j = 0;
130 while ($j < count($original)) {
131 if ($msgs[$i]["ID"] == $original[$j]["ID"]) {
132 $msgs[$i]["FROM"] = $original[$j]["FROM"];
133 $msgs[$i]["SUBJECT"] = $original[$j]["SUBJECT"];
134 }
135 $j++;
136 }
137 $i++;
138 }
139 }
4c2d69ac 140 }
926da13e 141
142 if ($startMessage + 24 < $numMessages) {
926da13e 143 $endMessage = $startMessage + 24;
144 } else {
926da13e 145 $endMessage = $numMessages;
146 }
147
5b10f02a 148 $nextGroup = $startMessage + 25;
926da13e 149 $prevGroup = $startMessage - 25;
20db5033 150 $urlMailbox = urlencode($mailbox);
926da13e 151
e550d551 152
20db5033 153 /** This is the beginning of the message list table. It wraps around all messages */
154 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1>";
926da13e 155
0d1b4832 156 if ($startMessage < $endMessage) {
f8f9bed9 157 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
16365011 158 echo "<CENTER><FONT FACE=\"Arial,Helvetica\">". _("Viewing messages ") ."<B>$startMessage</B>". _(" to ") ."<B>$endMessage</B> ($numMessages total)</FONT></CENTER>\n";
0d1b4832 159 echo "</TD></TR>\n";
160 } else if ($startMessage == $endMessage) {
f8f9bed9 161 echo "<TR BGCOLOR=\"$color[4]>\"TD>";
16365011 162 echo "<CENTER><FONT FACE=\"Arial,Helvetica\">". _("Viewing message ") ."<B>$startMessage</B> ($numMessages ". _("total") .")</FONT></CENTER>\n";
0d1b4832 163 echo "</TD></TR>\n";
164 }
26b6c99c 165
f8f9bed9 166 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
5b10f02a 167 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
16365011 168 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">". _("Previous") ."</FONT></A>\n";
169 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">". _("Next") ."</FONT></A>\n";
926da13e 170 }
5b10f02a 171 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
16365011 172 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">". _("Previous") ."</FONT></A>\n";
f8f9bed9 173 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=\"$color[9]\">Next</FONT>\n";
3302d0d4 174 }
5b10f02a 175 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
f8f9bed9 176 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=\"$color[9]\">Previous</FONT>\n";
16365011 177 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">". _("Next") ."</FONT></A>\n";
926da13e 178 }
20db5033 179 echo "</TD></TR>\n";
926da13e 180
68347a84 181 /** The delete and move options */
f8f9bed9 182 echo "<TR><TD BGCOLOR=\"$color[0]\">";
ed4332d1 183
184 echo "\n\n\n<FORM name=messageList method=post action=\"move_messages.php?msg=$msg&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage\">";
7ce342dc 185 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0>\n";
ed4332d1 186 echo " <TR>\n";
7ce342dc 187 echo " <TD WIDTH=60% ALIGN=LEFT>\n";
16365011 188 echo " <NOBR><FONT FACE=\"Arial,Helvetica\"><SMALL>". _("Move selected to:") ."</SMALL></FONT>";
7ce342dc 189 echo " <TT><SMALL><SELECT NAME=\"targetMailbox\">";
190
191 getFolderList($imapConnection, $boxes);
192 for ($i = 0; $i < count($boxes); $i++) {
dd88d31f 193 $use_folder = true;
194 for ($p = 0; $p < count($special_folders); $p++) {
7ce342dc 195 if ($boxes[$i]["UNFORMATTED"] == $special_folders[0]) {
196 $use_folder = true;
197 } else if ($boxes[$i]["UNFORMATTED"] == $special_folders[$p]) {
dd88d31f 198 $use_folder = false;
7ce342dc 199 } else if (substr($boxes[$i]["UNFORMATTED"], 0, strlen($trash_folder)) == $trash_folder) {
dd88d31f 200 $use_folder = false;
201 }
202 }
7ce342dc 203 if ($use_folder == true) {
204 $box = $boxes[$i]["UNFORMATTED"];
205 $box2 = $boxes[$i]["FORMATTED"];
206 echo " <OPTION VALUE=\"$box\">$box2\n";
207 }
dd88d31f 208 }
7ce342dc 209 echo " </SELECT></SMALL></TT>";
16365011 210 echo " <FONT FACE=\"Arial,Helvetica\"><SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"". _("Move") ."\"></SMALL></FONT></NOBR>\n";
ed4332d1 211
212 echo " </TD>\n";
7ce342dc 213 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
16365011 214 echo " <NOBR><FONT FACE=\"Arial,Helvetica\"><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\">&nbsp;". _("checked messages") ."</SMALL></FONT></NOBR>\n";
ed4332d1 215 echo " </TD>";
216 echo " </TR>\n";
217
ed4332d1 218 echo "</TABLE>\n\n\n";
aa4c3749 219 echo "</TD></TR>";
220
f8f9bed9 221 echo "<TR><TD BGCOLOR=\"$color[0]\">";
222 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[4]\">";
223 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
7ce342dc 224 echo " <TD WIDTH=5%><FONT FACE=\"Arial,Helvetica\"><B>&nbsp;</B></FONT></TD>";
0e919368 225 /** FROM HEADER **/
16365011 226 echo " <TD WIDTH=25%><FONT FACE=\"Arial,Helvetica\"><B>". _("From") ."</B></FONT>";
0e919368 227 if ($sort == 2)
228 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";
229 else if ($sort == 3)
230 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";
231 else
232 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";
233 /** DATE HEADER **/
16365011 234 echo " <TD WIDTH=15%><FONT FACE=\"Arial,Helvetica\"><B>". _("Date") ."</B></FONT>";
926da13e 235 if ($sort == 0)
a09387f4 236 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 237 else if ($sort == 1)
a09387f4 238 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 239 else
240 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";
241 /** SUBJECT HEADER **/
16365011 242 echo " <TD WIDTH=*><FONT FACE=\"Arial,Helvetica\"><B>". _("Subject") ."</B></FONT>\n";
0e919368 243 if ($sort == 4)
7ce342dc 244 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 245 else if ($sort == 5)
246 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";
247 else
248 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 249 echo "</TR>";
250
251 // loop through and display the info for each message.
aa4c3749 252 $t = 0; // $t is used for the checkbox number
4c2d69ac 253 if ($numMessages == 0) { // if there's no messages in this folder
f8f9bed9 254 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=4><CENTER><BR><B>THIS FOLDER IS EMPTY</B><BR>&nbsp</CENTER></TD></TR>";
4c2d69ac 255 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
3e054c43 256 $i = $startMessage - 1;
8467bf00 257 printMessageInfo($imapConnection, $t, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"], $mailbox, $sort, $startMessage);
4c2d69ac 258 } else {
259 for ($i = $startMessage - 1;$i <= $endMessage - 1; $i++) {
8467bf00 260 printMessageInfo($imapConnection, $t, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"], $mailbox, $sort, $startMessage);
4c2d69ac 261 $t++;
262 }
926da13e 263 }
68347a84 264 echo "</FORM></TABLE>";
aa4c3749 265
68347a84 266 echo "</TABLE>\n";
4c2d69ac 267 echo "</TD></TR>\n";
268
f8f9bed9 269 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
20db5033 270 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
32c7898c 271 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">" . _("Previous") . "</FONT></A>\n";
272 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">" . _("Next") . "</FONT></A>\n";
20db5033 273 }
274 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
32c7898c 275 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">" . _("Previous") . "</FONT></A>\n";
276 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=\"$color[9]\">" . _("Next") . "</FONT>\n";
20db5033 277 }
278 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
f8f9bed9 279 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=\"$color[9]\">Previous</FONT>\n";
32c7898c 280 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">" . _("Next") . "</FONT></A>\n";
20db5033 281 }
926da13e 282 echo "</TD></TR></TABLE>"; /** End of message-list table */
3302d0d4 283 }
26b6c99c 284?>