PageRenderTime 59ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

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

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