changed where a variable is registered in the session so heavy hard drive IO doesn...
[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 for ($q = 0; $q < $numMessages; $q++) {
48 if ($mailbox == $sent_folder)
49 $hdr = sqimap_get_small_header ($imapConnection, $q+1, true);
50 else
51 $hdr = sqimap_get_small_header ($imapConnection, $q+1, false);
52
53 $from[$q] = $hdr->from;
54 $date[$q] = $hdr->date;
55 $subject[$q] = $hdr->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 session_unregister("msgs");
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 session_register("msgs");
131 }
132
133 // generic function to convert the msgs array into an HTML table
134 function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
135 global $folder_prefix, $sent_folder;
136 global $imapServerAddress;
137
138 // do a check to see if the config stuff has already been included or not
139 // if (!isset($imapServerAddress))
140 // include("../config/config.php");
141
142 // if cache isn't already set, do it now
143 if (!session_is_registered("msgs"))
144 session_register("msgs");
145 if (!session_is_registered("msort"))
146 session_register("msort");
147
148 if ($startMessage + ($show_num - 1) < $numMessages) {
149 $endMessage = $startMessage + ($show_num-1);
150 } else {
151 $endMessage = $numMessages;
152 }
153
154 $nextGroup = $startMessage + $show_num;
155 $prevGroup = $startMessage - $show_num;
156 $urlMailbox = urlencode($mailbox);
157
158 /** This is the beginning of the message list table. It wraps around all messages */
159 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1>";
160
161 if ($startMessage < $endMessage) {
162 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
163 echo "<CENTER>". _("Viewing messages ") ."<B>$startMessage</B>". _(" to ") ."<B>$endMessage</B> ($numMessages total)</CENTER>\n";
164 echo "</TD></TR>\n";
165 } else if ($startMessage == $endMessage) {
166 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
167 echo "<CENTER>". _("Viewing message ") ."<B>$startMessage</B> ($numMessages ". _("total") .")</CENTER>\n";
168 echo "</TD></TR>\n";
169 }
170
171 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
172 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
173 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A>\n";
174 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
175 }
176 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
177 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A>\n";
178 echo "<FONT COLOR=\"$color[9]\">Next</FONT>\n";
179 }
180 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
181 echo "<FONT COLOR=\"$color[9]\">Previous</FONT>\n";
182 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
183 }
184 echo "</TD></TR>\n";
185
186 /** The delete and move options */
187 echo "<TR><TD BGCOLOR=\"$color[0]\">";
188
189 echo "\n\n\n<FORM name=messageList method=post action=\"move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage\">";
190 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0>\n";
191 echo " <TR>\n";
192 echo " <TD WIDTH=60% ALIGN=LEFT>\n";
193 echo " <NOBR><SMALL>". _("Move selected to:") ."</SMALL>";
194 echo " <TT><SMALL><SELECT NAME=\"targetMailbox\">";
195
196 $boxes = sqimap_mailbox_list($imapConnection);
197 for ($i = 0; $i < count($boxes); $i++) {
198 if ($boxes[$i]["flags"][0] != "noselect" && $boxes[$i]["flags"][1] != "noselect" && $boxes[$i]["flags"][2] != "noselect") {
199 $box = $boxes[$i]["unformatted"];
200 $box2 = replace_spaces($boxes[$i]["formatted"]);
201 echo " <OPTION VALUE=\"$box\">$box2\n";
202 }
203 }
204 echo " </SELECT></SMALL></TT>";
205 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"". _("Move") ."\"></SMALL></NOBR>\n";
206
207 echo " </TD>\n";
208 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
209 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\">&nbsp;". _("checked messages") ."</SMALL></NOBR>\n";
210 echo " </TD>";
211 echo " </TR>\n";
212
213 echo "</TABLE>\n\n\n";
214 echo "</TD></TR>";
215
216 echo "<TR><TD BGCOLOR=\"$color[0]\">";
217 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[4]\">";
218 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
219 echo " <TD WIDTH=1%><B>&nbsp;</B></TD>";
220 /** FROM HEADER **/
221 if ($mailbox == $sent_folder)
222 echo " <TD WIDTH=30%><B>". _("To") ."</B>";
223 else
224 echo " <TD WIDTH=30%><B>". _("From") ."</B>";
225
226 if ($sort == 2)
227 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";
228 else if ($sort == 3)
229 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";
230 else
231 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";
232 /** DATE HEADER **/
233 echo " <TD nowrap WIDTH=1%><B>". _("Date") ."</B>";
234 if ($sort == 0)
235 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";
236 else if ($sort == 1)
237 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";
238 else
239 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";
240 echo " <TD WIDTH=1%>&nbsp;</TD>\n";
241 /** SUBJECT HEADER **/
242 echo " <TD WIDTH=%><B>". _("Subject") ."</B>\n";
243 if ($sort == 4)
244 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";
245 else if ($sort == 5)
246 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";
247 else
248 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";
249
250 echo "</TR>";
251
252
253 // loop through and display the info for each message.
254 $t = 0; // $t is used for the checkbox number
255 if ($numMessages == 0) { // if there's no messages in this folder
256 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=5><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp;</CENTER></TD></TR>";
257 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
258 $i = $startMessage - 1;
259 reset($msort);
260 do {
261 $key = key($msort);
262 next($msort);
263 $k++;
264 } while (isset ($key) && ($k < $i));
265 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage);
266 } else {
267 $i = $startMessage;
268 reset($msort);
269 do {
270 $key = key($msort);
271 next($msort);
272 $k++;
273 } while (isset ($key) && ($k < $i));
274
275 do {
276 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage);
277 $key = key($msort);
278 $t++;
279 $i++;
280 next($msort);
281 } while ($i < ($endMessage+1));
282 }
283 echo "</FORM></TABLE>";
284
285 echo "</TABLE>\n";
286 echo "</TD></TR>\n";
287
288 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
289 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
290 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Previous") . "</A>\n";
291 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Next") . "</A>\n";
292 }
293 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
294 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Previous") . "</A>\n";
295 echo "<FONT COLOR=\"$color[9]\">" . _("Next") . "</FONT>\n";
296 }
297 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
298 echo "<FONT COLOR=\"$color[9]\">Previous</FONT>\n";
299 echo "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">" . _("Next") . "</A>\n";
300 }
301 echo "</TD></TR></TABLE>"; /** End of message-list table */
302
303 }
304 ?>