Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/steps/mail/check_recent.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. | Check for recent messages, in all mailboxes |
  15. | |
  16. +-----------------------------------------------------------------------+
  17. | Author: Thomas Bruederli <roundcube@gmail.com> |
  18. +-----------------------------------------------------------------------+
  19. */
  20. // If there's no folder or messages list, there's nothing to update
  21. // This can happen on 'refresh' request
  22. if (empty($_POST['_folderlist']) && empty($_POST['_list'])) {
  23. return;
  24. }
  25. $trash = $RCMAIL->config->get('trash_mbox');
  26. $current = $RCMAIL->storage->get_folder();
  27. $check_all = $RCMAIL->action != 'refresh' || (bool)$RCMAIL->config->get('check_all_folders');
  28. $page = $RCMAIL->storage->get_page();
  29. $page_size = $RCMAIL->storage->get_pagesize();
  30. $search_request = rcube_utils::get_input_value('_search', rcube_utils::INPUT_GPC);
  31. if ($search_request && $_SESSION['search_request'] != $search_request) {
  32. $search_request = null;
  33. }
  34. // list of folders to check
  35. if ($check_all) {
  36. $a_mailboxes = $RCMAIL->storage->list_folders_subscribed('', '*', 'mail');
  37. }
  38. else if ($search_request && is_object($_SESSION['search'][1])) {
  39. $a_mailboxes = (array) $_SESSION['search'][1]->get_parameters('MAILBOX');
  40. }
  41. else {
  42. $a_mailboxes = (array) $current;
  43. if ($current != 'INBOX') {
  44. $a_mailboxes[] = 'INBOX';
  45. }
  46. }
  47. // Control folders list from a plugin
  48. $plugin = $RCMAIL->plugins->exec_hook('check_recent', array('folders' => $a_mailboxes, 'all' => $check_all));
  49. $a_mailboxes = $plugin['folders'];
  50. // check recent/unseen counts
  51. foreach ($a_mailboxes as $mbox_name) {
  52. $is_current = $mbox_name == $current || ($search_request && is_object($_SESSION['search'][1]) && in_array($mbox_name, (array)$_SESSION['search'][1]->get_parameters('MAILBOX')));
  53. if ($is_current) {
  54. // Synchronize mailbox cache, handle flag changes
  55. $RCMAIL->storage->folder_sync($mbox_name);
  56. }
  57. // Get mailbox status
  58. $status = $RCMAIL->storage->folder_status($mbox_name, $diff);
  59. if ($status & 1) {
  60. // trigger plugin hook
  61. $RCMAIL->plugins->exec_hook('new_messages',
  62. array('mailbox' => $mbox_name, 'is_current' => $is_current, 'diff' => $diff));
  63. }
  64. rcmail_send_unread_count($mbox_name, true, null,
  65. (!$is_current && ($status & 1)) ? 'recent' : '');
  66. if ($status && $is_current) {
  67. // refresh saved search set
  68. if ($search_request && isset($_SESSION['search'])) {
  69. unset($search_request); // only do this once
  70. $_SESSION['search'] = $RCMAIL->storage->refresh_search();
  71. if ($_SESSION['search'][1]->multi) {
  72. $mbox_name = '';
  73. }
  74. }
  75. if (!empty($_POST['_quota'])) {
  76. $OUTPUT->command('set_quota', $RCMAIL->quota_content(null, $mbox_name));
  77. }
  78. $OUTPUT->set_env('exists', $RCMAIL->storage->count($mbox_name, 'EXISTS', true));
  79. // "No-list" mode, don't get messages
  80. if (empty($_POST['_list'])) {
  81. continue;
  82. }
  83. // get overall message count; allow caching because rcube_storage::folder_status()
  84. // did a refresh but only in list mode
  85. $list_mode = $RCMAIL->storage->get_threading() ? 'THREADS' : 'ALL';
  86. $all_count = $RCMAIL->storage->count($mbox_name, $list_mode, $list_mode == 'THREADS', false);
  87. // check current page if we're not on the first page
  88. if ($all_count && $page > 1) {
  89. $remaining = $all_count - $page_size * ($page - 1);
  90. if ($remaining <= 0) {
  91. $page -= 1;
  92. $RCMAIL->storage->set_page($page);
  93. $_SESSION['page'] = $page;
  94. }
  95. }
  96. $OUTPUT->set_env('messagecount', $all_count);
  97. $OUTPUT->set_env('pagecount', ceil($all_count/$page_size));
  98. $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($all_count), $mbox_name);
  99. $OUTPUT->set_env('current_page', $all_count ? $page : 1);
  100. // remove old rows (and clear selection if new list is empty)
  101. $OUTPUT->command('message_list.clear', $all_count ? false : true);
  102. if ($all_count) {
  103. $a_headers = $RCMAIL->storage->list_messages($mbox_name, null, rcmail_sort_column(), rcmail_sort_order());
  104. // add message rows
  105. rcmail_js_message_list($a_headers, false);
  106. // remove messages that don't exists from list selection array
  107. $OUTPUT->command('update_selection');
  108. }
  109. }
  110. // handle flag updates
  111. else if ($is_current && ($uids = rcube_utils::get_input_value('_uids', rcube_utils::INPUT_GPC)) && empty($search_request)) {
  112. $data = $RCMAIL->storage->folder_data($mbox_name);
  113. if (empty($_SESSION['list_mod_seq']) || $_SESSION['list_mod_seq'] != $data['HIGHESTMODSEQ']) {
  114. $flags = $RCMAIL->storage->list_flags($mbox_name, explode(',', $uids), $_SESSION['list_mod_seq']);
  115. foreach ($flags as $idx => $row) {
  116. $flags[$idx] = array_change_key_case(array_map('intval', $row));
  117. }
  118. // remember last HIGHESTMODSEQ value (if supported)
  119. if (!empty($data['HIGHESTMODSEQ'])) {
  120. $_SESSION['list_mod_seq'] = $data['HIGHESTMODSEQ'];
  121. }
  122. $RCMAIL->output->set_env('recent_flags', $flags);
  123. }
  124. }
  125. // set trash folder state
  126. if ($mbox_name === $trash) {
  127. $OUTPUT->command('set_trash_count', $RCMAIL->storage->count($mbox_name, 'EXISTS', true));
  128. }
  129. }
  130. // trigger refresh hook
  131. $RCMAIL->plugins->exec_hook('refresh', array());
  132. $OUTPUT->send();