PageRenderTime 71ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1_4_13/functions/mailbox_display.php

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