mailbox_display.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266
  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('../functions/strings.php');
  14. require_once('../functions/html.php');
  15. require_once('../class/html.class.php');
  16. require_once('../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. }
  327. if ($mbxresponse['EXISTS']>0) {
  328. /* if $start_msg is lower than $num_msgs, we probably deleted all messages
  329. * in the last page. We need to re-adjust the start_msg
  330. */
  331. if($start_msg > $num_msgs) {
  332. $start_msg -= $show_num;
  333. if($start_msg < 1) {
  334. $start_msg = 1;
  335. }
  336. }
  337. /* This code and the next if() block check for
  338. * server-side sorting methods. The $id array is
  339. * formatted and $sort is set to 6 to disable
  340. * SM internal sorting
  341. */
  342. if ($thread_sort_messages == 1) {
  343. $mode = 'thread';
  344. } elseif ($allow_server_sort == 1) {
  345. $mode = 'serversort';
  346. } else {
  347. $mode = '';
  348. }
  349. switch ($mode) {
  350. case 'thread':
  351. session_unregister('msort');
  352. session_unregister('msgs');
  353. $msgs = getThreadMessages($imapConnection, $start_msg, $show_num,
  354. $num_msgs);
  355. if ($msgs === false) {
  356. echo '<b><small><center><font color=red>' .
  357. _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
  358. '</center></small></b>';
  359. $thread_sort_messages = 0;
  360. $msort = $msgs = array();
  361. session_register('msort');
  362. session_register('msgs');
  363. } else {
  364. $msort= $msgs;
  365. $sort = 6;
  366. session_register('msort');
  367. session_register('msgs');
  368. }
  369. break;
  370. case 'serversort':
  371. $msgs = getServerSortMessages($imapConnection, $start_msg, $show_num,
  372. $num_msgs, $sort, $mbxresponse);
  373. if ($msgs === false) {
  374. echo '<b><small><center><font color=red>' .
  375. _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
  376. '</center></small></b>';
  377. $sort = $server_sort_order;
  378. $allow_server_sort = FALSE;
  379. $msort = $msgs = array();
  380. session_register('msort');
  381. session_register('msgs');
  382. $id = array();
  383. } else {
  384. $sort = 6;
  385. $msort = $msgs;
  386. session_register('msort');
  387. session_register('msgs');
  388. }
  389. break;
  390. default:
  391. if (!$use_cache) {
  392. session_unregister('msgs');
  393. session_unregister('msort');
  394. $msgs= getSelfSortMessages($imapConnection, $start_msg, $show_num,
  395. $num_msgs, $sort, $mbxresponse);
  396. $msort = calc_msort($msgs, $sort);
  397. session_register('msort');
  398. session_register('msgs');
  399. } /* !use cache */
  400. break;
  401. } // switch
  402. } /* if exists > 0 */
  403. $res = getEndMessage($start_msg, $show_num, $num_msgs);
  404. $start_msg = $res[0];
  405. $end_msg = $res[1];
  406. $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
  407. $num_msgs, $show_num, $sort);
  408. $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
  409. do_hook('mailbox_index_before');
  410. mail_message_listing_beginning($imapConnection, $mailbox, $sort,
  411. $msg_cnt_str, $paginator_str, $start_msg);
  412. printHeader($mailbox, $srt, $color, !$thread_sort_messages);
  413. displayMessageArray($imapConnection, $num_msgs, $start_msg,
  414. $msort, $mailbox, $sort, $color, $show_num,0,0);
  415. mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
  416. /**
  417. * TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series.
  418. */
  419. }
  420. function calc_msort($msgs, $sort) {
  421. /*
  422. * 0 = Date (up)
  423. * 1 = Date (dn)
  424. * 2 = Name (up)
  425. * 3 = Name (dn)
  426. * 4 = Subject (up)
  427. * 5 = Subject (dn)
  428. */
  429. if (($sort == 0) || ($sort == 1)) {
  430. $msort = array_cleave ($msgs, 'TIME_STAMP');
  431. } elseif (($sort == 2) || ($sort == 3)) {
  432. $msort = array_cleave ($msgs, 'FROM-SORT');
  433. } elseif (($sort == 4) || ($sort == 5)) {
  434. $msort = array_cleave ($msgs, 'SUBJECT-SORT');
  435. } else {
  436. $msort = $msgs;
  437. }
  438. if ($sort < 6) {
  439. if ($sort % 2) {
  440. asort($msort);
  441. } else {
  442. arsort($msort);
  443. }
  444. }
  445. return $msort;
  446. }
  447. function fillMessageArray($imapConnection,$id,$count) {
  448. $msgs_list = sqimap_get_small_header_list($imapConnection, $id);
  449. $messages = array();
  450. if (sizeof($msgs_list)){
  451. foreach ($msgs_list as $hdr) {
  452. $unique_id[] = $hdr->uid;
  453. $from[] = $hdr->from;
  454. $date[] = $hdr->date;
  455. $subject[] = $hdr->subject;
  456. $to[] = $hdr->to;
  457. $priority[] = $hdr->priority;
  458. $cc[] = $hdr->cc;
  459. $size[] = $hdr->size;
  460. $type[] = $hdr->type0;
  461. $flag_deleted[] = $hdr->flag_deleted;
  462. $flag_answered[] = $hdr->flag_answered;
  463. $flag_seen[] = $hdr->flag_seen;
  464. $flag_flagged[] = $hdr->flag_flagged;
  465. }
  466. }
  467. $j = 0;
  468. while ($j < $count) {
  469. if (isset($date[$j])) {
  470. $date[$j] = str_replace(' ', ' ', $date[$j]);
  471. $tmpdate = explode(' ', trim($date[$j]));
  472. } else {
  473. $tmpdate = $date = array('', '', '', '', '', '');
  474. }
  475. $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
  476. $messages[$j]['DATE_STRING'] =
  477. getDateString($messages[$j]['TIME_STAMP']);
  478. $messages[$j]['ID'] = $unique_id[$j];
  479. $messages[$j]['FROM'] = decodeHeader($from[$j]);
  480. $messages[$j]['FROM-SORT'] =
  481. strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
  482. $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
  483. $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
  484. $messages[$j]['TO'] = decodeHeader($to[$j]);
  485. $messages[$j]['PRIORITY'] = $priority[$j];
  486. $messages[$j]['CC'] = $cc[$j];
  487. $messages[$j]['SIZE'] = $size[$j];
  488. $messages[$j]['TYPE0'] = $type[$j];
  489. $messages[$j]['FLAG_DELETED'] = $flag_deleted[$j];
  490. $messages[$j]['FLAG_ANSWERED'] = $flag_answered[$j];
  491. $messages[$j]['FLAG_SEEN'] = $flag_seen[$j];
  492. $messages[$j]['FLAG_FLAGGED'] = $flag_flagged[$j];
  493. /*
  494. * fix SUBJECT-SORT to remove Re:
  495. * vedr|sv (Danish)
  496. * re|aw (English)
  497. *
  498. * TODO: i18n should be incorporated here. E.g. we catch the ones
  499. * we know about, but also define in i18n what the localized
  500. * "Re: " is for this or that locale.
  501. */
  502. if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
  503. $messages[$j]['SUBJECT-SORT'], $matches)){
  504. $messages[$j]['SUBJECT-SORT'] = $matches[2];
  505. }
  506. $j++;
  507. }
  508. return $messages;
  509. }
  510. /* Generic function to convert the msgs array into an HTML table. */
  511. function displayMessageArray($imapConnection, $num_msgs, $start_msg,
  512. $msort, $mailbox, $sort, $color,
  513. $show_num, $where=0, $what=0) {
  514. global $imapServerAddress, $use_mailbox_cache,
  515. $index_order, $checkall,
  516. $indent_array, $thread_sort_messages, $allow_server_sort,
  517. $server_sort_order, $PHP_SELF;
  518. $res = getEndMessage($start_msg, $show_num, $num_msgs);
  519. $start_msg = $res[0];
  520. $end_msg = $res[1];
  521. $urlMailbox = urlencode($mailbox);
  522. /* get indent level for subject display */
  523. if ($thread_sort_messages == 1 ) {
  524. $indent_array = get_parent_level($imapConnection);
  525. }
  526. $real_startMessage = $start_msg;
  527. if ($sort == 6) {
  528. if ($end_msg - $start_msg < $show_num - 1) {
  529. $end_msg = $end_msg - $start_msg + 1;
  530. $start_msg = 1;
  531. } else if ($start_msg > $show_num) {
  532. $end_msg = $show_num;
  533. $start_msg = 1;
  534. }
  535. }
  536. $endVar = $end_msg + 1;
  537. /*
  538. * Loop through and display the info for each message.
  539. * ($t is used for the checkbox number)
  540. */
  541. $t = 0;
  542. /* messages display */
  543. if ($num_msgs == 0) {
  544. /* if there's no messages in this folder */
  545. echo html_tag( 'tr',
  546. html_tag( 'td',
  547. "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR>&nbsp;",
  548. 'center',
  549. $color[4],
  550. 'COLSPAN="' . count($index_order) . '"'
  551. )
  552. );
  553. } elseif ($start_msg == $end_msg) {
  554. /* if there's only one message in the box, handle it differently. */
  555. if ($sort != 6){
  556. $i = $start_msg;
  557. } else {
  558. $i = 1;
  559. }
  560. reset($msort);
  561. $k = 0;
  562. do {
  563. $key = key($msort);
  564. next($msort);
  565. $k++;
  566. } while (isset ($key) && ($k < $i));
  567. printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
  568. $real_startMessage, $where, $what);
  569. } else {
  570. $i = $start_msg;
  571. reset($msort);
  572. $k = 0;
  573. do {
  574. $key = key($msort);
  575. next($msort);
  576. $k++;
  577. } while (isset ($key) && ($k < $i));
  578. do {
  579. printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
  580. $real_startMessage, $where, $what);
  581. $key = key($msort);
  582. $t++;
  583. $i++;
  584. next($msort);
  585. } while ($i && $i < $endVar);
  586. }
  587. echo '</table>';
  588. }
  589. /*
  590. * Displays the standard message list header. To finish the table,
  591. * you need to do a "</table></table>";
  592. *
  593. * $moveURL is the URL to submit the delete/move form to
  594. * $mailbox is the current mailbox
  595. * $sort is the current sorting method (-1 for no sorting available [searches])
  596. * $Message is a message that is centered on top of the list
  597. * $More is a second line that is left aligned
  598. */
  599. function mail_message_listing_beginning ($imapConnection,
  600. $mailbox = '', $sort = -1,
  601. $msg_cnt_str = '',
  602. $paginator = '&nbsp;',
  603. $start_msg = 1) {
  604. global $color, $auto_expunge, $base_uri, $thread_sort_messages,
  605. $allow_thread_sort, $allow_server_sort, $server_sort_order,
  606. $PHP_SELF;
  607. $urlMailbox = urlencode($mailbox);
  608. if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
  609. $source_url = $regs[1];
  610. } else {
  611. $source_url = $PHP_SELF;
  612. }
  613. if (!isset($msg)) {
  614. $msg = '';
  615. }
  616. $moveURL = "move_messages.php?msg=$msg&amp;mailbox=$urlMailbox"
  617. . "&amp;startMessage=$start_msg";
  618. /*
  619. * This is the beginning of the message list table.
  620. * It wraps around all messages
  621. */
  622. echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n"
  623. . html_tag( 'table' ,'' , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' ) .
  624. html_tag( 'tr',
  625. html_tag( 'td' ,
  626. html_tag( 'table' ,
  627. html_tag( 'tr',
  628. html_tag( 'td', $paginator, 'left' ) .
  629. html_tag( 'td', $msg_cnt_str, 'right' )
  630. )
  631. , '', $color[4], 'border="0" width="100%" cellpadding="2" cellspacing="0"' )
  632. , 'left', '', '' )
  633. , '', $color[0] )
  634. . html_tag( 'tr' ) . "\n"
  635. . html_tag( 'td' ,'' , 'left', $color[0], '' )
  636. . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="0" cellspacing="0"' )
  637. . html_tag( 'tr',
  638. getSmallStringCell(_("Move Selected To"), 'left') .
  639. getSmallStringCell(_("Transform Selected Messages"), 'right')
  640. )
  641. . html_tag( 'tr' ) ."\n"
  642. . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
  643. getMbxList($imapConnection);
  644. echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
  645. echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
  646. echo " </TD>\n"
  647. . html_tag( 'td', '', 'right', '', 'nowrap' );
  648. if (!$auto_expunge) {
  649. echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
  650. .'&nbsp;' . _("mailbox") . "\n";
  651. }
  652. echo getButton('SUBMIT', 'markRead',_("Read"));
  653. echo getButton('SUBMIT', 'markUnread',_("Unread"));
  654. echo getButton('SUBMIT', 'delete',_("Delete")) ."&nbsp\n";
  655. if (!strpos($PHP_SELF,'mailbox')) {
  656. $location = $PHP_SELF.'?mailbox=INBOX&amp;startMessage=1';
  657. } else {
  658. $location = $PHP_SELF;
  659. }
  660. echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">';
  661. echo "</TD>\n"
  662. . " </TR>\n";
  663. /* draws thread sorting links */
  664. if ($allow_thread_sort == TRUE) {
  665. if ($thread_sort_messages == 1 ) {
  666. $set_thread = 2;
  667. $thread_name = _("Unthread View");
  668. }
  669. elseif ($thread_sort_messages == 0) {
  670. $set_thread = 1;
  671. $thread_name = _("Thread View");
  672. }
  673. echo html_tag( 'tr' ,
  674. html_tag( 'td' ,
  675. '&nbsp;<a href=' . $source_url . '?sort='
  676. . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
  677. . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
  678. . '</a></small>&nbsp;'
  679. , '', '', '' )
  680. , '', '', '' );
  681. }
  682. echo "</TABLE>\n";
  683. echo "</table>\n";
  684. do_hook('mailbox_form_before');
  685. echo '</td></tr>'
  686. . html_tag( 'tr' )
  687. . html_tag( 'td' ,'' , '', $color[0], '' );
  688. if ($GLOBALS['alt_index_colors']){
  689. $cellspacing = '0';
  690. } else {
  691. $cellspacing = '1';
  692. }
  693. echo html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="2" cellspacing="'. $cellspacing .'"' );
  694. /* if using server sort we highjack the
  695. * the $sort var and use $server_sort_order
  696. * instead. but here we reset sort for a bit
  697. * since its easy
  698. */
  699. if ($allow_server_sort == TRUE) {
  700. $sort = $server_sort_order;
  701. }
  702. }
  703. function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
  704. if ($num_msgs) {
  705. echo html_tag( 'table',
  706. html_tag( 'tr',
  707. html_tag( 'td',
  708. html_tag( 'table',
  709. html_tag( 'tr',
  710. html_tag( 'td', $paginator_str ) .
  711. html_tag( 'td', $msg_cnt_str, 'right' )
  712. )
  713. , '', $color[4], 'width="100%" cellpadding="1" cellspacing="1"' )
  714. )
  715. , '', $color[4] )
  716. , '', $color[9], 'width="100%" cellpadding="1" cellspacing="1"' );
  717. }
  718. /* End of message-list table */
  719. do_hook('mailbox_index_after');
  720. echo "</FORM>\n";
  721. }
  722. function printHeader($mailbox, $sort, $color, $showsort=true) {
  723. global $index_order;
  724. echo html_tag( 'table' ,'' , '', $color[9], 'border="0" width="100%" cellpadding="1" cellspacing="1"' );
  725. echo html_tag( 'tr' ,'' , 'center', $color[5] );
  726. for ($i=1; $i <= count($index_order); $i++) {
  727. switch ($index_order[$i]) {
  728. case 1: /* checkbox */
  729. case 5: /* flags */
  730. echo html_tag( 'td' ,'&nbsp;' , '', '', 'width="1%"' );
  731. break;
  732. case 2: /* from */
  733. if (handleAsSent($mailbox)) {
  734. echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
  735. . '<b>' . _("To") . '</b>';
  736. } else {
  737. echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
  738. . '<b>' . _("From") . '</b>';
  739. }
  740. if ($showsort) {
  741. ShowSortButton($sort, $mailbox, 2, 3);
  742. }
  743. echo "</td>\n";
  744. break;
  745. case 3: /* date */
  746. echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
  747. . '<b>' . _("Date") . '</b>';
  748. if ($showsort) {
  749. ShowSortButton($sort, $mailbox, 0, 1);
  750. }
  751. echo "</td>\n";
  752. break;
  753. case 4: /* subject */
  754. echo html_tag( 'td' ,'' , 'left', '', '' )
  755. . '<b>' . _("Subject") . '</b>';
  756. if ($showsort) {
  757. ShowSortButton($sort, $mailbox, 4, 5);
  758. }
  759. echo "</td>\n";
  760. break;
  761. case 6: /* size */
  762. echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%"' );
  763. break;
  764. }
  765. }
  766. echo "</tr>\n";
  767. }
  768. /*
  769. * This function shows the sort button. Isn't this a good comment?
  770. */
  771. function ShowSortButton($sort, $mailbox, $Up, $Down ) {
  772. global $PHP_SELF;
  773. /* Figure out which image we want to use. */
  774. if ($sort != $Up && $sort != $Down) {
  775. $img = 'sort_none.png';
  776. $which = $Up;
  777. } elseif ($sort == $Up) {
  778. $img = 'up_pointer.png';
  779. $which = $Down;
  780. } else {
  781. $img = 'down_pointer.png';
  782. $which = 6;
  783. }
  784. if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
  785. $source_url = $regs[1];
  786. } else {
  787. $source_url = $PHP_SELF;
  788. }
  789. /* Now that we have everything figured out, show the actual button. */
  790. echo ' <a href="' . $source_url .'?newsort=' . $which
  791. . '&amp;startMessage=1&amp;mailbox=' . urlencode($mailbox)
  792. . '"><IMG SRC="../images/' . $img
  793. . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
  794. }
  795. function get_selectall_link($start_msg, $sort) {
  796. global $checkall, $what, $where, $mailbox, $javascript_on;
  797. global $PHP_SELF, $PG_SHOWNUM;
  798. $result = '';
  799. if ($javascript_on) {
  800. $result =
  801. '<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. if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
  865. $source_url = $regs[1];
  866. } else {
  867. $source_url = $PHP_SELF;
  868. }
  869. $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
  870. . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
  871. . "TARGET=\"right\">$text</A>";
  872. return ($result);
  873. }
  874. /*
  875. * This function computes the paginator string.
  876. */
  877. function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
  878. $show_num, $sort) {
  879. global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
  880. /* Initialize paginator string chunks. */
  881. $prv_str = '';
  882. $nxt_str = '';
  883. $pg_str = '';
  884. $all_str = '';
  885. $tgl_str = '';
  886. $box = urlencode($box);
  887. /* Create simple strings that will be creating the paginator. */
  888. $spc = '&nbsp;'; /* This will be used as a space. */
  889. $sep = '|'; /* This will be used as a seperator. */
  890. /* Get some paginator preference values. */
  891. $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON);
  892. $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX);
  893. /* Make sure that our start message number is not too big. */
  894. $start_msg = min($start_msg, $num_msgs);
  895. /* Decide whether or not we will use the mailbox cache. */
  896. /* Not sure why $use_mailbox_cache is even passed in. */
  897. if ($sort == 6) {
  898. $use = 0;
  899. } else {
  900. $use = 1;
  901. }
  902. /* Compute the starting message of the previous and next page group. */
  903. $next_grp = $start_msg + $show_num;
  904. $prev_grp = $start_msg - $show_num;
  905. /* Compute the basic previous and next strings. */
  906. if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
  907. $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
  908. $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
  909. } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
  910. $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
  911. $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
  912. } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
  913. $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
  914. $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
  915. }
  916. /* Page selector block. Following code computes page links. */
  917. if ($pg_sel && ($num_msgs > $show_num)) {
  918. /* Most importantly, what is the current page!!! */
  919. $cur_pg = intval($start_msg / $show_num) + 1;
  920. /* Compute total # of pages and # of paginator page links. */
  921. $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
  922. $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
  923. /* Compute the size of the four quarters of the page links. */
  924. /* If we can, just show all the pages. */
  925. if (($tot_pgs - 1) <= $pg_max) {
  926. $q1_pgs = $cur_pg - 1;
  927. $q2_pgs = $q3_pgs = 0;
  928. $q4_pgs = $tot_pgs - $cur_pg;
  929. /* Otherwise, compute some magic to choose the four quarters. */
  930. } else {
  931. /*
  932. * Compute the magic base values. Added together,
  933. * these values will always equal to the $pag_pgs.
  934. * NOTE: These are DEFAULT values and do not take
  935. * the current page into account. That is below.
  936. */
  937. $q1_pgs = floor($vis_pgs/4);
  938. $q2_pgs = round($vis_pgs/4, 0);
  939. $q3_pgs = ceil($vis_pgs/4);
  940. $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
  941. /* Adjust if the first quarter contains the current page. */
  942. if (($cur_pg - $q1_pgs) < 1) {
  943. $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
  944. $q1_pgs = $cur_pg - 1;
  945. $q2_pgs = 0;
  946. $q3_pgs += ceil($extra_pgs / 2);
  947. $q4_pgs += floor($extra_pgs / 2);
  948. /* Adjust if the first and second quarters intersect. */
  949. } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
  950. $extra_pgs = $q2_pgs;
  951. $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
  952. $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
  953. $q3_pgs += ceil($extra_pgs / 2);
  954. $q4_pgs += floor($extra_pgs / 2);
  955. /* Adjust if the fourth quarter contains the current page. */
  956. } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
  957. $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
  958. $q3_pgs = 0;
  959. $q4_pgs = $tot_pgs - $cur_pg;
  960. $q1_pgs += floor($extra_pgs / 2);
  961. $q2_pgs += ceil($extra_pgs / 2);
  962. /* Adjust if the third and fourth quarter intersect. */
  963. } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) {
  964. $extra_pgs = $q3_pgs;
  965. $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
  966. $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
  967. $q1_pgs += floor($extra_pgs / 2);
  968. $q2_pgs += ceil($extra_pgs / 2);
  969. }
  970. }
  971. /*
  972. * I am leaving this debug code here, commented out, because
  973. * it is a really nice way to see what the above code is doing.
  974. * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
  975. * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
  976. */
  977. /* Print out the page links from the compute page quarters. */
  978. /* Start with the first quarter. */
  979. if (($q1_pgs == 0) && ($cur_pg > 1)) {
  980. $pg_str .= "...$spc";
  981. } else {
  982. for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
  983. $start = (($pg-1) * $show_num) + 1;
  984. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  985. }
  986. if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
  987. $pg_str .= "...$spc";
  988. }
  989. }
  990. /* Continue with the second quarter. */
  991. for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
  992. $start = (($pg-1) * $show_num) + 1;
  993. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  994. }
  995. /* Now print the current page. */
  996. $pg_str .= $cur_pg . $spc;
  997. /* Next comes the third quarter. */
  998. for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
  999. $start = (($pg-1) * $show_num) + 1;
  1000. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  1001. }
  1002. /* And last, print the forth quarter page links. */
  1003. if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
  1004. $pg_str .= "...$spc";
  1005. } else {
  1006. if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
  1007. $pg_str .= "...$spc";
  1008. }
  1009. for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
  1010. $start = (($pg-1) * $show_num) + 1;
  1011. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  1012. }
  1013. }
  1014. } else if ($PG_SHOWNUM == 999999) {
  1015. $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
  1016. . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
  1017. . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
  1018. }
  1019. /* If necessary, compute the 'show all' string. */
  1020. if (($prv_str != '') || ($nxt_str != '')) {
  1021. $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
  1022. . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
  1023. . "TARGET=\"right\">" . _("Show All") . '</A>';
  1024. }
  1025. /* Last but not least, get the value for the toggle all link. */
  1026. $tgl_str = get_selectall_link($start_msg, $sort);
  1027. /* Put all the pieces of the paginator string together. */
  1028. /**
  1029. * Hairy code... But let's leave it like it is since I am not certain
  1030. * a different approach would be any easier to read. ;)
  1031. */
  1032. $result = '';
  1033. $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
  1034. $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : '');
  1035. $result .= ($pg_str != '' ? $pg_str : '');
  1036. $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : '');
  1037. $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str);
  1038. /* If the resulting string is blank, return a non-breaking space. */
  1039. if ($result == '') {
  1040. $result = '&nbsp;';
  1041. }
  1042. /* Return our final magical paginator string. */
  1043. return ($result);
  1044. }
  1045. function processSubject($subject) {
  1046. /* Shouldn't ever happen -- caught too many times in the IMAP functions */
  1047. if ($subject == '')
  1048. return _("(no subject)");
  1049. if (strlen($subject) <= 55)
  1050. return $subject;
  1051. $ent_strlen=strlen($subject);
  1052. $trim_val=50;
  1053. $ent_offset=0;
  1054. /*
  1055. * see if this is entities-encoded string
  1056. * If so, Iterate through the whole string, find out
  1057. * the real number of characters, and if more
  1058. * than 55, substr with an updated trim value.
  1059. */
  1060. while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
  1061. (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
  1062. $trim_val += ($ent_loc_end-$ent_loc)+1;
  1063. $ent_strlen -= $ent_loc_end-$ent_loc;
  1064. $ent_offset = $ent_loc_end+1;
  1065. }
  1066. if ($ent_strlen <= 55){
  1067. return $subject;
  1068. }
  1069. return substr($subject, 0, $trim_val) . '...';
  1070. }
  1071. function getMbxList($imapConnection) {
  1072. global $lastTargetMailbox;
  1073. echo ' <small>&nbsp;<tt><select name="targetMailbox">';
  1074. $boxes = sqimap_mailbox_list($imapConnection);
  1075. foreach ($boxes as $boxes_part) {
  1076. if (!in_array('noselect', $boxes_part['flags'])) {
  1077. $box = $boxes_part['unformatted'];
  1078. $box2 = str_replace(' ', '&nbsp;', imap_utf7_decode_local($boxes_part['unformatted-disp']));
  1079. if( $box2 == 'INBOX' ) {
  1080. $box2 = _("INBOX");
  1081. }
  1082. if ($lastTargetMailbox == $box) {
  1083. echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
  1084. }
  1085. else {
  1086. echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
  1087. }
  1088. }
  1089. }
  1090. echo ' </SELECT></TT>&nbsp;';
  1091. }
  1092. function getButton($type, $name, $value) {
  1093. return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
  1094. }
  1095. function getSmallStringCell($string, $align) {
  1096. return html_tag( 'td',
  1097. '<small>' . $string . ':&nbsp; </small>',
  1098. $align,
  1099. '',
  1100. 'nowrap' );
  1101. }
  1102. function getEndMessage($start_msg, $show_num, $num_msgs) {
  1103. if ($start_msg + ($show_num - 1) < $num_msgs){
  1104. $end_msg = $start_msg + ($show_num - 1);
  1105. } else {
  1106. $end_msg = $num_msgs;
  1107. }
  1108. if ($end_msg < $start_msg) {
  1109. $start_msg = $start_msg - $show_num;
  1110. if ($start_msg < 1) {
  1111. $start_msg = 1;
  1112. }
  1113. }
  1114. return (array($start_msg,$end_msg));
  1115. }
  1116. function handleAsSent($mailbox) {
  1117. global $sent_folder, $draft_folder, $handleAsSent_result;
  1118. /* First check if this is the sent or draft folder. */
  1119. $handleAsSent_result = (($mailbox == $sent_folder)
  1120. || ($mailbox == $draft_folder));
  1121. /* Then check the result of the handleAsSent hook. */
  1122. do_hook('check_handleAsSent_result', $mailbox);
  1123. /* And return the result. */
  1124. return ($handleAsSent_result);
  1125. }
  1126. ?>