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