PageRenderTime 81ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/webmail-release-1_4_22/functions/mailbox_display.php

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