mailbox_display.php 40 KB

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