mailbox_display.php 46 KB

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