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

/branches/tassium-auth/squirrelmail/functions/mailbox_display.php

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