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

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

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