PageRenderTime 53ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
PHP | 917 lines | 691 code | 108 blank | 118 comment | 221 complexity | 0215602d2a9394892a1ba81d0c72fa1c 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 2068 2001-12-31 22:12:36Z graf25 $
  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 = 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, $sort,
  163. $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]\"><td>" .
  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. "</td></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 "<FORM name=messageList method=post action=\"$moveURL\">\n"
  431. . "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\">\n"
  432. . "<TR BGCOLOR=\"$color[0]\"><TD>"
  433. . " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
  434. . " <TD ALIGN=LEFT>$paginator</TD>\n"
  435. . " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"
  436. . " </TR></TABLE>\n"
  437. . '</TD></TR>'
  438. . "<TR><TD BGCOLOR=\"$color[0]\">\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=MIDDLE 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=MIDDLE 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, $what, $where, $mailbox, $javascript_on;
  539. global $PHP_SELF, $PG_SHOWNUM;
  540. if ($javascript_on) {
  541. $result =
  542. '<script language="JavaScript">' .
  543. "\n<!-- \n" .
  544. "function CheckAll() {\n" .
  545. " for (var i = 0; i < document.messageList.elements.length; i++) {\n" .
  546. " if( document.messageList.elements[i].type == 'checkbox' ) {\n" .
  547. " document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);\n".
  548. " }\n" .
  549. " }\n" .
  550. "}\n" .
  551. "//-->\n" .
  552. '</script><a href="#" onClick="CheckAll();">' . _("Toggle All") . "</a>\n";
  553. } else {
  554. $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
  555. . "&startMessage=$start_msg&sort=$sort&checkall=";
  556. if (isset($checkall) && $checkall == '1') {
  557. $result .= '0';
  558. } else {
  559. $result .= '1';
  560. }
  561. if (isset($where) && isset($what)) {
  562. $result .= '&where=' . urlencode($where)
  563. . '&what=' . urlencode($what);
  564. }
  565. if ($PG_SHOWNUM == 999999) {
  566. $result .= '&PG_SHOWNUM=999999';
  567. }
  568. $result .= "\">";
  569. if (isset($checkall) && ($checkall == '1')) {
  570. $result .= _("Unselect All");
  571. } else {
  572. $result .= _("Select All");
  573. }
  574. $result .= "</A>\n";
  575. }
  576. /* Return our final result. */
  577. return ($result);
  578. }
  579. /**
  580. * This function computes the "Viewing Messages..." string.
  581. */
  582. function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
  583. /* Compute the $msg_cnt_str. */
  584. $result = '';
  585. if ($start_msg < $end_msg) {
  586. $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $start_msg, $end_msg, $num_msgs);
  587. } else if ($start_msg == $end_msg) {
  588. $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
  589. } else {
  590. $result = '<br>';
  591. }
  592. /* Return our result string. */
  593. return ($result);
  594. }
  595. /**
  596. * Generate a paginator link.
  597. */
  598. function get_paginator_link
  599. ($box, $start_msg, $use, $text) {
  600. $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
  601. . "&startMessage=$start_msg&mailbox=$box\" "
  602. . "TARGET=\"right\">$text</A>";
  603. return ($result);
  604. }
  605. /**
  606. * This function computes the paginator string.
  607. */
  608. function get_paginator_str
  609. ($box, $start_msg, $end_msg, $num_msgs, $show_num, $sort) {
  610. global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
  611. /* Initialize paginator string chunks. */
  612. $prv_str = '';
  613. $nxt_str = '';
  614. $pg_str = '';
  615. $all_str = '';
  616. $tgl_str = '';
  617. /* Create simple strings that will be creating the paginator. */
  618. $spc = '&nbsp;'; /* This will be used as a space. */
  619. $sep = '|'; /* This will be used as a seperator. */
  620. /* Get some paginator preference values. */
  621. $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON);
  622. $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX);
  623. /* Make sure that our start message number is not too big. */
  624. $start_msg = min($start_msg, $num_msgs);
  625. /* Decide whether or not we will use the mailbox cache. */
  626. /* Not sure why $use_mailbox_cache is even passed in. */
  627. if ($sort == 6) {
  628. $use = 0;
  629. } else {
  630. $use = 1;
  631. }
  632. /* Compute the starting message of the previous and next page group. */
  633. $next_grp = $start_msg + $show_num;
  634. $prev_grp = $start_msg - $show_num;
  635. /* Compute the basic previous and next strings. */
  636. if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
  637. $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
  638. $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
  639. } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
  640. $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
  641. $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
  642. } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
  643. $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
  644. $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
  645. }
  646. /* Page selector block. Following code computes page links. */
  647. if ($pg_sel && ($num_msgs > $show_num)) {
  648. /* Most importantly, what is the current page!!! */
  649. $cur_pg = intval($start_msg / $show_num) + 1;
  650. /* Compute total # of pages and # of paginator page links. */
  651. $tot_pgs = ceil($num_msgs / $show_num); /* Total # of Pages */
  652. $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
  653. /************************************************************/
  654. /* Compute the size of the four quarters of the page links. */
  655. /************************************************************/
  656. /* If we can, just show all the pages. */
  657. if (($tot_pgs - 1) <= $pg_max) {
  658. $q1_pgs = $cur_pg - 1;
  659. $q2_pgs = $q3_pgs = 0;
  660. $q4_pgs = $tot_pgs - $cur_pg;
  661. /* Otherwise, compute some magic to choose the four quarters. */
  662. } else {
  663. /* Compute the magic base values. Added together, */
  664. /* these values will always equal to the $pag_pgs. */
  665. /* NOTE: These are DEFAULT values and do not take */
  666. /* the current page into account. That is below. */
  667. $q1_pgs = floor($vis_pgs/4);
  668. $q2_pgs = round($vis_pgs/4, 0);
  669. $q3_pgs = ceil($vis_pgs/4);
  670. $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
  671. /* Adjust if the first quarter contains the current page. */
  672. if (($cur_pg - $q1_pgs) < 1) {
  673. $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
  674. $q1_pgs = $cur_pg - 1;
  675. $q2_pgs = 0;
  676. $q3_pgs += ceil($extra_pgs / 2);
  677. $q4_pgs += floor($extra_pgs / 2);
  678. /* Adjust if the first and second quarters intersect. */
  679. } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
  680. $extra_pgs = $q2_pgs;
  681. $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
  682. $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
  683. $q3_pgs += ceil($extra_pgs / 2);
  684. $q4_pgs += floor($extra_pgs / 2);
  685. /* Adjust if the fourth quarter contains the current page. */
  686. } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
  687. $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
  688. $q3_pgs = 0;
  689. $q4_pgs = $tot_pgs - $cur_pg;
  690. $q1_pgs += floor($extra_pgs / 2);
  691. $q2_pgs += ceil($extra_pgs / 2);
  692. /* Adjust if the third and fourth quarter intersect. */
  693. } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) {
  694. $extra_pgs = $q3_pgs;
  695. $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
  696. $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
  697. $q1_pgs += floor($extra_pgs / 2);
  698. $q2_pgs += ceil($extra_pgs / 2);
  699. }
  700. }
  701. /* I am leaving this debug code here, commented out, because */
  702. /* it is a really nice way to see what the above code is doing. */
  703. /* echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = " */
  704. /* . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>'; */
  705. /************************************************************/
  706. /* Print out the page links from the compute page quarters. */
  707. /************************************************************/
  708. /* Start with the first quarter. */
  709. if (($q1_pgs == 0) && ($cur_pg > 1)) {
  710. $pg_str .= "...$spc";
  711. } else {
  712. for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
  713. $start = (($pg-1) * $show_num) + 1;
  714. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  715. }
  716. if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
  717. $pg_str .= "...$spc";
  718. }
  719. }
  720. /* Continue with the second quarter. */
  721. for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
  722. $start = (($pg-1) * $show_num) + 1;
  723. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  724. }
  725. /* Now print the current page. */
  726. $pg_str .= $cur_pg . $spc;
  727. /* Next comes the third quarter. */
  728. for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
  729. $start = (($pg-1) * $show_num) + 1;
  730. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  731. }
  732. /* And last, print the forth quarter page links. */
  733. if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
  734. $pg_str .= "...$spc";
  735. } else {
  736. if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
  737. $pg_str .= "...$spc";
  738. }
  739. for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
  740. $start = (($pg-1) * $show_num) + 1;
  741. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  742. }
  743. }
  744. } else if ($PG_SHOWNUM == 999999) {
  745. $pg_str = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
  746. . "&startMessage=1&mailbox=$box\" TARGET=\"right\">"
  747. . _("Paginate") . '</A>' . $spc;
  748. }
  749. /* If necessary, compute the 'show all' string. */
  750. if (($prv_str != '') || ($nxt_str != '')) {
  751. $all_str = "<A HREF=\"right_main.php?PG_SHOWNUM=999999"
  752. . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
  753. . "TARGET=\"right\">" . _("Show All") . '</A>';
  754. }
  755. /* Last but not least, get the value for the toggle all link. */
  756. $tgl_str = get_selectall_link($start_msg, $sort);
  757. /* Put all the pieces of the paginator string together. */
  758. $result = '';
  759. $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
  760. $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : '');
  761. $result .= ($pg_str != '' ? $pg_str : '');
  762. $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : '');
  763. $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str);
  764. /* If the resulting string is blank, return a non-breaking space. */
  765. if ($result == '') {
  766. $result = '&nbsp;';
  767. }
  768. /* Return our final magical paginator string. */
  769. return ($result);
  770. }
  771. function processSubject($subject) {
  772. // Shouldn't ever happen -- caught too many times in the IMAP functions
  773. if ($subject == '')
  774. return _("(no subject)");
  775. if (strlen($subject) <= 55)
  776. return $subject;
  777. $ent_strlen=strlen($subject);
  778. $trim_val=50;
  779. $ent_offset=0;
  780. // see if this is entities-encoded string
  781. // If so, Iterate through the whole string, find out
  782. // the real number of characters, and if more
  783. // than 55, substr with an updated trim value.
  784. while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
  785. ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
  786. {
  787. $trim_val += ($ent_loc_end-$ent_loc)+1;
  788. $ent_strlen -= $ent_loc_end-$ent_loc;
  789. $ent_offset = $ent_loc_end+1;
  790. }
  791. if ($ent_strlen <= 55)
  792. return $subject;
  793. return substr($subject, 0, $trim_val) . '...';
  794. }
  795. function handleAsSent($mailbox) {
  796. global $sent_folder, $draft_folder;
  797. global $handleAsSent_result;
  798. /* First check if this is the sent or draft folder. */
  799. $handleAsSent_result = (($mailbox == $sent_folder)
  800. || ($mailbox == $draft_folder));
  801. /* Then check the result of the handleAsSent hook. */
  802. do_hook('check_handleAsSent_result', $mailbox);
  803. /* And return the result. */
  804. return ($handleAsSent_result);
  805. }
  806. ?>