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