mailbox_display.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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. ** $Id$
  9. **/
  10. if (defined('mailbox_display_php'))
  11. return;
  12. define('mailbox_display_php', true);
  13. function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, $where, $what) {
  14. global $checkall;
  15. global $color, $msgs, $msort;
  16. global $sent_folder;
  17. global $message_highlight_list;
  18. global $index_order;
  19. $color_string = $color[4];
  20. if ($GLOBALS['alt_index_colors']) {
  21. if (!isset($GLOBALS["row_count"])) {
  22. $GLOBALS["row_count"] = 0;
  23. }
  24. $GLOBALS["row_count"]++;
  25. if ($GLOBALS["row_count"] % 2) {
  26. if (!isset($color[12])) $color[12] = "#EAEAEA";
  27. $color_string = $color[12];
  28. }
  29. }
  30. $msg = $msgs[$key];
  31. $senderName = sqimap_find_displayable_name($msg['FROM']);
  32. $urlMailbox = urlencode($mailbox);
  33. $subject = processSubject($msg['SUBJECT']);
  34. echo "<TR>\n";
  35. if (isset($msg['FLAG_FLAGGED']) && $msg['FLAG_FLAGGED'] == true)
  36. {
  37. $flag = "<font color=$color[2]>";
  38. $flag_end = '</font>';
  39. }
  40. else
  41. {
  42. $flag = '';
  43. $flag_end = '';
  44. }
  45. if (!isset($msg['FLAG_SEEN']) || $msg['FLAG_SEEN'] == false)
  46. {
  47. $bold = '<b>';
  48. $bold_end = '</b>';
  49. }
  50. else
  51. {
  52. $bold = '';
  53. $bold_end = '';
  54. }
  55. if ($mailbox == $sent_folder)
  56. {
  57. $italic = '<i>';
  58. $italic_end = '</i>';
  59. }
  60. else
  61. {
  62. $italic = '';
  63. $italic_end = '';
  64. }
  65. if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'])
  66. {
  67. $fontstr = "<font color=\"$color[9]\">";
  68. $fontstr_end = '</font>';
  69. }
  70. else
  71. {
  72. $fontstr = '';
  73. $fontstr_end = '';
  74. }
  75. for ($i=0; $i < count($message_highlight_list); $i++) {
  76. if (trim($message_highlight_list[$i]['value']) != '') {
  77. if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
  78. if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) || strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) {
  79. $hlt_color = $message_highlight_list[$i]['color'];
  80. continue;
  81. }
  82. } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
  83. $hlt_color = $message_highlight_list[$i]['color'];
  84. continue;
  85. }
  86. }
  87. }
  88. if (!isset($hlt_color))
  89. $hlt_color = $color_string;
  90. if ($where && $what) {
  91. $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
  92. }
  93. if ($checkall == 1)
  94. $checked = ' checked';
  95. else
  96. $checked = '';
  97. for ($i=1; $i <= count($index_order); $i++) {
  98. switch ($index_order[$i]) {
  99. case 1: # checkbox
  100. echo " <td bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
  101. break;
  102. case 2: # from
  103. echo " <td bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
  104. break;
  105. case 3: # date
  106. echo " <td nowrap bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
  107. break;
  108. case 4: # subject
  109. echo " <td bgcolor=$hlt_color>$bold";
  110. if (! isset($search_stuff)) { $search_stuff = ''; }
  111. echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$startMessage&show_more=0$search_stuff\"";
  112. do_hook("subject_link");
  113. echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
  114. break;
  115. case 5: # flags
  116. $stuff = false;
  117. echo " <td bgcolor=$hlt_color align=center nowrap><b><small>\n";
  118. if (isset($msg['FLAG_ANSWERED']) &&
  119. $msg['FLAG_ANSWERED'] == true) {
  120. echo "A\n";
  121. $stuff = true;
  122. }
  123. if ($msg['TYPE0'] == 'multipart') {
  124. echo "+\n";
  125. $stuff = true;
  126. }
  127. if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
  128. echo "<font color=$color[1]>!</font>\n";
  129. $stuff = true;
  130. }
  131. if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
  132. echo "<font color=\"$color[1]\">D</font>\n";
  133. $stuff = true;
  134. }
  135. if (!$stuff) echo "&nbsp;\n";
  136. echo "</small></b></td>\n";
  137. break;
  138. case 6: # size
  139. echo " <td bgcolor=$hlt_color>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
  140. break;
  141. }
  142. }
  143. echo "</tr>\n";
  144. }
  145. /**
  146. ** This function loops through a group of messages in the mailbox and shows them
  147. **/
  148. function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
  149. global $msgs, $msort;
  150. global $sent_folder;
  151. global $message_highlight_list;
  152. global $auto_expunge;
  153. if ($auto_expunge == true) sqimap_mailbox_expunge($imapConnection, $mailbox, false);
  154. sqimap_mailbox_select($imapConnection, $mailbox);
  155. if (!$use_cache) {
  156. // if it's sorted
  157. if ($numMessages >= 1) {
  158. if ($sort < 6) {
  159. for ($q = 0; $q < $numMessages; $q++) {
  160. if($mailbox == $sent_folder)
  161. $hdr = sqimap_get_small_header ($imapConnection, $q+1, true);
  162. else
  163. $hdr = sqimap_get_small_header ($imapConnection, $q+1, false);
  164. $from[$q] = $hdr->from;
  165. $date[$q] = $hdr->date;
  166. $subject[$q] = $hdr->subject;
  167. $to[$q] = $hdr->to;
  168. $priority[$q] = $hdr->priority;
  169. $cc[$q] = $hdr->cc;
  170. $size[$q] = $hdr->size;
  171. $type[$q] = $hdr->type0;
  172. $flags[$q] = sqimap_get_flags ($imapConnection, $q+1);
  173. $id[$q] = $q + 1;
  174. }
  175. } else {
  176. // if it's not sorted
  177. if ($startMessage + ($show_num - 1) < $numMessages) {
  178. $endMessage = $startMessage + ($show_num-1);
  179. } else {
  180. $endMessage = $numMessages;
  181. }
  182. if ($endMessage < $startMessage) {
  183. $startMessage = $startMessage - $show_num;
  184. if ($startMessage < 1)
  185. $startMessage = 1;
  186. }
  187. $real_startMessage = $numMessages - $startMessage + 1;
  188. $real_endMessage = $numMessages - $startMessage - $show_num;
  189. if ($real_endMessage <= 0)
  190. $real_endMessage = 1;
  191. $j = 0;
  192. for ($q = $real_startMessage; $q >= $real_endMessage; $q--) {
  193. if($mailbox == $sent_folder)
  194. $hdr = sqimap_get_small_header ($imapConnection, $q, true);
  195. else
  196. $hdr = sqimap_get_small_header ($imapConnection, $q, false);
  197. $from[$j] = $hdr->from;
  198. $date[$j] = $hdr->date;
  199. $subject[$j] = $hdr->subject;
  200. $to[$j] = $hdr->to;
  201. $priority[$j] = $hdr->priority;
  202. $cc[$j] = $hdr->cc;
  203. $size[$j] = $hdr->size;
  204. $type[$j] = $hdr->type0;
  205. $flags[$j] = sqimap_get_flags ($imapConnection, $q);
  206. $id[$j] = $q;
  207. $j++;
  208. }
  209. }
  210. }
  211. $j = 0;
  212. if ($sort == 6) {
  213. $end = $startMessage + $show_num - 1;
  214. if ($numMessages < $show_num)
  215. $end_loop = $numMessages;
  216. elseif ($end > $numMessages)
  217. $end_loop = $numMessages - $startMessage + 1;
  218. else
  219. $end_loop = $show_num;
  220. } else {
  221. $end = $numMessages;
  222. $end_loop = $end;
  223. }
  224. while ($j < $end_loop) {
  225. if (isset($date[$j])) {
  226. $date[$j] = ereg_replace(' ', ' ', $date[$j]);
  227. $tmpdate = explode(' ', trim($date[$j]));
  228. } else {
  229. $tmpdate = $date = array("","","","","","");
  230. }
  231. $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
  232. $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
  233. $messages[$j]['ID'] = $id[$j];
  234. $messages[$j]['FROM'] = decodeHeader($from[$j]);
  235. $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
  236. $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
  237. $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
  238. $messages[$j]['TO'] = decodeHeader($to[$j]);
  239. $messages[$j]['PRIORITY'] = $priority[$j];
  240. $messages[$j]['CC'] = $cc[$j];
  241. $messages[$j]['SIZE'] = $size[$j];
  242. $messages[$j]['TYPE0'] = $type[$j];
  243. # fix SUBJECT-SORT to remove Re:
  244. $re_abbr = # Add more here!
  245. 'vedr|sv|' . # Danish
  246. 're|aw'; # English
  247. if (eregi("^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
  248. $messages[$j]['SUBJECT-SORT'] = $regs[2];
  249. $num = 0;
  250. while ($num < count($flags[$j])) {
  251. if ($flags[$j][$num] == 'Deleted') {
  252. $messages[$j]['FLAG_DELETED'] = true;
  253. }
  254. elseif ($flags[$j][$num] == 'Answered') {
  255. $messages[$j]['FLAG_ANSWERED'] = true;
  256. }
  257. elseif ($flags[$j][$num] == 'Seen') {
  258. $messages[$j]['FLAG_SEEN'] = true;
  259. }
  260. elseif ($flags[$j][$num] == 'Flagged') {
  261. $messages[$j]['FLAG_FLAGGED'] = true;
  262. }
  263. $num++;
  264. }
  265. $j++;
  266. }
  267. /* Only ignore messages flagged as deleted if we are using a
  268. * trash folder or auto_expunge */
  269. if (((isset($move_to_trash) && $move_to_trash)
  270. || (isset($auto_expunge) && $auto_expunge)) && $sort != 6)
  271. {
  272. /** Find and remove the ones that are deleted */
  273. $i = 0;
  274. $j = 0;
  275. while ($j < $numMessages) {
  276. if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
  277. $j++;
  278. continue;
  279. }
  280. $msgs[$i] = $messages[$j];
  281. $i++;
  282. $j++;
  283. }
  284. $numMessages = $i;
  285. } else {
  286. if (! isset($messages))
  287. $messages = array();
  288. $msgs = $messages;
  289. }
  290. }
  291. // There's gotta be messages in the array for it to sort them.
  292. if ($numMessages > 0 && ! $use_cache) {
  293. /** 0 = Date (up) 4 = Subject (up)
  294. ** 1 = Date (dn) 5 = Subject (dn)
  295. ** 2 = Name (up)
  296. ** 3 = Name (dn)
  297. **/
  298. session_unregister("msgs");
  299. if (($sort == 0) || ($sort == 1))
  300. $msort = array_cleave ($msgs, 'TIME_STAMP');
  301. elseif (($sort == 2) || ($sort == 3))
  302. $msort = array_cleave ($msgs, 'FROM-SORT');
  303. elseif (($sort == 4) || ($sort == 5))
  304. $msort = array_cleave ($msgs, 'SUBJECT-SORT');
  305. else // ($sort == 6)
  306. $msort = $msgs;
  307. if ($sort < 6) {
  308. if ($sort % 2) {
  309. asort($msort);
  310. } else {
  311. arsort($msort);
  312. }
  313. }
  314. session_register('msort');
  315. }
  316. displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
  317. session_register('msgs');
  318. }
  319. // generic function to convert the msgs array into an HTML table
  320. function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
  321. global $folder_prefix, $sent_folder;
  322. global $imapServerAddress;
  323. global $index_order, $real_endMessage, $real_startMessage, $checkall;
  324. // if cache isn't already set, do it now
  325. if (!session_is_registered('msgs'))
  326. session_register('msgs');
  327. if (!session_is_registered('msort'))
  328. session_register('msort');
  329. if ($startMessage + ($show_num - 1) < $numMessages) {
  330. $endMessage = $startMessage + ($show_num-1);
  331. } else {
  332. $endMessage = $numMessages;
  333. }
  334. if ($endMessage < $startMessage) {
  335. $startMessage = $startMessage - $show_num;
  336. if ($startMessage < 1)
  337. $startMessage = 1;
  338. }
  339. $nextGroup = $startMessage + $show_num;
  340. $prevGroup = $startMessage - $show_num;
  341. $urlMailbox = urlencode($mailbox);
  342. do_hook('mailbox_index_before');
  343. $Message = '';
  344. if ($startMessage < $endMessage) {
  345. $Message = _("Viewing messages") ." <B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")\n";
  346. } elseif ($startMessage == $endMessage) {
  347. $Message = _("Viewing message") ." <B>$startMessage</B> ($numMessages " . _("total") . ")\n";
  348. }
  349. $More = '';
  350. if ($sort == 6) {
  351. $use = 0;
  352. } else {
  353. $use = 1;
  354. }
  355. if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
  356. $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
  357. $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
  358. }
  359. elseif (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
  360. $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
  361. $More .= "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
  362. }
  363. elseif (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
  364. $More = "<FONT COLOR=\"$color[9]\">"._("Previous")."</FONT> | \n";
  365. $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
  366. }
  367. if (! isset($msg))
  368. $msg = "";
  369. mail_message_listing_beginning($imapConnection,
  370. "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
  371. $mailbox, $sort, $Message, $More, $startMessage);
  372. $groupNum = $startMessage % ($show_num - 1);
  373. $real_startMessage = $startMessage;
  374. if ($sort == 6) {
  375. if ($endMessage - $startMessage < $show_num - 1) {
  376. $endMessage = $endMessage - $startMessage + 1;
  377. $startMessage = 1;
  378. } else if ($startMessage > $show_num) {
  379. $endMessage = $show_num;
  380. $startMessage = 1;
  381. }
  382. }
  383. $endVar = $endMessage + 1;
  384. // loop through and display the info for each message.
  385. $t = 0; // $t is used for the checkbox number
  386. if ($numMessages == 0) { // if there's no messages in this folder
  387. echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
  388. echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp;</CENTER></TD></TR>";
  389. } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
  390. if ($sort != 6)
  391. $i = $startMessage;
  392. else
  393. $i = 1;
  394. reset($msort);
  395. $k = 0;
  396. do {
  397. $key = key($msort);
  398. next($msort);
  399. $k++;
  400. } while (isset ($key) && ($k < $i));
  401. printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
  402. } else {
  403. $i = $startMessage;
  404. reset($msort);
  405. $k = 0;
  406. do {
  407. $key = key($msort);
  408. next($msort);
  409. $k++;
  410. } while (isset ($key) && ($k < $i));
  411. do {
  412. printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
  413. $key = key($msort);
  414. $t++;
  415. $i++;
  416. next($msort);
  417. } while ($i && $i < $endVar);
  418. }
  419. echo '</TABLE></FORM>';
  420. echo "</td></tr>\n";
  421. echo "<TR BGCOLOR=\"$color[4]\"><TD>";
  422. echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
  423. echo "$More</td><td align=right>\n";
  424. if (!$startMessage) $startMessage=1;
  425. ShowSelectAllLink($startMessage, $sort);
  426. echo '</td></tr></table>';
  427. echo '</td></tr>';
  428. echo '</table>'; /** End of message-list table */
  429. do_hook('mailbox_index_after');
  430. }
  431. /* Displays the standard message list header.
  432. * To finish the table, you need to do a "</table></table>";
  433. * $moveURL is the URL to submit the delete/move form to
  434. * $mailbox is the current mailbox
  435. * $sort is the current sorting method (-1 for no sorting available [searches])
  436. * $Message is a message that is centered on top of the list
  437. * $More is a second line that is left aligned
  438. */
  439. function mail_message_listing_beginning($imapConnection, $moveURL,
  440. $mailbox = '', $sort = -1, $Message = '', $More = '', $startMessage = 1)
  441. {
  442. global $color, $index_order, $auto_expunge, $move_to_trash;
  443. global $checkall, $sent_folder;
  444. $urlMailbox = urlencode($mailbox);
  445. /** This is the beginning of the message list table. It wraps around all messages */
  446. echo '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="0">';
  447. if ($Message)
  448. {
  449. echo "<TR BGCOLOR=\"$color[4]\"><TD align=center>$Message</td></tr>\n";
  450. }
  451. echo "<TR BGCOLOR=\"$color[4]\"><TD>";
  452. echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
  453. echo "$More</td><td align=right>\n";
  454. ShowSelectAllLink($startMessage, $sort);
  455. echo '</td></tr></table>';
  456. echo '</td></tr>';
  457. /** The delete and move options */
  458. echo "<TR><TD BGCOLOR=\"$color[0]\">";
  459. echo "\n\n\n<FORM name=messageList method=post action=\"$moveURL\">\n";
  460. echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
  461. echo " <TR>\n";
  462. echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
  463. echo ' <NOBR><SMALL>'. _("Move selected to:") .'</SMALL>';
  464. echo ' <TT><SMALL><SELECT NAME="targetMailbox">';
  465. $boxes = sqimap_mailbox_list($imapConnection);
  466. for ($i = 0; $i < count($boxes); $i++) {
  467. if (!in_array("noselect", $boxes[$i]['flags'])) {
  468. $box = $boxes[$i]['unformatted'];
  469. $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
  470. echo " <OPTION VALUE=\"$box\">$box2</option>\n";
  471. }
  472. }
  473. echo ' </SELECT></SMALL></TT>';
  474. echo ' <SMALL><INPUT TYPE=SUBMIT NAME="moveButton" VALUE="'. _("Move") ."\"></SMALL></NOBR>\n";
  475. echo " </TD>\n";
  476. echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
  477. if (! $auto_expunge) {
  478. echo ' <NOBR><SMALL><INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'">&nbsp;'. _("mailbox") ."</SMALL></NOBR>&nbsp;&nbsp;\n";
  479. }
  480. echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\">&nbsp;". _("checked messages") ."</SMALL></NOBR>\n";
  481. echo " </TD>\n";
  482. echo " </TR>\n";
  483. echo "</TABLE>\n";
  484. do_hook('mailbox_form_before');
  485. echo '</TD></TR>';
  486. echo "<TR><TD BGCOLOR=\"$color[0]\">";
  487. echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
  488. if ($GLOBALS['alt_index_colors']) {
  489. echo "0";
  490. } else {
  491. echo "1";
  492. }
  493. echo " BGCOLOR=\"$color[0]\">";
  494. echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
  495. // Print the headers
  496. for ($i=1; $i <= count($index_order); $i++) {
  497. switch ($index_order[$i]) {
  498. case 1: # checkbox
  499. case 5: # flags
  500. echo ' <TD WIDTH="1%"><B>&nbsp;</B></TD>';
  501. break;
  502. case 2: # from
  503. if ($mailbox == $sent_folder)
  504. echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
  505. else
  506. echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
  507. ShowSortButton($sort, $mailbox, 2, 3);
  508. echo "</TD>\n";
  509. break;
  510. case 3: # date
  511. echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
  512. ShowSortButton($sort, $mailbox, 0, 1);
  513. echo "</TD>\n";
  514. break;
  515. case 4: # subject
  516. echo ' <TD><B>'. _("Subject") .'</B> ';
  517. ShowSortButton($sort, $mailbox, 4, 5);
  518. echo "</TD>\n";
  519. break;
  520. case 6: # size
  521. echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
  522. break;
  523. }
  524. }
  525. echo "</TR>\n";
  526. }
  527. function ShowSortButton($sort, $mailbox, $Up, $Down) {
  528. if ($sort != $Up && $sort != $Down) {
  529. $img = 'sort_none.gif';
  530. $which = $Up;
  531. } elseif ($sort == $Up) {
  532. $img = 'up_pointer.gif';
  533. $which = $Down;
  534. } else {
  535. $img = 'down_pointer.gif';
  536. $which = 6;
  537. }
  538. echo ' <a href="right_main.php?newsort=' . $which .
  539. '&startMessage=1&mailbox=' . urlencode($mailbox) .
  540. '"><IMG SRC="../images/' . $img .
  541. '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
  542. }
  543. function ShowSelectAllLink($startMessage, $sort)
  544. {
  545. global $checkall, $PHP_SELF, $what, $where, $mailbox;
  546. echo "\n<A HREF=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
  547. "&startMessage=$startMessage&sort=$sort&";
  548. if ( isset($checkall) && $checkall == '1')
  549. echo "checkall=0";
  550. else
  551. echo "checkall=1";
  552. if (isset($where) && isset($what))
  553. echo "&where=" . urlencode($where) . "&what=" . urlencode($what);
  554. echo "\">";
  555. if (isset($checkall) && $checkall == '1')
  556. echo _("Unselect All");
  557. else
  558. echo _("Select All");
  559. echo "</A>\n";
  560. }
  561. function processSubject($subject)
  562. {
  563. // Shouldn't ever happen -- caught too many times in the IMAP functions
  564. if ($subject == '')
  565. return _("(no subject)");
  566. if (strlen($subject) <= 55)
  567. return $subject;
  568. $ent_strlen=strlen($subject);
  569. $trim_val=50;
  570. $ent_offset=0;
  571. // see if this is entities-encoded string
  572. // If so, Iterate through the whole string, find out
  573. // the real number of characters, and if more
  574. // than 55, substr with an updated trim value.
  575. while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
  576. ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
  577. {
  578. $trim_val += ($ent_loc_end-$ent_loc)+1;
  579. $ent_strlen -= $ent_loc_end-$ent_loc;
  580. $ent_offset = $ent_loc_end+1;
  581. }
  582. if ($ent_strlen <= 55)
  583. return $subject;
  584. return substr($subject, 0, $trim_val) . '...';
  585. }
  586. ?>