您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

move_del.inc 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/steps/mail/move_del.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. | Move the submitted messages to a specific mailbox or delete them |
  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. // count messages before changing anything
  25. $threading = (bool) $RCMAIL->storage->get_threading();
  26. $trash = $RCMAIL->config->get('trash_mbox');
  27. $sources = array();
  28. if ($_POST['_from'] != 'show') {
  29. $old_count = $RCMAIL->storage->count(NULL, $threading ? 'THREADS' : 'ALL');
  30. $old_pages = ceil($old_count / $RCMAIL->storage->get_pagesize());
  31. }
  32. // move messages
  33. if ($RCMAIL->action == 'move' && !empty($_POST['_uid']) && strlen($_POST['_target_mbox'])) {
  34. $target = rcube_utils::get_input_value('_target_mbox', rcube_utils::INPUT_POST, true);
  35. $success = true;
  36. foreach (rcmail::get_uids(null, null, $multifolder, rcube_utils::INPUT_POST) as $mbox => $uids) {
  37. if ($mbox === $target) {
  38. $count += is_array($uids) ? count($uids) : 1;
  39. }
  40. else if ($RCMAIL->storage->move_message($uids, $target, $mbox)) {
  41. $count += is_array($uids) ? count($uids) : 1;
  42. $sources[] = $mbox;
  43. }
  44. else {
  45. $success = false;
  46. }
  47. }
  48. if (!$success) {
  49. // send error message
  50. if ($_POST['_from'] != 'show')
  51. $OUTPUT->command('list_mailbox');
  52. $RCMAIL->display_server_error('errormoving', null, $target == $trash ? 'delete' : '');
  53. $OUTPUT->send();
  54. }
  55. else {
  56. $OUTPUT->show_message($target == $trash ? 'messagemovedtotrash' : 'messagemoved', 'confirmation');
  57. }
  58. if (!empty($_POST['_refresh'])) {
  59. // FIXME: send updated message rows instead of reloading the entire list
  60. $OUTPUT->command('refresh_list');
  61. }
  62. else {
  63. $addrows = true;
  64. }
  65. }
  66. // delete messages
  67. else if ($RCMAIL->action == 'delete' && !empty($_POST['_uid'])) {
  68. foreach (rcmail::get_uids(null, null, $multifolder, rcube_utils::INPUT_POST) as $mbox => $uids) {
  69. $del += (int)$RCMAIL->storage->delete_message($uids, $mbox);
  70. $count += is_array($uids) ? count($uids) : 1;
  71. $sources[] = $mbox;
  72. }
  73. if (!$del) {
  74. // send error message
  75. if ($_POST['_from'] != 'show') {
  76. $OUTPUT->command('list_mailbox');
  77. }
  78. $RCMAIL->display_server_error('errordeleting');
  79. $OUTPUT->send();
  80. }
  81. else {
  82. $OUTPUT->show_message('messagedeleted', 'confirmation');
  83. }
  84. $addrows = true;
  85. }
  86. // unknown action or missing query param
  87. else {
  88. $OUTPUT->show_message('internalerror', 'error');
  89. $OUTPUT->send();
  90. }
  91. $search_request = rcube_utils::get_input_value('_search', rcube_utils::INPUT_GPC);
  92. // refresh saved search set after moving some messages
  93. if ($search_request && $RCMAIL->storage->get_search_set()) {
  94. $_SESSION['search'] = $RCMAIL->storage->refresh_search();
  95. }
  96. if ($_POST['_from'] == 'show') {
  97. if ($next = rcube_utils::get_input_value('_next_uid', rcube_utils::INPUT_GPC)) {
  98. $OUTPUT->command('show_message', $next);
  99. }
  100. else {
  101. $OUTPUT->command('command', 'list');
  102. }
  103. $OUTPUT->send();
  104. }
  105. $mbox = $RCMAIL->storage->get_folder();
  106. $msg_count = $RCMAIL->storage->count(NULL, $threading ? 'THREADS' : 'ALL');
  107. $exists = $RCMAIL->storage->count($mbox, 'EXISTS', true);
  108. $page_size = $RCMAIL->storage->get_pagesize();
  109. $page = $RCMAIL->storage->get_page();
  110. $pages = ceil($msg_count / $page_size);
  111. $nextpage_count = $old_count - $page_size * $page;
  112. $remaining = $msg_count - $page_size * ($page - 1);
  113. // jump back one page (user removed the whole last page)
  114. if ($page > 1 && $remaining == 0) {
  115. $page -= 1;
  116. $RCMAIL->storage->set_page($page);
  117. $_SESSION['page'] = $page;
  118. $jump_back = true;
  119. }
  120. // update message count display
  121. $OUTPUT->set_env('messagecount', $msg_count);
  122. $OUTPUT->set_env('current_page', $page);
  123. $OUTPUT->set_env('pagecount', $pages);
  124. $OUTPUT->set_env('exists', $exists);
  125. // update mailboxlist
  126. $unseen_count = $msg_count ? $RCMAIL->storage->count($mbox, 'UNSEEN') : 0;
  127. $old_unseen = rcmail_get_unseen_count($mbox);
  128. if ($old_unseen != $unseen_count) {
  129. $OUTPUT->command('set_unread_count', $mbox, $unseen_count, ($mbox == 'INBOX'));
  130. rcmail_set_unseen_count($mbox, $unseen_count);
  131. }
  132. if ($RCMAIL->action == 'move' && strlen($target)) {
  133. rcmail_send_unread_count($target, true);
  134. }
  135. $OUTPUT->command('set_quota', $RCMAIL->quota_content(null, $multifolder ? $sources[0] : 'INBOX'));
  136. $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count), $mbox);
  137. if ($threading) {
  138. $count = rcube_utils::get_input_value('_count', rcube_utils::INPUT_POST);
  139. }
  140. // add new rows from next page (if any)
  141. if ($addrows && $count && $uids != '*' && ($jump_back || $nextpage_count > 0)) {
  142. // #5862: Don't add more rows than it was on the next page
  143. $count = $jump_back ? null : min($nextpage_count, $count);
  144. $a_headers = $RCMAIL->storage->list_messages($mbox, NULL,
  145. rcmail_sort_column(), rcmail_sort_order(), $count);
  146. rcmail_js_message_list($a_headers, false);
  147. }
  148. // set trash folder state
  149. if ($mbox === $trash) {
  150. $OUTPUT->command('set_trash_count', $exists);
  151. }
  152. else if ($target !== null && $target === $trash) {
  153. $OUTPUT->command('set_trash_count', $RCMAIL->storage->count($trash, 'EXISTS', true));
  154. }
  155. // send response
  156. $OUTPUT->send();