PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

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

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