mailbox_display.php 45 KB

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