mailbox_display.php 28 KB

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