mailbox_display.php 45 KB

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