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

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

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