PageRenderTime 55ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/last-head-locales/squirrelmail/functions/mailbox_display.php

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