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