PageRenderTime 60ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1_2_0/squirrelmail/functions/mailbox_display.php

#
PHP | 908 lines | 682 code | 108 blank | 118 comment | 218 complexity | 81601765ea79dc106dc270743a05c45b MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. <?php
  2. /**
  3. * mailbox_display.php
  4. *
  5. * Copyright (c) 1999-2002 The SquirrelMail Project 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: mailbox_display.php 1939 2001-12-25 04:44:46Z thomppj $
  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 (handleAsSent($mailbox)) {
  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) {
  144. echo "&nbsp;\n";
  145. }
  146. echo "</small></b></td>\n";
  147. break;
  148. case 6: /* size */
  149. echo " <td bgcolor=$hlt_color>$bold$fontstr" .
  150. show_readable_size($msg['SIZE']) .
  151. "$fontstr_end$bold_end</td>\n";
  152. break;
  153. }
  154. }
  155. echo "</tr>\n";
  156. }
  157. /**
  158. * This function loops through a group of messages in the mailbox
  159. * and shows them to the user.
  160. */
  161. function showMessagesForMailbox
  162. ($imapConnection, $mailbox, $num_msgs, $start_msg,
  163. $sort, $color,$show_num, $use_cache) {
  164. global $msgs, $msort;
  165. global $sent_folder, $draft_folder;
  166. global $message_highlight_list;
  167. global $auto_expunge;
  168. /* If autoexpunge is turned on, then do it now. */
  169. if ($auto_expunge == true) {
  170. sqimap_mailbox_expunge($imapConnection, $mailbox, false);
  171. }
  172. sqimap_mailbox_select($imapConnection, $mailbox);
  173. $issent = handleAsSent($mailbox);
  174. if (!$use_cache) {
  175. /* If it is sorted... */
  176. if ($num_msgs >= 1) {
  177. if ($sort < 6) {
  178. $id = range(1, $num_msgs);
  179. } else {
  180. // if it's not sorted
  181. if ($start_msg + ($show_num - 1) < $num_msgs) {
  182. $end_msg = $start_msg + ($show_num-1);
  183. } else {
  184. $end_msg = $num_msgs;
  185. }
  186. if ($end_msg < $start_msg) {
  187. $start_msg = $start_msg - $show_num;
  188. if ($start_msg < 1) {
  189. $start_msg = 1;
  190. }
  191. }
  192. $real_startMessage = $num_msgs - $start_msg + 1;
  193. $real_endMessage = $num_msgs - $start_msg - $show_num + 2;
  194. if ($real_endMessage <= 0) {
  195. $real_endMessage = 1;
  196. }
  197. $id = array_reverse(range($real_endMessage, $real_startMessage));
  198. }
  199. $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
  200. $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
  201. foreach ($msgs_list as $hdr) {
  202. $from[] = $hdr->from;
  203. $date[] = $hdr->date;
  204. $subject[] = $hdr->subject;
  205. $to[] = $hdr->to;
  206. $priority[] = $hdr->priority;
  207. $cc[] = $hdr->cc;
  208. $size[] = $hdr->size;
  209. $type[] = $hdr->type0;
  210. }
  211. }
  212. $j = 0;
  213. if ($sort == 6) {
  214. $end = $start_msg + $show_num - 1;
  215. if ($num_msgs < $show_num) {
  216. $end_loop = $num_msgs;
  217. } else if ($end > $num_msgs) {
  218. $end_loop = $num_msgs - $start_msg + 1;
  219. } else {
  220. $end_loop = $show_num;
  221. }
  222. } else {
  223. $end = $num_msgs;
  224. $end_loop = $end;
  225. }
  226. while ($j < $end_loop) {
  227. if (isset($date[$j])) {
  228. $date[$j] = ereg_replace(' ', ' ', $date[$j]);
  229. $tmpdate = explode(' ', trim($date[$j]));
  230. } else {
  231. $tmpdate = $date = array('', '', '', '', '', '');
  232. }
  233. $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
  234. $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
  235. $messages[$j]['ID'] = $id[$j];
  236. $messages[$j]['FROM'] = decodeHeader($from[$j]);
  237. $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
  238. $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
  239. $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
  240. $messages[$j]['TO'] = decodeHeader($to[$j]);
  241. $messages[$j]['PRIORITY'] = $priority[$j];
  242. $messages[$j]['CC'] = $cc[$j];
  243. $messages[$j]['SIZE'] = $size[$j];
  244. $messages[$j]['TYPE0'] = $type[$j];
  245. # fix SUBJECT-SORT to remove Re:
  246. $re_abbr = /* Add more here! */
  247. 'vedr|sv|' . /* Danish */
  248. 're|aw'; /* English */
  249. if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs)) {
  250. $messages[$j]['SUBJECT-SORT'] = $regs[2];
  251. }
  252. $num = 0;
  253. while ($num < count($flags[$j])) {
  254. if ($flags[$j][$num] == 'Deleted') {
  255. $messages[$j]['FLAG_DELETED'] = true;
  256. } else if ($flags[$j][$num] == 'Answered') {
  257. $messages[$j]['FLAG_ANSWERED'] = true;
  258. } else if ($flags[$j][$num] == 'Seen') {
  259. $messages[$j]['FLAG_SEEN'] = true;
  260. } else if ($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. /** Find and remove the ones that are deleted */
  272. $i = 0;
  273. $j = 0;
  274. while ($j < $num_msgs) {
  275. if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
  276. $j++;
  277. continue;
  278. }
  279. $msgs[$i] = $messages[$j];
  280. $i++;
  281. $j++;
  282. }
  283. $num_msgs = $i;
  284. } else {
  285. if (!isset($messages)) {
  286. $messages = array();
  287. }
  288. $msgs = $messages;
  289. }
  290. }
  291. // There's gotta be messages in the array for it to sort them.
  292. if ($num_msgs > 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, $num_msgs, $start_msg, $msgs, $msort, $mailbox, $sort, $color,$show_num);
  317. session_register('msgs');
  318. }
  319. /**
  320. * Generic function to convert the msgs array into an HTML table.
  321. */
  322. function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $msort, $mailbox, $sort, $color, $show_num) {
  323. global $folder_prefix, $sent_folder;
  324. global $imapServerAddress, $data_dir, $username, $use_mailbox_cache;
  325. global $index_order, $real_endMessage, $real_startMessage, $checkall;
  326. /* If cache isn't already set, do it now. */
  327. if (!session_is_registered('msgs')) { session_register('msgs'); }
  328. if (!session_is_registered('msort')) { session_register('msort'); }
  329. if ($start_msg + ($show_num - 1) < $num_msgs) {
  330. $end_msg = $start_msg + ($show_num-1);
  331. } else {
  332. $end_msg = $num_msgs;
  333. }
  334. if ($end_msg < $start_msg) {
  335. $start_msg = $start_msg - $show_num;
  336. if ($start_msg < 1) { $start_msg = 1; }
  337. }
  338. $urlMailbox = urlencode($mailbox);
  339. do_hook('mailbox_index_before');
  340. $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
  341. $paginator_str = get_paginator_str
  342. ($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort);
  343. if (! isset($msg)) {
  344. $msg = '';
  345. }
  346. mail_message_listing_beginning( $imapConnection,
  347. "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$start_msg",
  348. $mailbox, $sort, $msg_cnt_str, $paginator_str, $start_msg);
  349. $groupNum = $start_msg % ($show_num - 1);
  350. $real_startMessage = $start_msg;
  351. if ($sort == 6) {
  352. if ($end_msg - $start_msg < $show_num - 1) {
  353. $end_msg = $end_msg - $start_msg + 1;
  354. $start_msg = 1;
  355. } else if ($start_msg > $show_num) {
  356. $end_msg = $show_num;
  357. $start_msg = 1;
  358. }
  359. }
  360. $endVar = $end_msg + 1;
  361. /* Loop through and display the info for each message. */
  362. $t = 0; // $t is used for the checkbox number
  363. if ($num_msgs == 0) { // if there's no messages in this folder
  364. echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order) . ">\n".
  365. " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp;</CENTER>\n".
  366. "</TD></TR>";
  367. } elseif ($start_msg == $end_msg) {
  368. /* If there's only one message in the box, handle it differently. */
  369. if ($sort != 6) {
  370. $i = $start_msg;
  371. } else {
  372. $i = 1;
  373. }
  374. reset($msort);
  375. $k = 0;
  376. do {
  377. $key = key($msort);
  378. next($msort);
  379. $k++;
  380. } while (isset ($key) && ($k < $i));
  381. printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
  382. } else {
  383. $i = $start_msg;
  384. reset($msort);
  385. $k = 0;
  386. do {
  387. $key = key($msort);
  388. next($msort);
  389. $k++;
  390. } while (isset ($key) && ($k < $i));
  391. do {
  392. printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
  393. $key = key($msort);
  394. $t++;
  395. $i++;
  396. next($msort);
  397. } while ($i && $i < $endVar);
  398. }
  399. echo '</table>'.
  400. "<table bgcolor=\"$color[9]\" width=100% border=0 cellpadding=1 cellspacing=1>" .
  401. "<tr BGCOLOR=\"$color[4]\">" .
  402. "<table width=100% BGCOLOR=\"$color[4]\" border=0 cellpadding=1 cellspacing=0><tr><td>$paginator_str</td>".
  403. "<td align=right>$msg_cnt_str</td></tr></table>".
  404. "</tr>".
  405. "</table>";
  406. /** End of message-list table */
  407. do_hook('mailbox_index_after');
  408. echo "</TABLE></FORM>\n";
  409. }
  410. /**
  411. * Displays the standard message list header. To finish the table,
  412. * you need to do a "</table></table>";
  413. *
  414. * $moveURL is the URL to submit the delete/move form to
  415. * $mailbox is the current mailbox
  416. * $sort is the current sorting method (-1 for no sorting available [searches])
  417. * $Message is a message that is centered on top of the list
  418. * $More is a second line that is left aligned
  419. */
  420. function mail_message_listing_beginning
  421. ($imapConnection, $moveURL, $mailbox = '', $sort = -1,
  422. $msg_cnt_str = '', $paginator = '&nbsp;', $start_msg = 1) {
  423. global $color, $index_order, $auto_expunge, $move_to_trash;
  424. global $checkall, $sent_folder, $draft_folder;
  425. $urlMailbox = urlencode($mailbox);
  426. /*
  427. * This is the beginning of the message list table.
  428. * It wraps around all messages
  429. */
  430. echo "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\">\n"
  431. . "<TR BGCOLOR=\"$color[0]\"><TD>"
  432. . " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
  433. . " <TD ALIGN=LEFT>$paginator</TD>\n"
  434. . " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"
  435. . " </TR></TABLE>\n"
  436. . '</TD></TR>'
  437. . "<TR><TD BGCOLOR=\"$color[0]\">\n"
  438. . "<FORM name=messageList method=post action=\"$moveURL\">\n"
  439. . "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=\"100%\">\n"
  440. . " <TR>\n"
  441. . " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n"
  442. . ' <SMALL>&nbsp;' . _("Move selected to:") . "</SMALL>\n"
  443. . " </TD>\n"
  444. . " <TD ALIGN=RIGHT NOWRAP>\n"
  445. . ' <SMALL>&nbsp;' . _("Transform Selected Messages") . ": &nbsp; </SMALL><BR>\n"
  446. . " </TD>\n"
  447. . " </TR>\n"
  448. . " <TR>\n"
  449. . " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n"
  450. . ' <SMALL>&nbsp;<TT><SELECT NAME="targetMailbox">';
  451. $boxes = sqimap_mailbox_list($imapConnection);
  452. for ($i = 0; $i < count($boxes); $i++) {
  453. if (!in_array("noselect", $boxes[$i]['flags'])) {
  454. $box = $boxes[$i]['unformatted'];
  455. $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
  456. echo " <OPTION VALUE=\"$box\">$box2</option>\n";
  457. }
  458. }
  459. echo ' </SELECT></TT>&nbsp;'.
  460. "<INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n".
  461. " </TD>\n".
  462. " <TD ALIGN=RIGHT NOWRAP>&nbsp;&nbsp;&nbsp;\n";
  463. if (!$auto_expunge) {
  464. echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'">&nbsp;'. _("mailbox") ."&nbsp;\n";
  465. }
  466. echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n".
  467. " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n".
  468. " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\">&nbsp;\n".
  469. " </TD>\n".
  470. " </TR>\n".
  471. "</TABLE>\n";
  472. do_hook('mailbox_form_before');
  473. echo '</TD></TR>'.
  474. "<TR><TD BGCOLOR=\"$color[0]\">".
  475. "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
  476. if ($GLOBALS['alt_index_colors']) {
  477. echo "0";
  478. } else {
  479. echo "1";
  480. }
  481. echo " BGCOLOR=\"$color[0]\">".
  482. "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
  483. /* Print the headers. */
  484. for ($i=1; $i <= count($index_order); $i++) {
  485. switch ($index_order[$i]) {
  486. case 1: /* checkbox */
  487. case 5: /* flags */
  488. echo ' <TD WIDTH="1%"><B>&nbsp;</B></TD>';
  489. break;
  490. case 2: /* from */
  491. if (handleAsSent($mailbox)) {
  492. echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
  493. } else {
  494. echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
  495. }
  496. ShowSortButton($sort, $mailbox, 2, 3);
  497. echo "</TD>\n";
  498. break;
  499. case 3: /* date */
  500. echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
  501. ShowSortButton($sort, $mailbox, 0, 1);
  502. echo "</TD>\n";
  503. break;
  504. case 4: /* subject */
  505. echo ' <TD><B>'. _("Subject") .'</B> ';
  506. ShowSortButton($sort, $mailbox, 4, 5);
  507. echo "</TD>\n";
  508. break;
  509. case 6: /* size */
  510. echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
  511. break;
  512. }
  513. }
  514. echo "</TR>\n";
  515. }
  516. /*
  517. * This function shows the sort button. Isn't this a good comment?
  518. */
  519. function ShowSortButton($sort, $mailbox, $Up, $Down) {
  520. /* Figure out which image we want to use. */
  521. if ($sort != $Up && $sort != $Down) {
  522. $img = 'sort_none.png';
  523. $which = $Up;
  524. } elseif ($sort == $Up) {
  525. $img = 'up_pointer.png';
  526. $which = $Down;
  527. } else {
  528. $img = 'down_pointer.png';
  529. $which = 6;
  530. }
  531. /* Now that we have everything figured out, show the actual button. */
  532. echo ' <a href="right_main.php?newsort=' . $which .
  533. '&startMessage=1&mailbox=' . urlencode($mailbox) .
  534. '"><IMG SRC="../images/' . $img .
  535. '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
  536. }
  537. function get_selectall_link($start_msg, $sort) {
  538. global $checkall, $PHP_SELF, $what, $where, $mailbox, $javascript_on;
  539. if ($javascript_on) {
  540. $result =
  541. '<script language="JavaScript">' .
  542. "\n<!-- \n" .
  543. "function CheckAll() {\n" .
  544. " for (var i = 0; i < document.messageList.elements.length; i++) {\n" .
  545. " if( document.messageList.elements[i].type == 'checkbox' ) {\n" .
  546. " document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);\n".
  547. " }\n" .
  548. " }\n" .
  549. "}\n" .
  550. "//-->\n" .
  551. '</script><a href=# onClick="CheckAll();">' . _("Toggle All") . "</a>\n";
  552. } else {
  553. $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
  554. . "&startMessage=$start_msg&sort=$sort&checkall=";
  555. if (isset($checkall) && $checkall == '1') {
  556. $result .= '0';
  557. } else {
  558. $result .= '1';
  559. }
  560. if (isset($where) && isset($what)) {
  561. $result .= '&where=' . urlencode($where)
  562. . '&what=' . urlencode($what);
  563. }
  564. $result .= "\">";
  565. if (isset($checkall) && ($checkall == '1')) {
  566. $result .= _("Unselect All");
  567. } else {
  568. $result .= _("Select All");
  569. }
  570. $result .= "</A>\n";
  571. }
  572. /* Return our final result. */
  573. return ($result);
  574. }
  575. /**
  576. * This function computes the "Viewing Messages..." string.
  577. */
  578. function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
  579. /* Compute the $msg_cnt_str. */
  580. $result = '';
  581. if ($start_msg < $end_msg) {
  582. $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $start_msg, $end_msg, $num_msgs);
  583. } else if ($start_msg == $end_msg) {
  584. $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
  585. } else {
  586. $result = '<br>';
  587. }
  588. /* Return our result string. */
  589. return ($result);
  590. }
  591. /**
  592. * Generate a paginator link.
  593. */
  594. function get_paginator_link
  595. ($box, $start_msg, $use, $text) {
  596. $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
  597. . "&startMessage=$start_msg&mailbox=$box\" "
  598. . "TARGET=\"right\">$text</A>";
  599. return ($result);
  600. }
  601. /**
  602. * This function computes the paginator string.
  603. */
  604. function get_paginator_str
  605. ($box, $start_msg, $end_msg, $num_msgs, $show_num, $sort) {
  606. global $username, $data_dir, $use_mailbox_cache, $color;
  607. /* Initialize paginator string chunks. */
  608. $prv_str = '';
  609. $nxt_str = '';
  610. $pg_str = '';
  611. $all_str = '';
  612. $tgl_str = '';
  613. /* Create simple strings that will be creating the paginator. */
  614. $spc = '&nbsp;'; /* This will be used as a space. */
  615. $sep = '|'; /* This will be used as a seperator. */
  616. /* Get some paginator preference values. */
  617. $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON);
  618. $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX);
  619. /* Make sure that our start message number is not too big. */
  620. $start_msg = min($start_msg, $num_msgs);
  621. /* Decide whether or not we will use the mailbox cache. */
  622. /* Not sure why $use_mailbox_cache is even passed in. */
  623. if ($sort == 6) {
  624. $use = 0;
  625. } else {
  626. $use = 1;
  627. }
  628. /* Compute the starting message of the previous and next page group. */
  629. $next_grp = $start_msg + $show_num;
  630. $prev_grp = $start_msg - $show_num;
  631. /* Compute the basic previous and next strings. */
  632. if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
  633. $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
  634. $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
  635. } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
  636. $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
  637. $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
  638. } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
  639. $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
  640. $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
  641. }
  642. /* Page selector block. Following code computes page links. */
  643. if ($pg_sel && ($num_msgs > $show_num)) {
  644. /* Most importantly, what is the current page!!! */
  645. $cur_pg = intval($start_msg / $show_num) + 1;
  646. /* Compute total # of pages and # of paginator page links. */
  647. $tot_pgs = ceil($num_msgs / $show_num); /* Total # of Pages */
  648. $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
  649. /************************************************************/
  650. /* Compute the size of the four quarters of the page links. */
  651. /************************************************************/
  652. /* If we can, just show all the pages. */
  653. if (($tot_pgs - 1) <= $pg_max) {
  654. $q1_pgs = $cur_pg - 1;
  655. $q2_pgs = $q3_pgs = 0;
  656. $q4_pgs = $tot_pgs - $cur_pg;
  657. /* Otherwise, compute some magic to choose the four quarters. */
  658. } else {
  659. /* Compute the magic base values. Added together, */
  660. /* these values will always equal to the $pag_pgs. */
  661. /* NOTE: These are DEFAULT values and do not take */
  662. /* the current page into account. That is below. */
  663. $q1_pgs = floor($vis_pgs/4);
  664. $q2_pgs = round($vis_pgs/4, 0);
  665. $q3_pgs = ceil($vis_pgs/4);
  666. $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
  667. /* Adjust if the first quarter contains the current page. */
  668. if (($cur_pg - $q1_pgs) < 1) {
  669. $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
  670. $q1_pgs = $cur_pg - 1;
  671. $q2_pgs = 0;
  672. $q3_pgs += ceil($extra_pgs / 2);
  673. $q4_pgs += floor($extra_pgs / 2);
  674. /* Adjust if the first and second quarters intersect. */
  675. } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
  676. $extra_pgs = $q2_pgs;
  677. $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
  678. $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
  679. $q3_pgs += ceil($extra_pgs / 2);
  680. $q4_pgs += floor($extra_pgs / 2);
  681. /* Adjust if the fourth quarter contains the current page. */
  682. } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
  683. $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
  684. $q3_pgs = 0;
  685. $q4_pgs = $tot_pgs - $cur_pg;
  686. $q1_pgs += floor($extra_pgs / 2);
  687. $q2_pgs += ceil($extra_pgs / 2);
  688. /* Adjust if the third and fourth quarter intersect. */
  689. } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) {
  690. $extra_pgs = $q3_pgs;
  691. $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
  692. $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
  693. $q1_pgs += floor($extra_pgs / 2);
  694. $q2_pgs += ceil($extra_pgs / 2);
  695. }
  696. }
  697. /* I am leaving this debug code here, commented out, because */
  698. /* it is a really nice way to see what the above code is doing. */
  699. /* echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = " */
  700. /* . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>'; */
  701. /************************************************************/
  702. /* Print out the page links from the compute page quarters. */
  703. /************************************************************/
  704. /* Start with the first quarter. */
  705. if (($q1_pgs == 0) && ($cur_pg > 1)) {
  706. $pg_str .= "...$spc";
  707. } else {
  708. for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
  709. $start = (($pg-1) * $show_num) + 1;
  710. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  711. }
  712. if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
  713. $pg_str .= "...$spc";
  714. }
  715. }
  716. /* Continue with the second quarter. */
  717. for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
  718. $start = (($pg-1) * $show_num) + 1;
  719. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  720. }
  721. /* Now print the current page. */
  722. $pg_str .= $cur_pg . $spc;
  723. /* Next comes the third quarter. */
  724. for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
  725. $start = (($pg-1) * $show_num) + 1;
  726. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  727. }
  728. /* And last, print the forth quarter page links. */
  729. if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
  730. $pg_str .= "...$spc";
  731. } else {
  732. if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
  733. $pg_str .= "...$spc";
  734. }
  735. for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
  736. $start = (($pg-1) * $show_num) + 1;
  737. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  738. }
  739. }
  740. }
  741. /* If necessary, compute the 'show all' string. */
  742. if (($prv_str != '') || ($nxt_str != '')) {
  743. $all_str = "<A HREF=\"right_main.php?PG_SHOWNUM=9999"
  744. . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
  745. . "TARGET=\"right\">" . _("Show All") . '</A>';
  746. }
  747. /* Last but not least, get the value for the toggle all link. */
  748. $tgl_str = get_selectall_link($start_msg, $sort);
  749. /* Put all the pieces of the paginator string together. */
  750. $result = '';
  751. $result .= ($all_str != '' ? $all_str . $spc . $sep . $spc: '');
  752. $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
  753. $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : '');
  754. $result .= ($pg_str != '' ? $pg_str : '');
  755. $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str);
  756. /* If the resulting string is blank, return a non-breaking space. */
  757. if ($result == '') {
  758. $result = '&nbsp;';
  759. }
  760. /* Return our final magical paginator string. */
  761. return ($result);
  762. }
  763. function processSubject($subject) {
  764. // Shouldn't ever happen -- caught too many times in the IMAP functions
  765. if ($subject == '')
  766. return _("(no subject)");
  767. if (strlen($subject) <= 55)
  768. return $subject;
  769. $ent_strlen=strlen($subject);
  770. $trim_val=50;
  771. $ent_offset=0;
  772. // see if this is entities-encoded string
  773. // If so, Iterate through the whole string, find out
  774. // the real number of characters, and if more
  775. // than 55, substr with an updated trim value.
  776. while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
  777. ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
  778. {
  779. $trim_val += ($ent_loc_end-$ent_loc)+1;
  780. $ent_strlen -= $ent_loc_end-$ent_loc;
  781. $ent_offset = $ent_loc_end+1;
  782. }
  783. if ($ent_strlen <= 55)
  784. return $subject;
  785. return substr($subject, 0, $trim_val) . '...';
  786. }
  787. function handleAsSent($mailbox) {
  788. global $sent_folder, $draft_folder;
  789. global $handleAsSent_result;
  790. /* First check if this is the sent or draft folder. */
  791. $handleAsSent_result = (($mailbox == $sent_folder)
  792. || ($mailbox == $draft_folder));
  793. /* Then check the result of the handleAsSent hook. */
  794. do_hook('check_handleAsSent_result', $mailbox);
  795. /* And return the result. */
  796. return ($handleAsSent_result);
  797. }
  798. ?>