PageRenderTime 52ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1_4_0-rc2/squirrelmail/functions/mailbox_display.php

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