PageRenderTime 77ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/SM_Devel_NoFrames/squirrelmail/functions/mailbox_display.php

#
PHP | 1339 lines | 1040 code | 134 blank | 165 comment | 263 complexity | d2dd58489c2fc08947ef63bca1019077 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 6236 2003-12-03 19:53:47Z cigamit $
  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. $id = get_thread_sort($imapConnection);
  438. $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
  439. if ($msgs === false) {
  440. echo '<b><small><center><font color=red>' .
  441. _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
  442. '</center></small></b>';
  443. $thread_sort_messages = 0;
  444. $msort = $msgs = array();
  445. } else {
  446. $msort= $msgs;
  447. $sort = 6;
  448. }
  449. break;
  450. case 'serversort':
  451. $id = sqimap_get_sort_order($imapConnection, $sort, $mbxresponse);
  452. $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
  453. if ($msgs === false) {
  454. echo '<b><small><center><font color=red>' .
  455. _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
  456. '</center></small></b>';
  457. $sort = $server_sort_order;
  458. $allow_server_sort = FALSE;
  459. $msort = $msgs = array();
  460. $id = array();
  461. } else {
  462. $msort = $msgs;
  463. $sort = 6;
  464. }
  465. break;
  466. default:
  467. if (!$use_cache) {
  468. $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
  469. $num_msgs, $sort, $mbxresponse);
  470. $msort = calc_msort($msgs, $sort);
  471. } /* !use cache */
  472. break;
  473. } // switch
  474. sqsession_register($msort, 'msort');
  475. sqsession_register($msgs, 'msgs');
  476. } /* if exists > 0 */
  477. $res = getEndMessage($start_msg, $show_num, $num_msgs);
  478. $start_msg = $res[0];
  479. $end_msg = $res[1];
  480. $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
  481. $num_msgs, $show_num, $sort);
  482. $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
  483. do_hook('mailbox_index_before');
  484. echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">';
  485. echo '<tr><td>';
  486. mail_message_listing_beginning($imapConnection, $mailbox, $sort,
  487. $msg_cnt_str, $paginator_str, $start_msg);
  488. echo '</td></tr>';
  489. /* line between the button area and the list */
  490. echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
  491. echo '<tr><td>';
  492. echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
  493. echo ' <tr><td>';
  494. echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">';
  495. echo '<tr><td>';
  496. printHeader($mailbox, $srt, $color, !$thread_sort_messages);
  497. displayMessageArray($imapConnection, $num_msgs, $start_msg,
  498. $msort, $mailbox, $sort, $color, $show_num,0,0);
  499. echo '</td></tr></table></td></tr></table>';
  500. mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
  501. echo '</td></tr></table>';
  502. //$t = elapsed($start);
  503. //echo("elapsed time = $t seconds\n");
  504. }
  505. function calc_msort($msgs, $sort) {
  506. /*
  507. * 0 = Date (up)
  508. * 1 = Date (dn)
  509. * 2 = Name (up)
  510. * 3 = Name (dn)
  511. * 4 = Subject (up)
  512. * 5 = Subject (dn)
  513. */
  514. if (($sort == 0) || ($sort == 1)) {
  515. foreach ($msgs as $item) {
  516. $msort[] = $item['TIME_STAMP'];
  517. }
  518. } elseif (($sort == 2) || ($sort == 3)) {
  519. foreach ($msgs as $item) {
  520. $msort[] = $item['FROM-SORT'];
  521. }
  522. } elseif (($sort == 4) || ($sort == 5)) {
  523. foreach ($msgs as $item) {
  524. $msort[] = $item['SUBJECT-SORT'];
  525. }
  526. } else {
  527. $msort = $msgs;
  528. }
  529. if ($sort < 6) {
  530. if ($sort % 2) {
  531. asort($msort);
  532. } else {
  533. arsort($msort);
  534. }
  535. }
  536. return $msort;
  537. }
  538. function fillMessageArray($imapConnection, $id, $count, $show_num=false) {
  539. return sqimap_get_small_header_list($imapConnection, $id, $show_num);
  540. }
  541. /* Generic function to convert the msgs array into an HTML table. */
  542. function displayMessageArray($imapConnection, $num_msgs, $start_msg,
  543. $msort, $mailbox, $sort, $color,
  544. $show_num, $where=0, $what=0) {
  545. global $imapServerAddress, $use_mailbox_cache, $index_order,
  546. $indent_array, $thread_sort_messages, $allow_server_sort,
  547. $server_sort_order, $PHP_SELF;
  548. $res = getEndMessage($start_msg, $show_num, $num_msgs);
  549. $start_msg = $res[0];
  550. $end_msg = $res[1];
  551. $urlMailbox = urlencode($mailbox);
  552. /* get indent level for subject display */
  553. if ($thread_sort_messages == 1 && $num_msgs) {
  554. $indent_array = get_parent_level($imapConnection);
  555. }
  556. $real_startMessage = $start_msg;
  557. if ($sort == 6) {
  558. if ($end_msg - $start_msg < $show_num - 1) {
  559. $end_msg = $end_msg - $start_msg + 1;
  560. $start_msg = 1;
  561. } else if ($start_msg > $show_num) {
  562. $end_msg = $show_num;
  563. $start_msg = 1;
  564. }
  565. }
  566. $endVar = $end_msg + 1;
  567. /*
  568. * Loop through and display the info for each message.
  569. * ($t is used for the checkbox number)
  570. */
  571. $t = 0;
  572. /* messages display */
  573. if (!$num_msgs) {
  574. /* if there's no messages in this folder */
  575. echo html_tag( 'tr',
  576. html_tag( 'td',
  577. "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR>&nbsp;",
  578. 'center',
  579. $color[4],
  580. 'COLSPAN="' . count($index_order) . '"'
  581. )
  582. );
  583. } elseif ($start_msg == $end_msg) {
  584. /* if there's only one message in the box, handle it differently. */
  585. if ($sort != 6) {
  586. $i = $start_msg;
  587. } else {
  588. $i = 1;
  589. }
  590. reset($msort);
  591. $k = 0;
  592. do {
  593. $key = key($msort);
  594. next($msort);
  595. $k++;
  596. } while (isset ($key) && ($k < $i));
  597. printMessageInfo($imapConnection, $t, true, $key, $mailbox,
  598. $real_startMessage, $where, $what);
  599. } else {
  600. $i = $start_msg;
  601. reset($msort);
  602. $k = 0;
  603. do {
  604. $key = key($msort);
  605. next($msort);
  606. $k++;
  607. } while (isset ($key) && ($k < $i));
  608. $not_last = true;
  609. do {
  610. if (!$i || $i == $endVar-1) $not_last = false;
  611. printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox,
  612. $real_startMessage, $where, $what);
  613. $key = key($msort);
  614. $t++;
  615. $i++;
  616. next($msort);
  617. } while ($i && $i < $endVar);
  618. }
  619. }
  620. /*
  621. * Displays the standard message list header. To finish the table,
  622. * you need to do a "</table></table>";
  623. *
  624. * $moveURL is the URL to submit the delete/move form to
  625. * $mailbox is the current mailbox
  626. * $sort is the current sorting method (-1 for no sorting available [searches])
  627. * $Message is a message that is centered on top of the list
  628. * $More is a second line that is left aligned
  629. */
  630. function mail_message_listing_beginning ($imapConnection,
  631. $mailbox = '', $sort = -1,
  632. $msg_cnt_str = '',
  633. $paginator = '&nbsp;',
  634. $start_msg = 1) {
  635. global $color, $auto_expunge, $base_uri, $thread_sort_messages,
  636. $allow_thread_sort, $allow_server_sort, $server_sort_order,
  637. $PHP_SELF;
  638. $php_self = $PHP_SELF;
  639. /* fix for incorrect $PHP_SELF */
  640. if (strpos($php_self, 'move_messages.php')) {
  641. $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
  642. }
  643. $urlMailbox = urlencode($mailbox);
  644. if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
  645. $source_url = $regs[1];
  646. } else {
  647. $source_url = $php_self;
  648. }
  649. if (!isset($msg)) {
  650. $msg = '';
  651. }
  652. $moveFields = '<input type="hidden" name="msg" value="'.htmlspecialchars($msg).'">' .
  653. '<input type="hidden" name="mailbox" value="'.htmlspecialchars($mailbox).'">' .
  654. '<input type="hidden" name="startMessage" value="'.htmlspecialchars($start_msg).'">';
  655. // $moveURL = "move_messages.php?msg=$msg&amp;mailbox=$urlMailbox"
  656. // . "&amp;startMessage=$start_msg";
  657. /*
  658. * This is the beginning of the message list table.
  659. * It wraps around all messages
  660. */
  661. $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
  662. $form_name = "FormMsgs" . $safe_name;
  663. echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' ."\n"
  664. . $moveFields
  665. . html_tag( 'table' ,
  666. html_tag( 'tr',
  667. html_tag( 'td' ,
  668. html_tag( 'table' ,
  669. html_tag( 'tr',
  670. html_tag( 'td', $paginator, 'left' ) .
  671. html_tag( 'td', $msg_cnt_str, 'right' )
  672. )
  673. , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
  674. , 'left', '', '' )
  675. , '', $color[0] )
  676. , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
  677. /* line between header and button area */
  678. echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
  679. echo '<tr><td>';
  680. echo html_tag( 'tr' ) . "\n"
  681. . html_tag( 'td' ,'' , 'left', '', '' )
  682. . html_tag( 'table' ,'' , '', $color[9], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
  683. . '<tr><td>'
  684. . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
  685. . html_tag( 'tr',
  686. getSmallStringCell(_("Move Selected To"), 'left', 'nowrap') .
  687. getSmallStringCell(_("Transform Selected Messages"), 'right')
  688. )
  689. . html_tag( 'tr' ) ."\n"
  690. . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
  691. getMbxList($imapConnection);
  692. echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
  693. echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
  694. echo " </TD>\n"
  695. . html_tag( 'td', '', 'right', '', 'nowrap' );
  696. if (!$auto_expunge) {
  697. echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
  698. .'&nbsp;' . _("mailbox") . "\n";
  699. }
  700. do_hook('mailbox_display_buttons');
  701. echo getButton('SUBMIT', 'markRead',_("Read"));
  702. echo getButton('SUBMIT', 'markUnread',_("Unread"));
  703. echo getButton('SUBMIT', 'delete',_("Delete")) ."&nbsp;\n";
  704. if (!strpos($php_self,'mailbox')) {
  705. $location = $php_self.'?mailbox=INBOX&amp;startMessage=1';
  706. } else {
  707. $location = $php_self;
  708. }
  709. echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">';
  710. echo "</TD>\n"
  711. . " </TR>\n";
  712. /* draws thread sorting links */
  713. if ($allow_thread_sort == TRUE) {
  714. if ($thread_sort_messages == 1 ) {
  715. $set_thread = 2;
  716. $thread_name = _("Unthread View");
  717. } elseif ($thread_sort_messages == 0) {
  718. $set_thread = 1;
  719. $thread_name = _("Thread View");
  720. }
  721. echo html_tag( 'tr' ,
  722. html_tag( 'td' ,
  723. '&nbsp;<a href=' . $source_url . '?sort='
  724. . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
  725. . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
  726. . '</a></small>&nbsp;'
  727. , '', '', '' ) . html_tag( 'td', _("Bypass Trash") . '<input type="checkbox" name="bypass_trash">','right','','')
  728. , '', '', '' );
  729. }
  730. echo "</TABLE></td></tr></table></td></tr>\n";
  731. do_hook('mailbox_form_before');
  732. /* if using server sort we highjack the
  733. * the $sort var and use $server_sort_order
  734. * instead. but here we reset sort for a bit
  735. * since its easy
  736. */
  737. if ($allow_server_sort == TRUE) {
  738. $sort = $server_sort_order;
  739. }
  740. }
  741. function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
  742. if ($num_msgs) {
  743. /* space between list and footer */
  744. echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'" COLSPAN="1">';
  745. echo '</td></tr><tr><td>';
  746. echo html_tag( 'table',
  747. html_tag( 'tr',
  748. html_tag( 'td',
  749. html_tag( 'table',
  750. html_tag( 'tr',
  751. html_tag( 'td', $paginator_str ) .
  752. html_tag( 'td', $msg_cnt_str, 'right' )
  753. )
  754. , '', $color[4], 'width="100%" border="0" cellpadding="1" cellspacing="0"' )
  755. )
  756. )
  757. , '', $color[9], 'width="100%" border="0" cellpadding="1" cellspacing="0"' );
  758. echo '</td></tr>';
  759. }
  760. /* End of message-list table */
  761. do_hook('mailbox_index_after');
  762. echo "</FORM>\n";
  763. }
  764. function printHeader($mailbox, $sort, $color, $showsort=true) {
  765. global $index_order;
  766. echo html_tag( 'tr' ,'' , 'center', $color[5] );
  767. /* calculate the width of the subject column based on the
  768. * widths of the other columns */
  769. $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
  770. $subjectwidth = 100;
  771. foreach($index_order as $item) {
  772. $subjectwidth -= $widths[$item];
  773. }
  774. foreach ($index_order as $item) {
  775. switch ($item) {
  776. case 1: /* checkbox */
  777. case 5: /* flags */
  778. echo html_tag( 'td' ,'&nbsp;' , '', '', 'width="1%"' );
  779. break;
  780. case 2: /* from */
  781. if (handleAsSent($mailbox)) {
  782. echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
  783. . '<b>' . _("To") . '</b>';
  784. } else {
  785. echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
  786. . '<b>' . _("From") . '</b>';
  787. }
  788. if ($showsort) {
  789. ShowSortButton($sort, $mailbox, 2, 3);
  790. }
  791. echo "</td>\n";
  792. break;
  793. case 3: /* date */
  794. echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
  795. . '<b>' . _("Date") . '</b>';
  796. if ($showsort) {
  797. ShowSortButton($sort, $mailbox, 0, 1);
  798. }
  799. echo "</td>\n";
  800. break;
  801. case 4: /* subject */
  802. echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
  803. . '<b>' . _("Subject") . '</b>';
  804. if ($showsort) {
  805. ShowSortButton($sort, $mailbox, 4, 5);
  806. }
  807. echo "</td>\n";
  808. break;
  809. case 6: /* size */
  810. echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%" nowrap' );
  811. break;
  812. }
  813. }
  814. echo "</tr>\n";
  815. }
  816. /*
  817. * This function shows the sort button. Isn't this a good comment?
  818. */
  819. function ShowSortButton($sort, $mailbox, $Up, $Down ) {
  820. global $PHP_SELF;
  821. /* Figure out which image we want to use. */
  822. if ($sort != $Up && $sort != $Down) {
  823. $img = 'sort_none.png';
  824. $which = $Up;
  825. } elseif ($sort == $Up) {
  826. $img = 'up_pointer.png';
  827. $which = $Down;
  828. } else {
  829. $img = 'down_pointer.png';
  830. $which = 6;
  831. }
  832. if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
  833. $source_url = $regs[1];
  834. } else {
  835. $source_url = $PHP_SELF;
  836. }
  837. /* Now that we have everything figured out, show the actual button. */
  838. echo ' <a href="' . $source_url .'?newsort=' . $which
  839. . '&amp;startMessage=1&amp;mailbox=' . urlencode($mailbox)
  840. . '"><img src="../images/' . $img
  841. . '" border="0" width="12" height="10" alt="sort" title="'
  842. . _("Click here to change the sorting of the message list") .'"></a>';
  843. }
  844. function get_selectall_link($start_msg, $sort) {
  845. global $checkall, $what, $where, $mailbox, $javascript_on;
  846. global $PHP_SELF, $PG_SHOWNUM;
  847. $result = '';
  848. if ($javascript_on) {
  849. $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
  850. $func_name = "CheckAll" . $safe_name;
  851. $form_name = "FormMsgs" . $safe_name;
  852. $result = '<script language="JavaScript" type="text/javascript">'
  853. . "\n<!-- \n"
  854. . "function " . $func_name . "() {\n"
  855. . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n"
  856. . " if(document." . $form_name . ".elements[i].type == 'checkbox' && "
  857. . "document." . $form_name . ".elements[i].name != 'bypass_trash'){\n"
  858. . " document." . $form_name . ".elements[i].checked = "
  859. . " !(document." . $form_name . ".elements[i].checked);\n"
  860. . " }\n"
  861. . " }\n"
  862. . "}\n"
  863. . "//-->\n"
  864. . '</script><a href="javascript:void(0)" onClick="' . $func_name . '();">' . _("Toggle All")
  865. /* . '</script><a href="javascript:' . $func_name . '()">' . _("Toggle All")*/
  866. . "</a>\n";
  867. } else {
  868. if (strpos($PHP_SELF, "?")) {
  869. $result .= "<a href=\"$PHP_SELF&amp;mailbox=" . urlencode($mailbox)
  870. . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
  871. } else {
  872. $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
  873. . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
  874. }
  875. if (isset($checkall) && $checkall == '1') {
  876. $result .= '0';
  877. } else {
  878. $result .= '1';
  879. }
  880. if (isset($where) && isset($what)) {
  881. $result .= '&amp;where=' . urlencode($where)
  882. . '&amp;what=' . urlencode($what);
  883. }
  884. $result .= "\">";
  885. if (isset($checkall) && ($checkall == '1')) {
  886. $result .= _("Unselect All");
  887. } else {
  888. $result .= _("Select All");
  889. }
  890. $result .= "</A>\n";
  891. }
  892. /* Return our final result. */
  893. return ($result);
  894. }
  895. /*
  896. * This function computes the "Viewing Messages..." string.
  897. */
  898. function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
  899. /* Compute the $msg_cnt_str. */
  900. $result = '';
  901. if ($start_msg < $end_msg) {
  902. $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
  903. $start_msg, $end_msg, $num_msgs);
  904. } else if ($start_msg == $end_msg) {
  905. $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
  906. } else {
  907. $result = '<br>';
  908. }
  909. /* Return our result string. */
  910. return ($result);
  911. }
  912. /*
  913. * Generate a paginator link.
  914. */
  915. function get_paginator_link($box, $start_msg, $use, $text) {
  916. global $PHP_SELF, $use_frames;
  917. if ($use_frames)
  918. $target = 'right';
  919. else
  920. $target = '';
  921. $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
  922. . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
  923. . "TARGET=\"$target\">$text</A>";
  924. return ($result);
  925. /*
  926. if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
  927. $source_url = $regs[1];
  928. } else {
  929. $source_url = $PHP_SELF;
  930. }
  931. $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
  932. . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
  933. . "TARGET=\"$target\">$text</A>";
  934. return ($result);
  935. */
  936. }
  937. /*
  938. * This function computes the paginator string.
  939. */
  940. function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
  941. $show_num, $sort) {
  942. global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM, $use_frames;
  943. /* Initialize paginator string chunks. */
  944. $prv_str = '';
  945. $nxt_str = '';
  946. $pg_str = '';
  947. $all_str = '';
  948. $tgl_str = '';
  949. if ($use_frames)
  950. $target = 'right';
  951. else
  952. $target = '';
  953. $box = urlencode($box);
  954. /* Create simple strings that will be creating the paginator. */
  955. $spc = '&nbsp;'; /* This will be used as a space. */
  956. $sep = '|'; /* This will be used as a seperator. */
  957. /* Get some paginator preference values. */
  958. $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON);
  959. $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX);
  960. /* Make sure that our start message number is not too big. */
  961. $start_msg = min($start_msg, $num_msgs);
  962. /* Decide whether or not we will use the mailbox cache. */
  963. /* Not sure why $use_mailbox_cache is even passed in. */
  964. if ($sort == 6) {
  965. $use = 0;
  966. } else {
  967. $use = 1;
  968. }
  969. /* Compute the starting message of the previous and next page group. */
  970. $next_grp = $start_msg + $show_num;
  971. $prev_grp = $start_msg - $show_num;
  972. /* Compute the basic previous and next strings. */
  973. if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
  974. $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
  975. $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
  976. } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
  977. $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
  978. $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
  979. } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
  980. $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
  981. $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
  982. }
  983. /* Page selector block. Following code computes page links. */
  984. if ($pg_sel && ($num_msgs > $show_num)) {
  985. /* Most importantly, what is the current page!!! */
  986. $cur_pg = intval($start_msg / $show_num) + 1;
  987. /* Compute total # of pages and # of paginator page links. */
  988. $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
  989. $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
  990. /* Compute the size of the four quarters of the page links. */
  991. /* If we can, just show all the pages. */
  992. if (($tot_pgs - 1) <= $pg_max) {
  993. $q1_pgs = $cur_pg - 1;
  994. $q2_pgs = $q3_pgs = 0;
  995. $q4_pgs = $tot_pgs - $cur_pg;
  996. /* Otherwise, compute some magic to choose the four quarters. */
  997. } else {
  998. /*
  999. * Compute the magic base values. Added together,
  1000. * these values will always equal to the $pag_pgs.
  1001. * NOTE: These are DEFAULT values and do not take
  1002. * the current page into account. That is below.
  1003. */
  1004. $q1_pgs = floor($vis_pgs/4);
  1005. $q2_pgs = round($vis_pgs/4, 0);
  1006. $q3_pgs = ceil($vis_pgs/4);
  1007. $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
  1008. /* Adjust if the first quarter contains the current page. */
  1009. if (($cur_pg - $q1_pgs) < 1) {
  1010. $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
  1011. $q1_pgs = $cur_pg - 1;
  1012. $q2_pgs = 0;
  1013. $q3_pgs += ceil($extra_pgs / 2);
  1014. $q4_pgs += floor($extra_pgs / 2);
  1015. /* Adjust if the first and second quarters intersect. */
  1016. } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
  1017. $extra_pgs = $q2_pgs;
  1018. $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 3/4);
  1019. $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 3/4);
  1020. $q3_pgs += ceil($extra_pgs / 2);
  1021. $q4_pgs += floor($extra_pgs / 2);
  1022. /* Adjust if the fourth quarter contains the current page. */
  1023. } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
  1024. $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
  1025. $q3_pgs = 0;
  1026. $q4_pgs = $tot_pgs - $cur_pg;
  1027. $q1_pgs += floor($extra_pgs / 2);
  1028. $q2_pgs += ceil($extra_pgs / 2);
  1029. /* Adjust if the third and fourth quarter intersect. */
  1030. } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) {
  1031. $extra_pgs = $q3_pgs;
  1032. $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
  1033. $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
  1034. $q1_pgs += floor($extra_pgs / 2);
  1035. $q2_pgs += ceil($extra_pgs / 2);
  1036. }
  1037. }
  1038. /*
  1039. * I am leaving this debug code here, commented out, because
  1040. * it is a really nice way to see what the above code is doing.
  1041. * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
  1042. * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
  1043. */
  1044. /* Print out the page links from the compute page quarters. */
  1045. /* Start with the first quarter. */
  1046. if (($q1_pgs == 0) && ($cur_pg > 1)) {
  1047. $pg_str .= "...$spc";
  1048. } else {
  1049. for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
  1050. $start = (($pg-1) * $show_num) + 1;
  1051. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  1052. }
  1053. if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
  1054. $pg_str .= "...$spc";
  1055. }
  1056. }
  1057. /* Continue with the second quarter. */
  1058. for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
  1059. $start = (($pg-1) * $show_num) + 1;
  1060. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  1061. }
  1062. /* Now print the current page. */
  1063. $pg_str .= $cur_pg . $spc;
  1064. /* Next comes the third quarter. */
  1065. for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
  1066. $start = (($pg-1) * $show_num) + 1;
  1067. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  1068. }
  1069. /* And last, print the forth quarter page links. */
  1070. if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
  1071. $pg_str .= "...$spc";
  1072. } else {
  1073. if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
  1074. $pg_str .= "...$spc";
  1075. }
  1076. for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
  1077. $start = (($pg-1) * $show_num) + 1;
  1078. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  1079. }
  1080. }
  1081. } else if ($PG_SHOWNUM == 999999) {
  1082. $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
  1083. . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
  1084. . "TARGET=\"$target\">" ._("Paginate") . '</A>' . $spc;
  1085. }
  1086. /* If necessary, compute the 'show all' string. */
  1087. if (($prv_str != '') || ($nxt_str != '')) {
  1088. $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
  1089. . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
  1090. . "TARGET=\"$target\">" . _("Show All") . '</A>';
  1091. }
  1092. /* Last but not least, get the value for the toggle all link. */
  1093. $tgl_str = get_selectall_link($start_msg, $sort);
  1094. /* Put all the pieces of the paginator string together. */
  1095. /**
  1096. * Hairy code... But let's leave it like it is since I am not certain
  1097. * a different approach would be any easier to read. ;)
  1098. */
  1099. $result = '';
  1100. $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
  1101. $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : '');
  1102. $result .= ($pg_str != '' ? $pg_str : '');
  1103. $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : '');
  1104. $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str);
  1105. /* If the resulting string is blank, return a non-breaking space. */
  1106. if ($result == '') {
  1107. $result = '&nbsp;';
  1108. }
  1109. /* Return our final magical paginator string. */
  1110. return ($result);
  1111. }
  1112. function truncateWithEntities($subject, $trim_at)
  1113. {
  1114. $ent_strlen = strlen($subject);
  1115. if (($trim_at <= 0) || ($ent_strlen <= $trim_at))
  1116. return $subject;
  1117. global $languages, $squirrelmail_language;
  1118. /*
  1119. * see if this is entities-encoded string
  1120. * If so, Iterate through the whole string, find out
  1121. * the real number of characters, and if more
  1122. * than $trim_at, substr with an updated trim value.
  1123. */
  1124. $trim_val = $trim_at;
  1125. $ent_offset = 0;
  1126. $ent_loc = 0;
  1127. while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
  1128. (($ent_loc_end = strpos($subject, ';', $ent_loc+3)) !== false) ) {
  1129. $trim_val += ($ent_loc_end-$ent_loc);
  1130. $ent_offset = $ent_loc_end+1;
  1131. }
  1132. if (($trim_val > $trim_at) && ($ent_strlen > $trim_val) && (strpos($subject,';',$trim_val) < ($trim_val + 6))) {
  1133. $i = strpos($subject,';',$trim_val);
  1134. if ($i) {
  1135. $trim_val = strpos($subject,';',$trim_val);
  1136. }
  1137. }
  1138. // only print '...' when we're actually dropping part of the subject
  1139. if ($ent_strlen <= $trim_val)
  1140. return $subject;
  1141. if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
  1142. function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
  1143. return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
  1144. }
  1145. return substr_replace($subject, '...', $trim_val);
  1146. }
  1147. function processSubject($subject, $threadlevel = 0) {
  1148. /* Shouldn't ever happen -- caught too many times in the IMAP functions */
  1149. if ($subject == '') {
  1150. return _("(no subject)");
  1151. }
  1152. global $truncate_subject; /* number of characters for Subject field (<= 0 for unchanged) */
  1153. $trim_at = $truncate_subject;
  1154. /* if this is threaded, subtract two chars per indentlevel */
  1155. if (($threadlevel > 0) && ($threadlevel <= 10))
  1156. $trim_at -= (2*$threadlevel);
  1157. return truncateWithEntities($subject, $trim_at);
  1158. }
  1159. function getMbxList($imapConnection, $boxes = 0) {
  1160. global $lastTargetMailbox;
  1161. echo ' <small>&nbsp;<tt><select name="targetMailbox">';
  1162. echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes);
  1163. echo ' </SELECT></TT>&nbsp;';
  1164. }
  1165. function getButton($type, $name, $value) {
  1166. return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
  1167. }
  1168. function getSmallStringCell($string, $align) {
  1169. return html_tag('td',
  1170. '<small>' . $string . ':&nbsp; </small>',
  1171. $align,
  1172. '',
  1173. 'nowrap' );
  1174. }
  1175. function getEndMessage($start_msg, $show_num, $num_msgs) {
  1176. if ($start_msg + ($show_num - 1) < $num_msgs){
  1177. $end_msg = $start_msg + ($show_num - 1);
  1178. } else {
  1179. $end_msg = $num_msgs;
  1180. }
  1181. if ($end_msg < $start_msg) {
  1182. $start_msg = $start_msg - $show_num;
  1183. if ($start_msg < 1) {
  1184. $start_msg = 1;
  1185. }
  1186. }
  1187. return (array($start_msg,$end_msg));
  1188. }
  1189. // This should go in imap_mailbox.php
  1190. function handleAsSent($mailbox) {
  1191. global $handleAsSent_result;
  1192. /* First check if this is the sent or draft folder. */
  1193. $handleAsSent_result = isSentMailbox($mailbox) || isDraftMailbox($mailbox);
  1194. /* Then check the result of the handleAsSent hook. */
  1195. do_hook('check_handleAsSent_result', $mailbox);
  1196. /* And return the result. */
  1197. return $handleAsSent_result;
  1198. }
  1199. ?>