PageRenderTime 57ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/tags/rel-1_4_4-rc1/squirrelmail/functions/mailbox_display.php

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