added step for copying config_default.php to config.php
[squirrelmail.git] / functions / mailbox_display.php
1 <?
2
3 /**
4 ** mailbox_display.php
5 **
6 ** This contains functions that display mailbox information, such as the
7 ** table row that has sender, date, subject, etc...
8 **
9 **/
10
11 function printMessageInfo($imapConnection, $t, $i, $from, $subject, $dateString, $answered, $seen, $mailbox, $sort, $startMessage) {
12 require ("../config/config.php");
13
14 $senderName = getSenderName($from);
15 $urlMailbox = urlencode($mailbox);
16 $subject = trim(stripslashes($subject));
17 echo "<TR>\n";
18 if ($seen == false) {
19 echo " <TD><FONT FACE=\"Arial,Helvetica\"><nobr><B><input type=checkbox name=\"msg[$t]\" value=$i></B></nobr></FONT></TD>\n";
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";
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";
23 } else {
24 echo " <TD><FONT FACE=\"Arial,Helvetica\"><nobr><input type=checkbox name=\"msg[$t]\" value=$i></nobr></FONT></TD>\n";
25 echo " <TD><FONT FACE=\"Arial,Helvetica\">$senderName</FONT></TD>\n";
26 echo " <TD><FONT FACE=\"Arial,Helvetica\"><CENTER>$dateString</CENTER></FONT></TD>\n";
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";
28 }
29 echo "</TR>\n";
30 }
31
32 /**
33 ** This function loops through a group of messages in the mailbox and shows them
34 **/
35 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color) {
36 include ("../config/config.php");
37
38 if (1 <= $numMessages) {
39 getMessageHeaders($imapConnection, 1, $numMessages, $from, $subject, $date);
40 }
41
42 $j = 0;
43 while ($j < $numMessages) {
44 $date[$j] = ereg_replace(" ", " ", $date[$j]);
45 $tmpdate = explode(" ", trim($date[$j]));
46
47 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
48 $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
49 $messages[$j]["ID"] = $j+1;
50 $messages[$j]["FROM"] = getSenderName($from[$j]);
51 $messages[$j]["SUBJECT"] = $subject[$j];
52 $messages[$j]["FLAG_DELETED"] = false;
53 $messages[$j]["FLAG_ANSWERED"] = false;
54 $messages[$j]["FLAG_SEEN"] = false;
55
56 $num = 0;
57 getMessageFlags($imapConnection, $j+1, $flags);
58 while ($num < count($flags)) {
59 if ($flags[$num] == "Deleted") {
60 $messages[$j]["FLAG_DELETED"] = true;
61 }
62 else if ($flags[$num] == "Answered") {
63 $messages[$j]["FLAG_ANSWERED"] = true;
64 }
65 else if ($flags[$num] == "Seen") {
66 $messages[$j]["FLAG_SEEN"] = true;
67 }
68 $num++;
69 }
70 $j++;
71 }
72
73 /** Find and remove the ones that are deleted */
74 $i = 0;
75 $j = 0;
76 while ($j < $numMessages) {
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"];
89
90 $i++;
91 $j++;
92 }
93
94 $numMessages = $i;
95
96 // There's gotta be messages in the array for it to sort them.
97 if ($numMessages > 0) {
98 /** 0 = Date (up) 4 = Subject (up)
99 ** 1 = Date (dn) 5 = Subject (dn)
100 ** 2 = Name (up)
101 ** 3 = Name (dn)
102 **/
103 if ($sort == 0)
104 $msgs = ary_sort($msgs, "TIME_STAMP", -1);
105 else if ($sort == 1)
106 $msgs = ary_sort($msgs, "TIME_STAMP", 1);
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 }
140 }
141
142 if ($startMessage + 24 < $numMessages) {
143 $endMessage = $startMessage + 24;
144 } else {
145 $endMessage = $numMessages;
146 }
147
148 $nextGroup = $startMessage + 25;
149 $prevGroup = $startMessage - 25;
150 $urlMailbox = urlencode($mailbox);
151
152
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>";
155
156 if ($startMessage < $endMessage) {
157 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
158 echo "<CENTER><FONT FACE=\"Arial,Helvetica\">". _("Viewing messages ") ."<B>$startMessage</B>". _(" to ") ."<B>$endMessage</B> ($numMessages total)</FONT></CENTER>\n";
159 echo "</TD></TR>\n";
160 } else if ($startMessage == $endMessage) {
161 echo "<TR BGCOLOR=\"$color[4]>\"TD>";
162 echo "<CENTER><FONT FACE=\"Arial,Helvetica\">". _("Viewing message ") ."<B>$startMessage</B> ($numMessages ". _("total") .")</FONT></CENTER>\n";
163 echo "</TD></TR>\n";
164 }
165
166 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
167 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
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";
170 }
171 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
172 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">". _("Previous") ."</FONT></A>\n";
173 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=\"$color[9]\">Next</FONT>\n";
174 }
175 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
176 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=\"$color[9]\">Previous</FONT>\n";
177 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">". _("Next") ."</FONT></A>\n";
178 }
179 echo "</TD></TR>\n";
180
181 /** The delete and move options */
182 echo "<TR><TD BGCOLOR=\"$color[0]\">";
183
184 echo "\n\n\n<FORM name=messageList method=post action=\"move_messages.php?msg=$msg&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage\">";
185 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0>\n";
186 echo " <TR>\n";
187 echo " <TD WIDTH=60% ALIGN=LEFT>\n";
188 echo " <NOBR><FONT FACE=\"Arial,Helvetica\"><SMALL>". _("Move selected to:") ."</SMALL></FONT>";
189 echo " <TT><SMALL><SELECT NAME=\"targetMailbox\">";
190
191 getFolderList($imapConnection, $boxes);
192 for ($i = 0; $i < count($boxes); $i++) {
193 $use_folder = true;
194 for ($p = 0; $p < count($special_folders); $p++) {
195 if ($boxes[$i]["UNFORMATTED"] == $special_folders[0]) {
196 $use_folder = true;
197 } else if ($boxes[$i]["UNFORMATTED"] == $special_folders[$p]) {
198 $use_folder = false;
199 } else if (substr($boxes[$i]["UNFORMATTED"], 0, strlen($trash_folder)) == $trash_folder) {
200 $use_folder = false;
201 }
202 }
203 if ($use_folder == true) {
204 $box = $boxes[$i]["UNFORMATTED"];
205 $box2 = $boxes[$i]["FORMATTED"];
206 echo " <OPTION VALUE=\"$box\">$box2\n";
207 }
208 }
209 echo " </SELECT></SMALL></TT>";
210 echo " <FONT FACE=\"Arial,Helvetica\"><SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"". _("Move") ."\"></SMALL></FONT></NOBR>\n";
211
212 echo " </TD>\n";
213 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
214 echo " <NOBR><FONT FACE=\"Arial,Helvetica\"><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\">&nbsp;". _("checked messages") ."</SMALL></FONT></NOBR>\n";
215 echo " </TD>";
216 echo " </TR>\n";
217
218 echo "</TABLE>\n\n\n";
219 echo "</TD></TR>";
220
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\">";
224 echo " <TD WIDTH=5%><FONT FACE=\"Arial,Helvetica\"><B>&nbsp;</B></FONT></TD>";
225 /** FROM HEADER **/
226 echo " <TD WIDTH=25%><FONT FACE=\"Arial,Helvetica\"><B>". _("From") ."</B></FONT>";
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 **/
234 echo " <TD WIDTH=15%><FONT FACE=\"Arial,Helvetica\"><B>". _("Date") ."</B></FONT>";
235 if ($sort == 0)
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";
237 else if ($sort == 1)
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";
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 **/
242 echo " <TD WIDTH=*><FONT FACE=\"Arial,Helvetica\"><B>". _("Subject") ."</B></FONT>\n";
243 if ($sort == 4)
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";
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";
249 echo "</TR>";
250
251 // loop through and display the info for each message.
252 $t = 0; // $t is used for the checkbox number
253 if ($numMessages == 0) { // if there's no messages in this folder
254 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=4><CENTER><BR><B>THIS FOLDER IS EMPTY</B><BR>&nbsp</CENTER></TD></TR>";
255 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
256 $i = $startMessage - 1;
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);
258 } else {
259 for ($i = $startMessage - 1;$i <= $endMessage - 1; $i++) {
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);
261 $t++;
262 }
263 }
264 echo "</FORM></TABLE>";
265
266 echo "</TABLE>\n";
267 echo "</TD></TR>\n";
268
269 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
270 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
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";
273 }
274 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
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";
277 }
278 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
279 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=\"$color[9]\">Previous</FONT>\n";
280 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">" . _("Next") . "</FONT></A>\n";
281 }
282 echo "</TD></TR></TABLE>"; /** End of message-list table */
283 }
284 ?>