Source for file mailbox_display.php

Documentation is available at mailbox_display.php

  1. <?php
  2. /**
  3. * mailbox_display.php
  4. *
  5. * This contains functions that display mailbox information, such as the
  6. * table row that has sender, date, subject, etc...
  7. *
  8. * @copyright 1999-2020 The SquirrelMail Project Team
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @version $Id: mailbox_display.php 14840 2020年01月07日 07:42:38Z pdontthink $
  11. * @package squirrelmail
  12. */
  13. /** The standard includes.. */
  14. require_once(SM_PATH . 'functions/strings.php');
  15. require_once(SM_PATH . 'functions/html.php');
  16. require_once(SM_PATH . 'class/html.class.php');
  17. require_once(SM_PATH . 'functions/imap_mailbox.php');
  18. /* Constants:
  19. * PG_SEL_MAX: default value for page_selector_max
  20. * SUBJ_TRIM_AT: the length at which we trim off subjects
  21. */
  22. define ('PG_SEL_MAX', 10);
  23. define ('SUBJ_TRIM_AT', 55);
  24. function elapsed ($start)
  25. {
  26. $end = microtime ();
  27. list($start2, $start1) = explode (" ", $start);
  28. list($end2, $end1) = explode (" ", $end);
  29. $diff1 = $end1 - $start1;
  30. $diff2 = $end2 - $start2;
  31. if( $diff2 < 0 ){
  32. $diff1 -= 1;
  33. $diff2 += 1.0;
  34. }
  35. return $diff2 + $diff1;
  36. }
  37. function printMessageInfo ($imapConnection, $t, $not_last=true, $key, $mailbox,
  38. $start_msg, $where, $what) {
  39. global $checkall, $preselected,
  40. $color, $msgs, $msort, $td_str, $msg,
  41. $message_highlight_list,
  42. $index_order,
  43. $indent_array, /* indent subject by */
  44. $pos, /* Search postion (if any) */
  45. $thread_sort_messages, /* thread sorting on/off */
  46. $server_sort_order, /* sort value when using server-sorting */
  47. $row_count,
  48. $allow_server_sort , /* enable/disable server-side sorting */
  49. $truncate_subject,
  50. $truncate_sender,
  51. $internal_date_sort;
  52. sqgetGlobalVar ('sort', $sort, SQ_SESSION );
  53. $color_string = $color[4];
  54. if ($GLOBALS['alt_index_colors']) {
  55. if (!isset($row_count)) {
  56. $row_count = 0;
  57. }
  58. $row_count++;
  59. if ($row_count % 2) {
  60. if (!isset($color[12])) {
  61. $color[12] = '#EAEAEA';
  62. }
  63. $color_string = $color[12];
  64. }
  65. }
  66. $msg = $msgs[$key];
  67. if($mailbox == 'None') {
  68. $boxes = sqimap_mailbox_list ($imapConnection);
  69. $mailbox = $boxes[0]['unformatted'];
  70. unset($boxes);
  71. }
  72. $urlMailbox = urlencode ($mailbox);
  73. if (handleAsSent ($mailbox)) {
  74. $msg['FROM'] = $msg['TO'];
  75. }
  76. $msg['FROM'] = parseAddress ($msg['FROM'],1);
  77. /*
  78. * This is done in case you're looking into Sent folders,
  79. * because you can have multiple receivers.
  80. */
  81. $senderNames = $msg['FROM'];
  82. $senderName = '';
  83. $senderFrom = '';
  84. if (sizeof ($senderNames)){
  85. foreach ($senderNames as $senderNames_part) {
  86. if ($senderName != '') {
  87. $senderName .= ', ';
  88. }
  89. if ($senderFrom != '') {
  90. $senderFrom .= ', ';
  91. }
  92. if ($senderNames_part[1]) {
  93. $senderName .= decodeHeader ($senderNames_part[1]);
  94. } else {
  95. $senderName .= sm_encode_html_special_chars ($senderNames_part[0]);
  96. }
  97. $senderFrom .= sm_encode_html_special_chars ($senderNames_part[0]);
  98. }
  99. }
  100. $senderName = str_replace ('&nbsp;',' ',$senderName);
  101. if (substr ($senderName, 0, 6) == '&quot;'
  102. && substr ($senderName, -6) == '&quot;')
  103. $senderName = substr (substr ($senderName, 0, -6), 6);
  104. echo html_tag ( 'tr','','','','valign="top"') . "\n";
  105. if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
  106. $flag = "<font color=\"$color[2]\">";
  107. $flag_end = '</font>';
  108. } else {
  109. $flag = '';
  110. $flag_end = '';
  111. }
  112. if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) {
  113. $bold = '<b>';
  114. $bold_end = '</b>';
  115. } else {
  116. $bold = '';
  117. $bold_end = '';
  118. }
  119. if (handleAsSent ($mailbox)) {
  120. $italic = '<i>';
  121. $italic_end = '</i>';
  122. } else {
  123. $italic = '';
  124. $italic_end = '';
  125. }
  126. if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
  127. $fontstr = "<font color=\"$color[9]\">";
  128. $fontstr_end = '</font>';
  129. } else {
  130. $fontstr = '';
  131. $fontstr_end = '';
  132. }
  133. if ($where && $what) {
  134. $searchstr = '&amp;where='.$where.'&amp;what='.$what;
  135. } else {
  136. $searchstr = '';
  137. }
  138. if (is_array ($message_highlight_list) && count ($message_highlight_list)) {
  139. $msg['TO'] = parseAddress ($msg['TO']);
  140. $msg['CC'] = parseAddress ($msg['CC']);
  141. $decoded_addresses = array();
  142. foreach ($message_highlight_list as $message_highlight_list_part) {
  143. if (trim ($message_highlight_list_part['value']) != '') {
  144. $high_val = strtolower ($message_highlight_list_part['value']);
  145. $match_type = strtoupper ($message_highlight_list_part['match_type']);
  146. if($match_type == 'TO_CC') {
  147. $match = array('TO', 'CC');
  148. } else {
  149. $match = array($match_type);
  150. }
  151. foreach($match as $match_type) {
  152. switch($match_type) {
  153. case('TO'):
  154. case('CC'):
  155. case('FROM'):
  156. foreach ($msg[$match_type] as $i => $address) {
  157. if (empty($decoded_addresses[$match_type][$i])) {
  158. $decoded_addresses[$match_type][$i][0] = decodeHeader ($address[0], true, false);
  159. $decoded_addresses[$match_type][$i][1] = decodeHeader ($address[1], true, false);
  160. }
  161. $address = $decoded_addresses[$match_type][$i];
  162. if (strstr ('^^' . strtolower ($address[0]), $high_val) ||
  163. strstr ('^^' . strtolower ($address[1]), $high_val)) {
  164. $hlt_color = $message_highlight_list_part['color'];
  165. break 4;
  166. }
  167. }
  168. break;
  169. default:
  170. $headertest = strtolower (decodeHeader ($msg[$match_type], true, false));
  171. if (strstr ('^^' . $headertest, $high_val)) {
  172. $hlt_color = $message_highlight_list_part['color'];
  173. break 3;
  174. }
  175. break;
  176. }
  177. }
  178. }
  179. }
  180. }
  181. if (!isset($hlt_color)) {
  182. $hlt_color = $color_string;
  183. }
  184. if ($checkall == 1 || in_array ($msg['ID'], $preselected))
  185. $checked = ' checked="checked"';
  186. else
  187. $checked = '';
  188. $col = 0;
  189. $msg['SUBJECT'] = decodeHeader ($msg['SUBJECT']);
  190. $subject = sm_truncate_string (str_replace ('&nbsp;',' ',$msg['SUBJECT']), $truncate_subject, '...', TRUE);
  191. if (sizeof ($index_order)) {
  192. foreach ($index_order as $index_order_part) {
  193. switch ($index_order_part) {
  194. case 1: /* checkbox */
  195. echo html_tag ( 'td',
  196. "<input type=\"checkbox\" name=\"msg[$t]\" id=\"msg".$msg['ID'].
  197. "\" value=\"".$msg['ID']."\"$checked>",
  198. 'center',
  199. $hlt_color );
  200. break;
  201. case 2: /* from */
  202. $from_xtra = '';
  203. $from_xtra = 'title="' . $senderFrom . '"';
  204. if (trim ($senderName) == '') {
  205. $senderName = '(' . _ ("unknown") . ')';
  206. }
  207. echo html_tag ( 'td',
  208. html_tag ('label',
  209. $italic . $bold . $flag . $fontstr . sm_truncate_string ($senderName, $truncate_sender, '...', TRUE) .
  210. $fontstr_end . $flag_end . $bold_end . $italic_end,
  211. '','','for="msg'.$msg['ID'].'"'),
  212. 'left',
  213. $hlt_color, $from_xtra );
  214. break;
  215. case 3: /* date */
  216. // show internal date if using it to sort
  217. if ($internal_date_sort && ($sort == 0 || $sort == 1)) {
  218. $date_string = $msg['RECEIVED_DATE_STRING'] . '';
  219. $date_title_string = $msg['RECEIVED_DATE_STRING_FULL'] . '';
  220. } else {
  221. $date_string = $msg['DATE_STRING'] . '';
  222. $date_title_string = $msg['DATE_STRING_FULL'] . '';
  223. }
  224. if ($date_string == '') {
  225. $date_string = _ ("Unknown date");
  226. }
  227. echo html_tag ( 'td',
  228. $bold . $flag . $fontstr . $date_string .
  229. $fontstr_end . $flag_end . $bold_end,
  230. 'center',
  231. $hlt_color,
  232. 'nowrap title="' . $date_title_string . '"' );
  233. break;
  234. case 4: /* subject */
  235. if (trim ($subject) == '') {
  236. $subject = '(' . _ ("unknown") . ')';
  237. }
  238. $td_str = $bold;
  239. if ($thread_sort_messages == 1) {
  240. if (isset($indent_array[$msg['ID']])) {
  241. $td_str .= str_repeat ("&nbsp;&nbsp;&nbsp;&nbsp;",$indent_array[$msg['ID']]);
  242. }
  243. }
  244. $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
  245. . '&amp;passed_id='. $msg["ID"]
  246. . '&amp;startMessage='.$start_msg.$searchstr.'"';
  247. $td_str .= ' ' .concat_hook_function ('subject_link', array($start_msg, $searchstr));
  248. // Nah, it's nice to always have a roll-over
  249. //if ($subject != $msg['SUBJECT']) {
  250. $title = get_html_translation_table (HTML_SPECIALCHARS);
  251. $title = array_flip ($title);
  252. $title = strtr ($msg['SUBJECT'], $title);
  253. $title = str_replace ('"', "''", $title);
  254. $td_str .= " title=\"$title\"";
  255. //}
  256. $td_str .= ">$flag$subject$flag_end</a>$bold_end";
  257. echo html_tag ( 'td', $td_str, 'left', $hlt_color );
  258. break;
  259. case 5: /* flags */
  260. $stuff = false;
  261. $td_str = "<b><small>";
  262. if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
  263. // i18n: "A" is short for "Answered". Make sure that two icon strings aren't translated to the same character (only in 1.5).
  264. $td_str .= _ ("A");
  265. $stuff = true;
  266. }
  267. if ($msg['TYPE0'] == 'multipart' && $msg['TYPE1'] == 'mixed') {
  268. $td_str .= '+';
  269. $stuff = true;
  270. }
  271. if ($default_use_priority) {
  272. if ( ($msg['PRIORITY'] == 1) || ($msg['PRIORITY'] == 2) ) {
  273. $td_str .= "<font color=\"$color[1]\">!</font>";
  274. $stuff = true;
  275. }
  276. if ($msg['PRIORITY'] == 5) {
  277. $td_str .= "<font color=\"$color[8]\">?</font>";
  278. $stuff = true;
  279. }
  280. }
  281. if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
  282. $td_str .= "<font color=\"$color[1]\">D</font>";
  283. $stuff = true;
  284. }
  285. if (!$stuff) {
  286. $td_str .= '&nbsp;';
  287. }
  288. do_hook ("msg_envelope");
  289. $td_str .= '</small></b>';
  290. echo html_tag ( 'td',
  291. $td_str,
  292. 'center',
  293. $hlt_color,
  294. 'nowrap' );
  295. break;
  296. case 6: /* size */
  297. echo html_tag ( 'td',
  298. $bold . $fontstr . show_readable_size ($msg['SIZE']) .
  299. $fontstr_end . $bold_end,
  300. 'right',
  301. $hlt_color );
  302. break;
  303. }
  304. ++$col;
  305. }
  306. }
  307. if ($not_last) {
  308. echo '</tr>' . "\n" . '<tr><td colspan="' . $col . '" bgcolor="' .
  309. $color[0] . '" height="1"></td></tr>' . "\n";
  310. } else {
  311. echo '</tr>'."\n";
  312. }
  313. }
  314. function getServerMessages ($imapConnection, $start_msg, $show_num, $num_msgs, $id) {
  315. if ($id != 'no') {
  316. $id = array_slice ($id, ($start_msg-1), $show_num);
  317. $end = $start_msg + $show_num - 1;
  318. if ($num_msgs < $show_num) {
  319. $end_loop = $num_msgs;
  320. } else if ($end > $num_msgs) {
  321. $end_loop = $num_msgs - $start_msg + 1;
  322. } else {
  323. $end_loop = $show_num;
  324. }
  325. return fillMessageArray ($imapConnection,$id,$end_loop,$show_num);
  326. } else {
  327. return false;
  328. }
  329. }
  330. function getThreadMessages ($imapConnection, $start_msg, $show_num, $num_msgs) {
  331. $id = get_thread_sort ($imapConnection);
  332. return getServerMessages ($imapConnection, $start_msg, $show_num, $num_msgs, $id);
  333. }
  334. function getServerSortMessages ($imapConnection, $start_msg, $show_num,
  335. $num_msgs, $server_sort_order, $mbxresponse) {
  336. $id = sqimap_get_sort_order ($imapConnection, $server_sort_order,$mbxresponse);
  337. return getServerMessages ($imapConnection, $start_msg, $show_num, $num_msgs, $id);
  338. }
  339. function getSelfSortMessages ($imapConnection, $start_msg, $show_num,
  340. $num_msgs, $sort, $mbxresponse) {
  341. $msgs = array();
  342. if ($num_msgs >= 1) {
  343. $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
  344. if ($sort != 6 ) {
  345. $end = $num_msgs;
  346. $end_loop = $end;
  347. /* set shownum to 999999 to fool sqimap_get_small_header_list
  348. and rebuild the msgs_str to 1:* */
  349. $show_num = 999999;
  350. } else {
  351. /* if it's not sorted */
  352. if ($start_msg + ($show_num - 1) < $num_msgs) {
  353. $end_msg = $start_msg + ($show_num - 1);
  354. } else {
  355. $end_msg = $num_msgs;
  356. }
  357. if ($end_msg < $start_msg) {
  358. $start_msg = $start_msg - $show_num;
  359. if ($start_msg < 1) {
  360. $start_msg = 1;
  361. }
  362. }
  363. $id = array_slice (array_reverse ($id), ($start_msg-1), $show_num);
  364. $end = $start_msg + $show_num - 1;
  365. if ($num_msgs < $show_num) {
  366. $end_loop = $num_msgs;
  367. } else if ($end > $num_msgs) {
  368. $end_loop = $num_msgs - $start_msg + 1;
  369. } else {
  370. $end_loop = $show_num;
  371. }
  372. }
  373. $msgs = fillMessageArray ($imapConnection,$id,$end_loop, $show_num);
  374. }
  375. return $msgs;
  376. }
  377. /*
  378. * This function loops through a group of messages in the mailbox
  379. * and shows them to the user.
  380. */
  381. function showMessagesForMailbox ($imapConnection, $mailbox, $num_msgs,
  382. $start_msg, $sort, $color, $show_num,
  383. $use_cache, $mode='') {
  384. global $msgs, $msort, $auto_expunge, $thread_sort_messages,
  385. $allow_server_sort , $server_sort_order;
  386. /*
  387. * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc
  388. * so setting it to an empty array beforehand seems to clean up the issue, and stopping the
  389. * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error
  390. */
  391. if (!isset($msort)) {
  392. $msort = array();
  393. }
  394. if (!isset($msgs)) {
  395. $msgs = array();
  396. }
  397. //$start = microtime();
  398. /* If autoexpunge is turned on, then do it now. */
  399. $mbxresponse = sqimap_mailbox_select ($imapConnection, $mailbox);
  400. $srt = $sort;
  401. /* If autoexpunge is turned on, then do it now. */
  402. if ($auto_expunge == true) {
  403. $exp_cnt = sqimap_mailbox_expunge ($imapConnection, $mailbox, false, '');
  404. $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
  405. $num_msgs = $mbxresponse['EXISTS'];
  406. }
  407. if ($mbxresponse['EXISTS'] > 0) {
  408. /* if $start_msg is lower than $num_msgs, we probably deleted all messages
  409. * in the last page. We need to re-adjust the start_msg
  410. */
  411. if($start_msg > $num_msgs) {
  412. $start_msg -= $show_num;
  413. if($start_msg < 1) {
  414. $start_msg = 1;
  415. }
  416. }
  417. /* This code and the next if() block check for
  418. * server-side sorting methods. The $id array is
  419. * formatted and $sort is set to 6 to disable
  420. * SM internal sorting
  421. */
  422. if ($thread_sort_messages == 1) {
  423. $mode = 'thread';
  424. } elseif ($allow_server_sort == 1) {
  425. $mode = 'serversort';
  426. } else {
  427. $mode = '';
  428. }
  429. if ($use_cache) {
  430. sqgetGlobalVar ('msgs', $msgs, SQ_SESSION );
  431. sqgetGlobalVar ('msort', $msort, SQ_SESSION );
  432. } else {
  433. }
  434. switch ($mode) {
  435. case 'thread':
  436. $id = get_thread_sort ($imapConnection);
  437. $msgs = getServerMessages ($imapConnection, $start_msg, $show_num, $num_msgs, $id);
  438. if ($msgs === false) {
  439. echo '<b><small><center><font color="red">' .
  440. _ ("Thread sorting is not supported by your IMAP server.") . '<br />' .
  441. _ ("Please contact your system administrator and report this error.") .
  442. '</font></center></small></b>';
  443. $thread_sort_messages = 0;
  444. $msort = $msgs = array();
  445. } else {
  446. $msort= $msgs;
  447. $sort = 6;
  448. }
  449. break;
  450. case 'serversort':
  451. $id = sqimap_get_sort_order ($imapConnection, $sort, $mbxresponse);
  452. $msgs = getServerMessages ($imapConnection, $start_msg, $show_num, $num_msgs, $id);
  453. if ($msgs === false) {
  454. echo '<b><small><center><font color="red">' .
  455. _ ( "Server-side sorting is not supported by your IMAP server.") . '<br />' .
  456. _ ("Please contact your system administrator and report this error.") .
  457. '</font></center></small></b>';
  458. $sort = $server_sort_order;
  459. $allow_server_sort = FALSE;
  460. $msort = $msgs = array();
  461. $id = array();
  462. } else {
  463. $msort = $msgs;
  464. $sort = 6;
  465. }
  466. break;
  467. default:
  468. if (!$use_cache) {
  469. $msgs = getSelfSortMessages ($imapConnection, $start_msg, $show_num,
  470. $num_msgs, $sort, $mbxresponse);
  471. $msort = calc_msort ($msgs, $sort, $mailbox);
  472. } /* !use cache */
  473. break;
  474. } // switch
  475. sqsession_register ($msort, 'msort');
  476. sqsession_register ($msgs, 'msgs');
  477. } /* if exists > 0 */
  478. $res = getEndMessage ($start_msg, $show_num, $num_msgs);
  479. $start_msg = $res[0];
  480. $end_msg = $res[1];
  481. if ($num_msgs > 0) {
  482. $paginator_str = get_paginator_str ($mailbox, $start_msg, $end_msg,
  483. $num_msgs, $show_num, $sort);
  484. } else {
  485. $paginator_str = '';
  486. }
  487. $msg_cnt_str = get_msgcnt_str ($start_msg, $end_msg, $num_msgs);
  488. do_hook ('mailbox_index_before');
  489. $safe_name = preg_replace ("/[^0-9A-Za-z_]/", '_', $mailbox);
  490. $form_name = "FormMsgs" . $safe_name;
  491. echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' ."\n" .
  492. '<input type="hidden" name="smtoken" value="'.sm_generate_security_token ().'">' . "\n" .
  493. '<input type="hidden" name="mailbox" value="'.sm_encode_html_special_chars ($mailbox).'">' . "\n" .
  494. '<input type="hidden" name="startMessage" value="'.sm_encode_html_special_chars ($start_msg).'">' . "\n";
  495. echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">';
  496. echo '<tr><td>';
  497. mail_message_listing_beginning ($imapConnection, $mailbox, $sort,
  498. $msg_cnt_str, $paginator_str, $start_msg);
  499. /* line between the button area and the list */
  500. echo '<tr><td height="5" bgcolor="'.$color[4].'"></td></tr>';
  501. echo '<tr><td>';
  502. echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
  503. echo ' <tr><td>';
  504. echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">';
  505. printHeader ($mailbox, $srt, $color, !$thread_sort_messages);
  506. displayMessageArray ($imapConnection, $num_msgs, $start_msg,
  507. $msort, $mailbox, $sort, $color, $show_num,0,0);
  508. echo '</table></td></tr></table>';
  509. mail_message_listing_end ($num_msgs, $paginator_str, $msg_cnt_str, $color);
  510. echo '</table>';
  511. echo "\n</form>\n\n";
  512. //$t = elapsed($start);
  513. //echo("elapsed time = $t seconds\n");
  514. }
  515. function calc_msort ($msgs, $sort, $mailbox = 'INBOX') {
  516. /*
  517. * 0 = Date (up)
  518. * 1 = Date (dn)
  519. * 2 = Name (up)
  520. * 3 = Name (dn)
  521. * 4 = Subject (up)
  522. * 5 = Subject (dn)
  523. * 6 = default no sort
  524. * 7 - UNUSED
  525. * 8 = Size (up)
  526. * 9 = Size (dn)
  527. */
  528. global $internal_date_sort;
  529. if (($sort == 0) || ($sort == 1)) {
  530. foreach ($msgs as $item) {
  531. if ($internal_date_sort)
  532. $msort[] = $item['RECEIVED_TIME_STAMP'];
  533. else
  534. $msort[] = $item['TIME_STAMP'];
  535. }
  536. } elseif (($sort == 2) || ($sort == 3)) {
  537. $fld_sort = (handleAsSent ($mailbox)?'TO-SORT':'FROM-SORT');
  538. foreach ($msgs as $item) {
  539. $msort[] = $item[$fld_sort];
  540. }
  541. } elseif (($sort == 4) || ($sort == 5)) {
  542. foreach ($msgs as $item) {
  543. $msort[] = $item['SUBJECT-SORT'];
  544. }
  545. } elseif (($sort == 8) || ($sort == 9)) {
  546. foreach ($msgs as $item) {
  547. $msort[] = $item['SIZE'];
  548. }
  549. } else {
  550. $msort = $msgs;
  551. }
  552. if ($sort != 6) {
  553. if ($sort % 2) {
  554. asort ($msort);
  555. } else {
  556. arsort ($msort);
  557. }
  558. }
  559. return $msort;
  560. }
  561. function fillMessageArray ($imapConnection, $id, $count, $show_num=false) {
  562. return sqimap_get_small_header_list ($imapConnection, $id, $show_num);
  563. }
  564. /* Generic function to convert the msgs array into an HTML table. */
  565. function displayMessageArray ($imapConnection, $num_msgs, $start_msg,
  566. $msort, $mailbox, $sort, $color,
  567. $show_num, $where=0, $what=0) {
  568. global $imapServerAddress , $use_mailbox_cache, $index_order,
  569. $indent_array, $thread_sort_messages, $allow_server_sort ,
  570. $server_sort_order, $PHP_SELF;
  571. $res = getEndMessage ($start_msg, $show_num, $num_msgs);
  572. $start_msg = $res[0];
  573. $end_msg = $res[1];
  574. $urlMailbox = urlencode ($mailbox);
  575. /* get indent level for subject display */
  576. if ($thread_sort_messages == 1 && $num_msgs) {
  577. $indent_array = get_parent_level ($imapConnection);
  578. }
  579. $real_startMessage = $start_msg;
  580. if ($sort == 6) {
  581. if ($end_msg - $start_msg < $show_num - 1) {
  582. $end_msg = $end_msg - $start_msg + 1;
  583. $start_msg = 1;
  584. } else if ($start_msg > $show_num) {
  585. $end_msg = $show_num;
  586. $start_msg = 1;
  587. }
  588. }
  589. $endVar = $end_msg + 1;
  590. /*
  591. * Loop through and display the info for each message.
  592. * ($t is used for the checkbox number)
  593. */
  594. $t = 0;
  595. /* messages display */
  596. if (!$num_msgs) {
  597. /* if there's no messages in this folder */
  598. echo html_tag ( 'tr',
  599. html_tag ( 'td',
  600. "<br><b>" . _ ("THIS FOLDER IS EMPTY") . "</b><br>&nbsp;",
  601. 'center',
  602. $color[4],
  603. 'colspan="' . count ($index_order) . '"'
  604. )
  605. );
  606. } elseif ($start_msg == $end_msg) {
  607. /* if there's only one message in the box, handle it differently. */
  608. if ($sort != 6) {
  609. $i = $start_msg;
  610. } else {
  611. $i = 1;
  612. }
  613. reset ($msort);
  614. $k = 0;
  615. do {
  616. $key = key ($msort);
  617. next ($msort);
  618. $k++;
  619. } while (isset ($key) && ($k < $i));
  620. printMessageInfo ($imapConnection, $t, true, $key, $mailbox,
  621. $real_startMessage, $where, $what);
  622. } else {
  623. $i = $start_msg;
  624. reset ($msort);
  625. $k = 0;
  626. do {
  627. $key = key ($msort);
  628. next ($msort);
  629. $k++;
  630. } while (isset ($key) && ($k < $i));
  631. $not_last = true;
  632. do {
  633. if (!$i || $i == $endVar-1) $not_last = false;
  634. printMessageInfo ($imapConnection, $t, $not_last, $key, $mailbox,
  635. $real_startMessage, $where, $what);
  636. $key = key ($msort);
  637. $t++;
  638. $i++;
  639. next ($msort);
  640. } while ($i && $i < $endVar);
  641. }
  642. }
  643. /*
  644. * Displays the standard message list header. To finish the table,
  645. * you need to do a "</table></table>";
  646. *
  647. * $moveURL is the URL to submit the delete/move form to
  648. * $mailbox is the current mailbox
  649. * $sort is the current sorting method (-1 for no sorting available [searches])
  650. * $Message is a message that is centered on top of the list
  651. * $More is a second line that is left aligned
  652. */
  653. function mail_message_listing_beginning ($imapConnection,
  654. $mailbox = '', $sort = -1,
  655. $msg_cnt_str = '',
  656. $paginator = '&nbsp;',
  657. $start_msg = 1) {
  658. global $color, $auto_expunge, $base_uri, $thread_sort_messages,
  659. $allow_thread_sort , $allow_server_sort , $server_sort_order,
  660. $PHP_SELF, $javascript_on;
  661. $php_self = $PHP_SELF;
  662. /* fix for incorrect $PHP_SELF */
  663. if (strpos ($php_self, 'move_messages.php')) {
  664. $php_self = str_replace ('move_messages.php', 'right_main.php', $php_self);
  665. }
  666. $urlMailbox = urlencode ($mailbox);
  667. if (preg_match ('/^(.+)\?.+$/',$php_self,$regs)) {
  668. $source_url = $regs[1];
  669. } else {
  670. $source_url = $php_self;
  671. }
  672. if ($javascript_on) {
  673. $safe_name = preg_replace ("/[^0-9A-Za-z_]/", '_', $mailbox);
  674. $form_name = "FormMsgs" . $safe_name;
  675. $func_name = "CheckAll" . $safe_name;
  676. echo '<script language="JavaScript" type="text/javascript">'
  677. . "\n<!-- \n"
  678. . "function " . $func_name . "() {\n"
  679. . " var c;\n"
  680. . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n"
  681. . " c = document." . $form_name . ".elements[i];\n"
  682. . " if(c.type == 'checkbox' && c.name.substring(0,3) == 'msg'){\n"
  683. . " c.checked = !c.checked;\n"
  684. . " }\n"
  685. . " }\n"
  686. . "}\n"
  687. . "//-->\n"
  688. . '</script>';
  689. }
  690. /*
  691. * This is the beginning of the message list table.
  692. * It wraps around all messages
  693. */
  694. if (!empty($paginator) && !empty($msg_cnt_str)) {
  695. echo html_tag ( 'table' ,
  696. html_tag ( 'tr',
  697. html_tag ( 'td' ,
  698. html_tag ( 'table' ,
  699. html_tag ( 'tr',
  700. html_tag ( 'td', $paginator, 'left' ) .
  701. html_tag ( 'td', $msg_cnt_str, 'right' )
  702. )
  703. , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
  704. , 'left', '', '' )
  705. , '', $color[0] )
  706. , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
  707. }
  708. /* line between header and button area */
  709. echo '</td></tr><tr><td height="5" bgcolor="'.$color[4].'"></td></tr>';
  710. echo html_tag ( 'tr' ) . "\n"
  711. . html_tag ( 'td' ,'' , 'left', '', '' )
  712. . html_tag ( 'table' ,'' , '', $color[9], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
  713. . '<tr><td>'
  714. . html_tag ( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
  715. . html_tag ( 'tr',
  716. getSmallStringCell (_ ("Move Selected To"), 'left', 'nowrap') .
  717. getSmallStringCell (_ ("Transform Selected Messages"), 'right')
  718. )
  719. . html_tag ( 'tr' ) ."\n"
  720. . html_tag ( 'td', '', 'left', '', 'valign="middle" nowrap' );
  721. getMbxList ($imapConnection);
  722. echo getButton ('SUBMIT', 'moveButton',_ ("Move")) . "\n";
  723. echo getButton ('SUBMIT', 'attache',_ ("Forward")) . "\n";
  724. do_hook ('mailbox_display_buttons');
  725. echo " </td>\n"
  726. . html_tag ( 'td', '', 'right', '', 'nowrap' );
  727. if (!$auto_expunge) {
  728. echo getButton ('SUBMIT', 'expungeButton',_ ("Expunge")) ."\n";
  729. }
  730. echo getButton ('SUBMIT', 'markRead',_ ("Read")) . "\n";
  731. echo getButton ('SUBMIT', 'markUnread',_ ("Unread")) . "\n";
  732. echo getButton ('SUBMIT', 'delete',_ ("Delete")) ."&nbsp;\n";
  733. if (!strpos ($php_self,'mailbox')) {
  734. $location = $php_self.'?mailbox=INBOX&amp;startMessage=1';
  735. } else {
  736. $location = $php_self;
  737. }
  738. // $location = urlencode($location);
  739. echo '<input type="hidden" name="location" value="'.$location.'">';
  740. echo "</td>\n"
  741. . " </tr>\n";
  742. /* draws thread sorting links */
  743. if ($allow_thread_sort == TRUE) {
  744. if ($thread_sort_messages == 1 ) {
  745. $set_thread = 2;
  746. $thread_name = _ ("Unthread View");
  747. } elseif ($thread_sort_messages == 0) {
  748. $set_thread = 1;
  749. $thread_name = _ ("Thread View");
  750. }
  751. echo html_tag ( 'tr' ,
  752. html_tag ( 'td' ,
  753. '&nbsp;<small><a href="' . $source_url . '?sort='
  754. . "$sort" . '&amp;start_messages=1&amp;set_thread=' . "$set_thread"
  755. . '&amp;mailbox=' . urlencode ($mailbox) . '">' . $thread_name
  756. . '</a></small>&nbsp;'
  757. , '', '', ' colspan="2" ' )
  758. , '', '', '' );
  759. }
  760. echo "</table></td></tr></table></td></tr>\n";
  761. do_hook ('mailbox_form_before');
  762. /* if using server sort we highjack the
  763. * the $sort var and use $server_sort_order
  764. * instead. but here we reset sort for a bit
  765. * since its easy
  766. */
  767. if ($allow_server_sort == TRUE) {
  768. $sort = $server_sort_order;
  769. }
  770. }
  771. function mail_message_listing_end ($num_msgs, $paginator_str, $msg_cnt_str, $color) {
  772. if ($num_msgs) {
  773. /* space between list and footer */
  774. echo '<tr><td height="5" bgcolor="'.$color[4].'" colspan="1">';
  775. echo '</td></tr><tr><td>';
  776. echo html_tag ( 'table',
  777. html_tag ( 'tr',
  778. html_tag ( 'td',
  779. html_tag ( 'table',
  780. html_tag ( 'tr',
  781. html_tag ( 'td', $paginator_str ) .
  782. html_tag ( 'td', $msg_cnt_str, 'right' )
  783. )
  784. , '', $color[4], 'width="100%" border="0" cellpadding="1" cellspacing="0"' )
  785. )
  786. )
  787. , '', $color[9], 'width="100%" border="0" cellpadding="1" cellspacing="0"' );
  788. echo '</td></tr>';
  789. }
  790. /* End of message-list table */
  791. do_hook ('mailbox_index_after');
  792. }
  793. function printHeader ($mailbox, $sort, $color, $showsort=true) {
  794. global $index_order, $internal_date_sort, $imap_server_type ;
  795. // gmail doesn't support custom sorting, so we always
  796. // hide the sort buttons when using gmail
  797. if ($imap_server_type == 'gmail') $showsort = false;
  798. echo html_tag ( 'tr' ,'' , 'center', $color[5] );
  799. /* calculate the width of the subject column based on the
  800. * widths of the other columns */
  801. $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
  802. $subjectwidth = 100;
  803. foreach($index_order as $item) {
  804. $subjectwidth -= $widths[$item];
  805. }
  806. foreach ($index_order as $item) {
  807. switch ($item) {
  808. case 1: /* checkbox */
  809. case 5: /* flags */
  810. echo html_tag ( 'td' ,'&nbsp;' , '', '', 'width="1%"' );
  811. break;
  812. case 2: /* from */
  813. if (handleAsSent ($mailbox)) {
  814. echo html_tag ( 'td' ,'' , 'left', '', 'width="25%"' )
  815. . '<b>' . _ ("To") . '</b>';
  816. } else {
  817. echo html_tag ( 'td' ,'' , 'left', '', 'width="25%"' )
  818. . '<b>' . _ ("From") . '</b>';
  819. }
  820. if ($showsort) {
  821. ShowSortButton ($sort, $mailbox, 2, 3);
  822. }
  823. echo "</td>\n";
  824. break;
  825. case 3: /* date */
  826. echo html_tag ( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
  827. . '<b>'
  828. . ($internal_date_sort && ($sort == 0 || $sort == 1) ? _ ("Received") : _ ("Date"))
  829. . '</b>';
  830. if ($showsort) {
  831. ShowSortButton ($sort, $mailbox, 0, 1);
  832. }
  833. echo "</td>\n";
  834. break;
  835. case 4: /* subject */
  836. echo html_tag ( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
  837. . '<b>' . _ ("Subject") . '</b>';
  838. if ($showsort) {
  839. ShowSortButton ($sort, $mailbox, 4, 5);
  840. }
  841. echo "</td>\n";
  842. break;
  843. case 6: /* size */
  844. echo html_tag ( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
  845. . '<b>' . _ ("Size") . '</b>';
  846. if ($showsort) {
  847. ShowSortButton ($sort, $mailbox, 8, 9);
  848. }
  849. echo "</td>\n";
  850. break;
  851. }
  852. }
  853. echo "</tr>\n";
  854. }
  855. /*
  856. * This function shows the sort button. Isn't this a good comment?
  857. */
  858. function ShowSortButton ($sort, $mailbox, $Up, $Down ) {
  859. global $PHP_SELF;
  860. /* Figure out which image we want to use. */
  861. if ($sort != $Up && $sort != $Down) {
  862. $img = 'sort_none.png';
  863. $which = $Up;
  864. } elseif ($sort == $Up) {
  865. $img = 'up_pointer.png';
  866. $which = $Down;
  867. } else {
  868. $img = 'down_pointer.png';
  869. $which = 6;
  870. }
  871. if (preg_match ('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
  872. $source_url = $regs[1];
  873. } else {
  874. $source_url = $PHP_SELF;
  875. }
  876. /* Now that we have everything figured out, show the actual button. */
  877. echo ' <a href="' . $source_url .'?newsort=' . $which
  878. . '&amp;startMessage=1&amp;mailbox=' . urlencode ($mailbox)
  879. . '"><img src="../images/' . $img
  880. . '" border="0" width="12" height="10" alt="sort"></a>';
  881. }
  882. function get_selectall_link ($start_msg, $sort) {
  883. global $checkall, $what, $where, $mailbox, $javascript_on;
  884. global $PHP_SELF, $PG_SHOWNUM;
  885. $whitespace_style = ' style="white-space:nowrap" ';
  886. $result = '';
  887. if ($javascript_on) {
  888. $safe_name = preg_replace ("/[^0-9A-Za-z_]/", '_', $mailbox);
  889. $func_name = "CheckAll" . $safe_name;
  890. $result = '<a href="javascript:void(0)" onClick="' . $func_name . '();"' . $whitespace_style . '>' . _ ("Toggle All")
  891. /* . '</script><a href="javascript:' . $func_name . '()">' . _("Toggle All")*/
  892. . "</a>\n";
  893. } else {
  894. if (strpos ($PHP_SELF, "?")) {
  895. $result .= "<a href=\"$PHP_SELF&amp;mailbox=" . urlencode ($mailbox)
  896. . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
  897. } else {
  898. $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode ($mailbox)
  899. . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
  900. }
  901. if (isset($checkall) && $checkall == '1') {
  902. $result .= '0';
  903. } else {
  904. $result .= '1';
  905. }
  906. if (isset($where) && isset($what)) {
  907. $result .= '&amp;where=' . urlencode ($where)
  908. . '&amp;what=' . urlencode ($what);
  909. }
  910. $result .= "\"$whitespace_style>";
  911. if (isset($checkall) && ($checkall == '1')) {
  912. $result .= _ ("Unselect All");
  913. } else {
  914. $result .= _ ("Select All");
  915. }
  916. $result .= "</a>\n";
  917. }
  918. /* Return our final result. */
  919. return ($result);
  920. }
  921. /*
  922. * This function computes the "Viewing Messages..." string.
  923. */
  924. function get_msgcnt_str ($start_msg, $end_msg, $num_msgs) {
  925. /* Compute the $msg_cnt_str. */
  926. $result = '';
  927. if ($start_msg < $end_msg) {
  928. $result = sprintf (_ ("Viewing Messages: %s to %s (%s total)"),
  929. '<b>'.$start_msg.'</b>', '<b>'.$end_msg.'</b>', $num_msgs);
  930. } else if ($start_msg == $end_msg) {
  931. $result = sprintf (_ ("Viewing Message: %s (%s total)"), '<b>'.$start_msg.'</b>', $num_msgs);
  932. } else {
  933. $result = '<br>';
  934. }
  935. /* Return our result string. */
  936. return ($result);
  937. }
  938. /*
  939. * Generate a paginator link.
  940. */
  941. function get_paginator_link ($box, $start_msg, $use, $text) {
  942. global $PHP_SELF;
  943. $result = "<a href=\"right_main.php?use_mailbox_cache=$use"
  944. . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
  945. . ">$text</a>";
  946. return ($result);
  947. /*
  948. if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
  949. $source_url = $regs[1];
  950. } else {
  951. $source_url = $PHP_SELF;
  952. }
  953. $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
  954. . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
  955. . ">$text</A>";
  956. return ($result);
  957. */
  958. }
  959. /*
  960. * This function computes the paginator string.
  961. */
  962. function get_paginator_str ($box, $start_msg, $end_msg, $num_msgs,
  963. $show_num, $sort) {
  964. global $username, $data_dir , $use_mailbox_cache, $color, $PG_SHOWNUM;
  965. /* Initialize paginator string chunks. */
  966. $prv_str = '';
  967. $nxt_str = '';
  968. $pg_str = '';
  969. $all_str = '';
  970. $tgl_str = '';
  971. $box = urlencode ($box);
  972. /* Create simple strings that will be creating the paginator. */
  973. $spc = '&nbsp;'; /* This will be used as a space. */
  974. $sep = '|'; /* This will be used as a seperator. */
  975. /* Get some paginator preference values. */
  976. $pg_sel = getPref ($data_dir, $username, 'page_selector', SMPREF_ON );
  977. $pg_max = getPref ($data_dir, $username, 'page_selector_max', PG_SEL_MAX );
  978. /* Make sure that our start message number is not too big. */
  979. $start_msg = min ($start_msg, $num_msgs);
  980. /* Decide whether or not we will use the mailbox cache. */
  981. /* Not sure why $use_mailbox_cache is even passed in. */
  982. if ($sort == 6) {
  983. $use = 0;
  984. } else {
  985. $use = 1;
  986. }
  987. /* Compute the starting message of the previous and next page group. */
  988. $next_grp = $start_msg + $show_num;
  989. $prev_grp = $start_msg - $show_num;
  990. /* Compute the basic previous and next strings. */
  991. if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
  992. $prv_str = get_paginator_link ($box, $prev_grp, $use, _ ("Previous"));
  993. $nxt_str = get_paginator_link ($box, $next_grp, $use, _ ("Next"));
  994. } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
  995. $prv_str = get_paginator_link ($box, $prev_grp, $use, _ ("Previous"));
  996. $nxt_str = "<font color=\"$color[9]\">"._ ("Next")."</font>\n";
  997. } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
  998. $prv_str = "<font color=\"$color[9]\">"._ ("Previous") . '</font>';
  999. $nxt_str = get_paginator_link ($box, $next_grp, $use, _ ("Next"));
  1000. }
  1001. /* Page selector block. Following code computes page links. */
  1002. if ($pg_sel && ($num_msgs > $show_num)) {
  1003. /* Most importantly, what is the current page!!! */
  1004. $cur_pg = intval ($start_msg / $show_num) + 1;
  1005. /* Compute total # of pages and # of paginator page links. */
  1006. $tot_pgs = ceil ($num_msgs / $show_num); /* Total number of Pages */
  1007. $vis_pgs = min ($pg_max, $tot_pgs - 1); /* Visible Pages */
  1008. /* Compute the size of the four quarters of the page links. */
  1009. /* If we can, just show all the pages. */
  1010. if (($tot_pgs - 1) <= $pg_max) {
  1011. $q1_pgs = $cur_pg - 1;
  1012. $q2_pgs = $q3_pgs = 0;
  1013. $q4_pgs = $tot_pgs - $cur_pg;
  1014. /* Otherwise, compute some magic to choose the four quarters. */
  1015. } else {
  1016. /*
  1017. * Compute the magic base values. Added together,
  1018. * these values will always equal to the $pag_pgs.
  1019. * NOTE: These are DEFAULT values and do not take
  1020. * the current page into account. That is below.
  1021. */
  1022. $q1_pgs = floor ($vis_pgs/4);
  1023. $q2_pgs = round ($vis_pgs/4, 0);
  1024. $q3_pgs = ceil ($vis_pgs/4);
  1025. $q4_pgs = round (($vis_pgs - $q2_pgs)/3, 0);
  1026. /* Adjust if the first quarter contains the current page. */
  1027. if (($cur_pg - $q1_pgs) < 1) {
  1028. $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
  1029. $q1_pgs = $cur_pg - 1;
  1030. $q2_pgs = 0;
  1031. $q3_pgs += ceil ($extra_pgs / 2);
  1032. $q4_pgs += floor ($extra_pgs / 2);
  1033. /* Adjust if the first and second quarters intersect. */
  1034. } else if (($cur_pg - $q2_pgs - ceil ($q2_pgs/3)) <= $q1_pgs) {
  1035. $extra_pgs = $q2_pgs;
  1036. $extra_pgs -= ceil (($cur_pg - $q1_pgs - 1) * 3/4);
  1037. $q2_pgs = ceil (($cur_pg - $q1_pgs - 1) * 3/4);
  1038. $q3_pgs += ceil ($extra_pgs / 2);
  1039. $q4_pgs += floor ($extra_pgs / 2);
  1040. /* Adjust if the fourth quarter contains the current page. */
  1041. } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
  1042. $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
  1043. $q3_pgs = 0;
  1044. $q4_pgs = $tot_pgs - $cur_pg;
  1045. $q1_pgs += floor ($extra_pgs / 2);
  1046. $q2_pgs += ceil ($extra_pgs / 2);
  1047. /* Adjust if the third and fourth quarter intersect. */
  1048. } else if (($cur_pg + $q3_pgs) >= ($tot_pgs - $q4_pgs)) {
  1049. $extra_pgs = $q3_pgs;
  1050. $extra_pgs -= ceil (($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
  1051. $q3_pgs = ceil (($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
  1052. $q1_pgs += floor ($extra_pgs / 2);
  1053. $q2_pgs += ceil ($extra_pgs / 2);
  1054. }
  1055. }
  1056. /*
  1057. * I am leaving this debug code here, commented out, because
  1058. * it is a really nice way to see what the above code is doing.
  1059. */
  1060. // echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
  1061. // . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
  1062. /* Print out the page links from the compute page quarters. */
  1063. /* Start with the first quarter. */
  1064. if (($q1_pgs == 0) && ($cur_pg > 1)) {
  1065. $pg_str .= "...$spc";
  1066. } else {
  1067. for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
  1068. $start = (($pg-1) * $show_num) + 1;
  1069. $pg_str .= get_paginator_link ($box, $start, $use, $pg) . $spc;
  1070. }
  1071. if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
  1072. $pg_str .= "...$spc";
  1073. }
  1074. }
  1075. /* Continue with the second quarter. */
  1076. for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
  1077. $start = (($pg-1) * $show_num) + 1;
  1078. $pg_str .= get_paginator_link ($box, $start, $use, $pg) . $spc;
  1079. }
  1080. /* Now print the current page. */
  1081. $pg_str .= $cur_pg . $spc;
  1082. /* Next comes the third quarter. */
  1083. for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
  1084. $start = (($pg-1) * $show_num) + 1;
  1085. $pg_str .= get_paginator_link ($box, $start, $use, $pg) . $spc;
  1086. }
  1087. /* And last, print the forth quarter page links. */
  1088. if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
  1089. $pg_str .= "...$spc";
  1090. } else {
  1091. if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
  1092. $pg_str .= "...$spc";
  1093. }
  1094. for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
  1095. $start = (($pg-1) * $show_num) + 1;
  1096. $pg_str .= get_paginator_link ($box, $start, $use, $pg) . $spc;
  1097. }
  1098. }
  1099. } else if ($PG_SHOWNUM == 999999) {
  1100. $pg_str = "<a href=\"right_main.php?PG_SHOWALL=0"
  1101. . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
  1102. . ">" ._ ("Paginate") . '</a>' . $spc;
  1103. }
  1104. /* If necessary, compute the 'show all' string. */
  1105. if (($prv_str != '') || ($nxt_str != '')) {
  1106. $all_str = "<a href=\"right_main.php?PG_SHOWALL=1"
  1107. . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
  1108. . "style=\"white-space:nowrap\">" . _ ("Show All") . '</a>';
  1109. }
  1110. /* Last but not least, get the value for the toggle all link. */
  1111. $tgl_str = get_selectall_link ($start_msg, $sort);
  1112. /* Put all the pieces of the paginator string together. */
  1113. /**
  1114. * Hairy code... But let's leave it like it is since I am not certain
  1115. * a different approach would be any easier to read. ;)
  1116. */
  1117. $result = '';
  1118. $result .= ($prv_str != '' ? $prv_str . $spc . $sep . ' ' : '');
  1119. $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . ' ' : '');
  1120. $result .= ($pg_str != '' ? $pg_str : '');
  1121. $result .= ($all_str != '' ? $sep . ' ' . $all_str . $spc : '');
  1122. $result .= ($result != '' ? $sep . ' ' . $tgl_str: $tgl_str);
  1123. /* If the resulting string is blank, return a non-breaking space. */
  1124. if ($result == '') {
  1125. $result = '&nbsp;';
  1126. }
  1127. /* Return our final magical paginator string. */
  1128. return ($result);
  1129. }
  1130. function processSubject ($subject, $threadlevel = 0) {
  1131. global $languages , $squirrelmail_language;
  1132. /* Shouldn't ever happen -- caught too many times in the IMAP functions */
  1133. if ($subject == '') {
  1134. return _ ("(no subject)");
  1135. }
  1136. $trim_at = SUBJ_TRIM_AT ;
  1137. /* if this is threaded, subtract two chars per indentlevel */
  1138. if($threadlevel > 0 && $threadlevel <= 10) {
  1139. $trim_at -= (2*$threadlevel);
  1140. }
  1141. if (strlen ($subject) <= $trim_at) {
  1142. return $subject;
  1143. }
  1144. $ent_strlen = $orig_len = strlen ($subject);
  1145. $trim_val = $trim_at - 5;
  1146. $ent_offset = 0;
  1147. /*
  1148. * see if this is entities-encoded string
  1149. * If so, Iterate through the whole string, find out
  1150. * the real number of characters, and if more
  1151. * than 55, substr with an updated trim value.
  1152. */
  1153. $step = $ent_loc = 0;
  1154. while ( $ent_loc < $trim_val && (($ent_loc = strpos ($subject, '&', $ent_offset)) !== false) &&
  1155. (($ent_loc_end = strpos ($subject, ';', $ent_loc+3)) !== false) ) {
  1156. $trim_val += ($ent_loc_end-$ent_loc);
  1157. $ent_offset = $ent_loc_end+1;
  1158. ++$step;
  1159. }
  1160. if (($trim_val > 50) && (strlen ($subject) > ($trim_val))&& (strpos ($subject,';',$trim_val) < ($trim_val +6))) {
  1161. $i = strpos ($subject,';',$trim_val);
  1162. if ($i) {
  1163. $trim_val = strpos ($subject,';',$trim_val);
  1164. }
  1165. }
  1166. if ($ent_strlen <= $trim_at){
  1167. return $subject;
  1168. }
  1169. if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
  1170. function_exists ($languages[$squirrelmail_language]['XTRA_CODE'])) {
  1171. return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
  1172. }
  1173. // only print '...' when we're actually dropping part of the subject
  1174. if(strlen ($subject) <= $trim_val) {
  1175. return $subject;
  1176. } else {
  1177. return substr ($subject, 0, $trim_val) . '...';
  1178. }
  1179. }
  1180. function getMbxList ($imapConnection) {
  1181. global $lastTargetMailbox;
  1182. echo ' &nbsp;<tt><select name="targetMailbox">';
  1183. echo sqimap_mailbox_option_list ($imapConnection, array(strtolower ($lastTargetMailbox)) );
  1184. echo ' </select></tt>&nbsp;';
  1185. }
  1186. function getButton ($type, $name, $value) {
  1187. return '<input type="'.$type.'" name="'.$name.'" value="'.$value . '">';
  1188. }
  1189. function getSmallStringCell ($string, $align) {
  1190. return html_tag ('td',
  1191. '<small>' . $string . ':&nbsp; </small>',
  1192. $align,
  1193. '',
  1194. 'nowrap' );
  1195. }
  1196. function getEndMessage ($start_msg, $show_num, $num_msgs) {
  1197. if ($start_msg + ($show_num - 1) < $num_msgs){
  1198. $end_msg = $start_msg + ($show_num - 1);
  1199. } else {
  1200. $end_msg = $num_msgs;
  1201. }
  1202. if ($end_msg < $start_msg) {
  1203. $start_msg = $start_msg - $show_num;
  1204. if ($start_msg < 1) {
  1205. $start_msg = 1;
  1206. }
  1207. }
  1208. return (array($start_msg,$end_msg));
  1209. }
  1210. function handleAsSent ($mailbox) {
  1211. global $handleAsSent_result;
  1212. /* First check if this is the sent or draft folder. */
  1213. $handleAsSent_result = isSentMailbox ($mailbox) || isDraftMailbox ($mailbox);
  1214. /* Then check the result of the handleAsSent hook. */
  1215. do_hook ('check_handleAsSent_result', $mailbox);
  1216. /* And return the result. */
  1217. return $handleAsSent_result;
  1218. }

Documentation generated on 2020年1月13日 04:24:54 +0100 by phpDocumentor 1.4.3

AltStyle によって変換されたページ (->オリジナル) /