mailbox_display.php 16 KB

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