mailbox_display.php 33 KB

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