mailbox_display.php 17 KB

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