PageRenderTime 64ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

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

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