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