PageRenderTime 53ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/tags/rel-1_2_7/squirrelmail/functions/mailbox_display.php

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