mailbox_display.php 41 KB

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