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.

move_del.inc 6.0KB

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