mailbox_display.php 40 KB

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