mailbox_display.php 46 KB

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