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