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.

mark.inc 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/steps/mail/mark.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. | Mark the submitted messages with the specified flag |
  15. | |
  16. +-----------------------------------------------------------------------+
  17. | Author: Thomas Bruederli <roundcube@gmail.com> |
  18. +-----------------------------------------------------------------------+
  19. */
  20. // only process ajax requests
  21. if (!$OUTPUT->ajax_call) {
  22. return;
  23. }
  24. $threading = (bool) $RCMAIL->storage->get_threading();
  25. $skip_deleted = (bool) $RCMAIL->config->get('skip_deleted');
  26. $read_deleted = (bool) $RCMAIL->config->get('read_when_deleted');
  27. $a_flags_map = array(
  28. 'undelete' => 'UNDELETED',
  29. 'delete' => 'DELETED',
  30. 'read' => 'SEEN',
  31. 'unread' => 'UNSEEN',
  32. 'flagged' => 'FLAGGED',
  33. 'unflagged' => 'UNFLAGGED',
  34. );
  35. if (($_uids = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST))
  36. && ($flag = rcube_utils::get_input_value('_flag', rcube_utils::INPUT_POST))
  37. ) {
  38. $flag = $a_flags_map[$flag] ?: strtoupper($flag);
  39. if ($flag == 'DELETED' && $skip_deleted && $_POST['_from'] != 'show') {
  40. // count messages before changing anything
  41. $old_count = $RCMAIL->storage->count(NULL, $threading ? 'THREADS' : 'ALL');
  42. $old_pages = ceil($old_count / $RCMAIL->storage->get_pagesize());
  43. }
  44. foreach (rcmail::get_uids() as $mbox => $uids) {
  45. $marked += (int)$RCMAIL->storage->set_flag($uids, $flag, $mbox);
  46. $count += count($uids);
  47. }
  48. if (!$marked) {
  49. // send error message
  50. if ($_POST['_from'] != 'show') {
  51. $OUTPUT->command('list_mailbox');
  52. }
  53. $RCMAIL->display_server_error('errormarking');
  54. $OUTPUT->send();
  55. exit;
  56. }
  57. else if (empty($_POST['_quiet'])) {
  58. $OUTPUT->show_message('messagemarked', 'confirmation');
  59. }
  60. if ($flag == 'DELETED' && $read_deleted && !empty($_POST['_ruid'])) {
  61. $ruids = rcube_utils::get_input_value('_ruid', rcube_utils::INPUT_POST);
  62. foreach (rcmail::get_uids($ruids) as $mbox => $uids) {
  63. $read += (int)$RCMAIL->storage->set_flag($uids, 'SEEN', $mbox);
  64. }
  65. if ($read && !$skip_deleted) {
  66. $OUTPUT->command('flag_deleted_as_read', $ruids);
  67. }
  68. }
  69. if ($flag == 'SEEN' || $flag == 'UNSEEN' || ($flag == 'DELETED' && !$skip_deleted)) {
  70. foreach (rcmail::get_uids() as $mbox => $uids) {
  71. rcmail_send_unread_count($mbox);
  72. }
  73. }
  74. else if ($flag == 'DELETED' && $skip_deleted) {
  75. if ($_POST['_from'] == 'show') {
  76. if ($next = rcube_utils::get_input_value('_next_uid', rcube_utils::INPUT_GPC))
  77. $OUTPUT->command('show_message', $next);
  78. else
  79. $OUTPUT->command('command', 'list');
  80. }
  81. else {
  82. $search_request = rcube_utils::get_input_value('_search', rcube_utils::INPUT_GPC);
  83. // refresh saved search set after moving some messages
  84. if ($search_request && $RCMAIL->storage->get_search_set()) {
  85. $_SESSION['search'] = $RCMAIL->storage->refresh_search();
  86. }
  87. $msg_count = $RCMAIL->storage->count(NULL, $threading ? 'THREADS' : 'ALL');
  88. $page_size = $RCMAIL->storage->get_pagesize();
  89. $page = $RCMAIL->storage->get_page();
  90. $pages = ceil($msg_count / $page_size);
  91. $nextpage_count = $old_count - $page_size * $page;
  92. $remaining = $msg_count - $page_size * ($page - 1);
  93. // jump back one page (user removed the whole last page)
  94. if ($page > 1 && $remaining == 0) {
  95. $page -= 1;
  96. $RCMAIL->storage->set_page($page);
  97. $_SESSION['page'] = $page;
  98. $jump_back = true;
  99. }
  100. // update message count display
  101. $OUTPUT->set_env('messagecount', $msg_count);
  102. $OUTPUT->set_env('current_page', $page);
  103. $OUTPUT->set_env('pagecount', $pages);
  104. // update mailboxlist
  105. $mbox = $RCMAIL->storage->get_folder();
  106. $unseen_count = $msg_count ? $RCMAIL->storage->count($mbox, 'UNSEEN') : 0;
  107. $old_unseen = rcmail_get_unseen_count($mbox);
  108. if ($old_unseen != $unseen_count) {
  109. $OUTPUT->command('set_unread_count', $mbox, $unseen_count, ($mbox == 'INBOX'));
  110. rcmail_set_unseen_count($mbox, $unseen_count);
  111. }
  112. $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count), $mbox);
  113. if ($threading) {
  114. $count = rcube_utils::get_input_value('_count', rcube_utils::INPUT_POST);
  115. }
  116. // add new rows from next page (if any)
  117. if ($old_count && $_uids != '*' && ($jump_back || $nextpage_count > 0)) {
  118. $a_headers = $RCMAIL->storage->list_messages($mbox, NULL,
  119. rcmail_sort_column(), rcmail_sort_order(), $jump_back ? NULL : $count);
  120. rcmail_js_message_list($a_headers, false);
  121. }
  122. }
  123. }
  124. }
  125. else {
  126. $OUTPUT->show_message('internalerror', 'error');
  127. }
  128. $OUTPUT->send();