You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

list.inc 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/steps/mail/list.inc |
  5. | |
  6. | This file is part of the Roundcube Webmail client |
  7. | Copyright (C) 2005-2014, The Roundcube Dev Team |
  8. | |
  9. | Licensed under the GNU General Public License version 3 or |
  10. | any later version with exceptions for skins & plugins. |
  11. | See the README file for a full license statement. |
  12. | |
  13. | PURPOSE: |
  14. | Send message list to client (as remote response) |
  15. | |
  16. +-----------------------------------------------------------------------+
  17. | Author: Thomas Bruederli <roundcube@gmail.com> |
  18. +-----------------------------------------------------------------------+
  19. */
  20. if (!$OUTPUT->ajax_call) {
  21. return;
  22. }
  23. $save_arr = array();
  24. $dont_override = (array) $RCMAIL->config->get('dont_override');
  25. // is there a sort type for this request?
  26. if ($sort = rcube_utils::get_input_value('_sort', rcube_utils::INPUT_GET)) {
  27. // yes, so set the sort vars
  28. list($sort_col, $sort_order) = explode('_', $sort);
  29. // set session vars for sort (so next page and task switch know how to sort)
  30. if (!in_array('message_sort_col', $dont_override)) {
  31. $_SESSION['sort_col'] = $save_arr['message_sort_col'] = $sort_col;
  32. }
  33. if (!in_array('message_sort_order', $dont_override)) {
  34. $_SESSION['sort_order'] = $save_arr['message_sort_order'] = $sort_order;
  35. }
  36. }
  37. // register layout change
  38. if ($layout = rcube_utils::get_input_value('_layout', rcube_utils::INPUT_GET)) {
  39. $OUTPUT->set_env('layout', $layout);
  40. $save_arr['layout'] = $layout;
  41. // force header replace on layout change
  42. $cols = $_SESSION['list_attrib']['columns'];
  43. }
  44. // is there a set of columns for this request?
  45. else if ($cols = rcube_utils::get_input_value('_cols', rcube_utils::INPUT_GET)) {
  46. $_SESSION['list_attrib']['columns'] = explode(',', $cols);
  47. if (!in_array('list_cols', $dont_override)) {
  48. $save_arr['list_cols'] = explode(',', $cols);
  49. }
  50. }
  51. if (!empty($save_arr)) {
  52. $RCMAIL->user->save_prefs($save_arr);
  53. }
  54. $mbox_name = $RCMAIL->storage->get_folder();
  55. $threading = (bool) $RCMAIL->storage->get_threading();
  56. // Synchronize mailbox cache, handle flag changes
  57. $RCMAIL->storage->folder_sync($mbox_name);
  58. // fetch message headers
  59. if ($count = $RCMAIL->storage->count($mbox_name, $threading ? 'THREADS' : 'ALL', !empty($_REQUEST['_refresh']))) {
  60. $a_headers = $RCMAIL->storage->list_messages($mbox_name, NULL, rcmail_sort_column(), rcmail_sort_order());
  61. }
  62. // update search set (possible change of threading mode)
  63. if (!empty($_REQUEST['_search']) && isset($_SESSION['search'])
  64. && $_SESSION['search_request'] == $_REQUEST['_search']
  65. ) {
  66. $search_request = $_REQUEST['_search'];
  67. $_SESSION['search'] = $RCMAIL->storage->get_search_set();
  68. }
  69. // remove old search data
  70. else if (empty($_REQUEST['_search']) && isset($_SESSION['search'])) {
  71. $RCMAIL->session->remove('search');
  72. }
  73. rcmail_list_pagetitle();
  74. // update mailboxlist
  75. if (empty($search_request)) {
  76. rcmail_send_unread_count($mbox_name, !empty($_REQUEST['_refresh']), empty($a_headers) ? 0 : null);
  77. }
  78. // update message count display
  79. $pages = ceil($count/$RCMAIL->storage->get_pagesize());
  80. $page = $count ? $RCMAIL->storage->get_page() : 1;
  81. $exists = $RCMAIL->storage->count($mbox_name, 'EXISTS', true);
  82. $OUTPUT->set_env('messagecount', $count);
  83. $OUTPUT->set_env('pagecount', $pages);
  84. $OUTPUT->set_env('threading', $threading);
  85. $OUTPUT->set_env('current_page', $page);
  86. $OUTPUT->set_env('exists', $exists);
  87. $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($count), $mbox_name);
  88. // remove old message rows if commanded by the client
  89. if (!empty($_REQUEST['_clear'])) {
  90. $OUTPUT->command('clear_message_list');
  91. }
  92. // add message rows
  93. rcmail_js_message_list($a_headers, false, $cols);
  94. if (isset($a_headers) && count($a_headers)) {
  95. if ($search_request) {
  96. $OUTPUT->show_message('searchsuccessful', 'confirmation', array('nr' => $count));
  97. }
  98. // remember last HIGHESTMODSEQ value (if supported)
  99. // we need it for flag updates in check-recent
  100. $data = $RCMAIL->storage->folder_data($mbox_name);
  101. if (!empty($data['HIGHESTMODSEQ'])) {
  102. $_SESSION['list_mod_seq'] = $data['HIGHESTMODSEQ'];
  103. }
  104. }
  105. else {
  106. // handle IMAP errors (e.g. #1486905)
  107. if ($err_code = $RCMAIL->storage->get_error_code()) {
  108. $RCMAIL->display_server_error();
  109. }
  110. else if ($search_request) {
  111. $OUTPUT->show_message('searchnomatch', 'notice');
  112. }
  113. else {
  114. $OUTPUT->show_message('nomessagesfound', 'notice');
  115. }
  116. }
  117. // set trash folder state
  118. if ($mbox_name === $RCMAIL->config->get('trash_mbox')) {
  119. $OUTPUT->command('set_trash_count', $exists);
  120. }
  121. if ($page == 1) {
  122. $OUTPUT->command('set_quota', $RCMAIL->quota_content(null, $multifolder ? 'INBOX' : $mbox_name));
  123. }
  124. // send response
  125. $OUTPUT->send();