mailbox_display.php 42 KB

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