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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. // is there a set of columns for this request?
  38. if ($cols = rcube_utils::get_input_value('_cols', rcube_utils::INPUT_GET)) {
  39. $_SESSION['list_attrib']['columns'] = explode(',', $cols);
  40. if (!in_array('list_cols', $dont_override)) {
  41. $save_arr['list_cols'] = explode(',', $cols);
  42. }
  43. }
  44. if (!empty($save_arr)) {
  45. $RCMAIL->user->save_prefs($save_arr);
  46. }
  47. $mbox_name = $RCMAIL->storage->get_folder();
  48. $threading = (bool) $RCMAIL->storage->get_threading();
  49. // Synchronize mailbox cache, handle flag changes
  50. $RCMAIL->storage->folder_sync($mbox_name);
  51. // fetch message headers
  52. if ($count = $RCMAIL->storage->count($mbox_name, $threading ? 'THREADS' : 'ALL', !empty($_REQUEST['_refresh']))) {
  53. $a_headers = $RCMAIL->storage->list_messages($mbox_name, NULL, rcmail_sort_column(), rcmail_sort_order());
  54. }
  55. // update search set (possible change of threading mode)
  56. if (!empty($_REQUEST['_search']) && isset($_SESSION['search'])
  57. && $_SESSION['search_request'] == $_REQUEST['_search']
  58. ) {
  59. $search_request = $_REQUEST['_search'];
  60. $_SESSION['search'] = $RCMAIL->storage->get_search_set();
  61. }
  62. // remove old search data
  63. else if (empty($_REQUEST['_search']) && isset($_SESSION['search'])) {
  64. $RCMAIL->session->remove('search');
  65. }
  66. rcmail_list_pagetitle();
  67. // update mailboxlist
  68. if (empty($search_request)) {
  69. rcmail_send_unread_count($mbox_name, !empty($_REQUEST['_refresh']), empty($a_headers) ? 0 : null);
  70. }
  71. // update message count display
  72. $pages = ceil($count/$RCMAIL->storage->get_pagesize());
  73. $page = $count ? $RCMAIL->storage->get_page() : 1;
  74. $exists = $RCMAIL->storage->count($mbox_name, 'EXISTS', true);
  75. $OUTPUT->set_env('messagecount', $count);
  76. $OUTPUT->set_env('pagecount', $pages);
  77. $OUTPUT->set_env('threading', $threading);
  78. $OUTPUT->set_env('current_page', $page);
  79. $OUTPUT->set_env('exists', $exists);
  80. $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($count), $mbox_name);
  81. // remove old message rows if commanded by the client
  82. if (!empty($_REQUEST['_clear'])) {
  83. $OUTPUT->command('clear_message_list');
  84. }
  85. // add message rows
  86. rcmail_js_message_list($a_headers, false, $cols);
  87. if (isset($a_headers) && count($a_headers)) {
  88. if ($search_request) {
  89. $OUTPUT->show_message('searchsuccessful', 'confirmation', array('nr' => $count));
  90. }
  91. // remember last HIGHESTMODSEQ value (if supported)
  92. // we need it for flag updates in check-recent
  93. $data = $RCMAIL->storage->folder_data($mbox_name);
  94. if (!empty($data['HIGHESTMODSEQ'])) {
  95. $_SESSION['list_mod_seq'] = $data['HIGHESTMODSEQ'];
  96. }
  97. }
  98. else {
  99. // handle IMAP errors (e.g. #1486905)
  100. if ($err_code = $RCMAIL->storage->get_error_code()) {
  101. $RCMAIL->display_server_error();
  102. }
  103. else if ($search_request) {
  104. $OUTPUT->show_message('searchnomatch', 'notice');
  105. }
  106. else {
  107. $OUTPUT->show_message('nomessagesfound', 'notice');
  108. }
  109. }
  110. // set trash folder state
  111. if ($mbox_name === $RCMAIL->config->get('trash_mbox')) {
  112. $OUTPUT->command('set_trash_count', $exists);
  113. }
  114. if ($page == 1) {
  115. $OUTPUT->command('set_quota', $RCMAIL->quota_content(null, $multifolder ? 'INBOX' : $mbox_name));
  116. }
  117. // send response
  118. $OUTPUT->send();