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