| [4e17e6c] | 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | +-----------------------------------------------------------------------+ |
|---|
| 5 | | program/steps/mail/move_del.inc | |
|---|
| 6 | | | |
|---|
| [e019f2d] | 7 | | This file is part of the Roundcube Webmail client | |
|---|
| [f5e7b353] | 8 | | Copyright (C) 2005-2009, The Roundcube Dev Team | |
|---|
| [7fe3811] | 9 | | | |
|---|
| 10 | | Licensed under the GNU General Public License version 3 or | |
|---|
| 11 | | any later version with exceptions for skins & plugins. | |
|---|
| 12 | | See the README file for a full license statement. | |
|---|
| [4e17e6c] | 13 | | | |
|---|
| 14 | | PURPOSE: | |
|---|
| 15 | | Move the submitted messages to a specific mailbox or delete them | |
|---|
| 16 | | | |
|---|
| 17 | +-----------------------------------------------------------------------+ |
|---|
| 18 | | Author: Thomas Bruederli <roundcube@gmail.com> | |
|---|
| 19 | +-----------------------------------------------------------------------+ |
|---|
| 20 | |
|---|
| 21 | $Id$ |
|---|
| 22 | |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| [881217a] | 25 | // only process ajax requests |
|---|
| 26 | if (!$OUTPUT->ajax_call) |
|---|
| 27 | return; |
|---|
| 28 | |
|---|
| [c3ab87b6] | 29 | // count messages before changing anything |
|---|
| [c321a955] | 30 | $threading = (bool) $RCMAIL->storage->get_threading(); |
|---|
| 31 | $old_count = $RCMAIL->storage->count(NULL, $threading ? 'THREADS' : 'ALL'); |
|---|
| 32 | $old_pages = ceil($old_count / $RCMAIL->storage->get_pagesize()); |
|---|
| [51e14a1] | 33 | |
|---|
| [4e17e6c] | 34 | // move messages |
|---|
| [4484097] | 35 | if ($RCMAIL->action=='moveto' && !empty($_POST['_uid']) && strlen($_POST['_target_mbox'])) { |
|---|
| [e090a1a] | 36 | $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_POST)))); |
|---|
| [b72e2f9] | 37 | $target = get_input_value('_target_mbox', RCUBE_INPUT_POST, true); |
|---|
| 38 | $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true); |
|---|
| [2855518] | 39 | |
|---|
| [c321a955] | 40 | $moved = $RCMAIL->storage->move_message($uids, $target, $mbox); |
|---|
| [fb7ec57] | 41 | |
|---|
| [9281884] | 42 | if (!$moved) { |
|---|
| [e090a1a] | 43 | // send error message |
|---|
| [fb7ec57] | 44 | if ($_POST['_from'] != 'show') |
|---|
| 45 | $OUTPUT->command('list_mailbox'); |
|---|
| [90f81a6] | 46 | rcmail_display_server_error('errormoving'); |
|---|
| [e090a1a] | 47 | $OUTPUT->send(); |
|---|
| 48 | exit; |
|---|
| 49 | } |
|---|
| [c50d887] | 50 | else { |
|---|
| 51 | $OUTPUT->show_message('messagemoved', 'confirmation'); |
|---|
| 52 | } |
|---|
| [9281884] | 53 | |
|---|
| [0b2ce91] | 54 | $addrows = true; |
|---|
| [f115416] | 55 | } |
|---|
| [4e17e6c] | 56 | // delete messages |
|---|
| [e090a1a] | 57 | else if ($RCMAIL->action=='delete' && !empty($_POST['_uid'])) { |
|---|
| 58 | $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_POST)))); |
|---|
| [b72e2f9] | 59 | $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true); |
|---|
| [f52c936f] | 60 | |
|---|
| [c321a955] | 61 | $del = $RCMAIL->storage->delete_message($uids, $mbox); |
|---|
| [c50d887] | 62 | |
|---|
| [e090a1a] | 63 | if (!$del) { |
|---|
| 64 | // send error message |
|---|
| [fb7ec57] | 65 | if ($_POST['_from'] != 'show') |
|---|
| 66 | $OUTPUT->command('list_mailbox'); |
|---|
| [90f81a6] | 67 | rcmail_display_server_error('errordeleting'); |
|---|
| [e090a1a] | 68 | $OUTPUT->send(); |
|---|
| 69 | exit; |
|---|
| 70 | } |
|---|
| [c50d887] | 71 | else { |
|---|
| 72 | $OUTPUT->show_message('messagedeleted', 'confirmation'); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| [9281884] | 75 | $addrows = true; |
|---|
| [f115416] | 76 | } |
|---|
| [4e17e6c] | 77 | // unknown action or missing query param |
|---|
| [e090a1a] | 78 | else { |
|---|
| 79 | exit; |
|---|
| 80 | } |
|---|
| [dc2fc08] | 81 | |
|---|
| [c321a955] | 82 | $search_request = get_input_value('_search', RCUBE_INPUT_GPC); |
|---|
| 83 | |
|---|
| [1107480] | 84 | // refresh saved search set after moving some messages |
|---|
| [c321a955] | 85 | if ($search_request && $RCMAIL->storage->get_search_set()) { |
|---|
| 86 | $_SESSION['search'] = $RCMAIL->storage->refresh_search(); |
|---|
| [e090a1a] | 87 | } |
|---|
| [4e17e6c] | 88 | |
|---|
| [dc2fc08] | 89 | if ($_POST['_from'] == 'show') |
|---|
| 90 | { |
|---|
| 91 | if ($next = get_input_value('_next_uid', RCUBE_INPUT_GPC)) |
|---|
| 92 | $OUTPUT->command('show_message', $next); |
|---|
| 93 | else |
|---|
| 94 | $OUTPUT->command('command', 'list'); |
|---|
| 95 | } |
|---|
| 96 | else |
|---|
| 97 | { |
|---|
| [c321a955] | 98 | $msg_count = $RCMAIL->storage->count(NULL, $threading ? 'THREADS' : 'ALL'); |
|---|
| 99 | $page_size = $RCMAIL->storage->get_pagesize(); |
|---|
| 100 | $page = $RCMAIL->storage->get_page(); |
|---|
| 101 | $pages = ceil($msg_count / $page_size); |
|---|
| 102 | $nextpage_count = $old_count - $page_size * $page; |
|---|
| 103 | $remaining = $msg_count - $page_size * ($page - 1); |
|---|
| [dc2fc08] | 104 | |
|---|
| 105 | // jump back one page (user removed the whole last page) |
|---|
| [c321a955] | 106 | if ($page > 1 && $remaining == 0) { |
|---|
| 107 | $page -= 1; |
|---|
| 108 | $RCMAIL->storage->set_page($page); |
|---|
| 109 | $_SESSION['page'] = $page; |
|---|
| [e090a1a] | 110 | $jump_back = true; |
|---|
| [dc2fc08] | 111 | } |
|---|
| [c3ab87b6] | 112 | |
|---|
| [dc2fc08] | 113 | // update message count display |
|---|
| 114 | $OUTPUT->set_env('messagecount', $msg_count); |
|---|
| [c321a955] | 115 | $OUTPUT->set_env('current_page', $page); |
|---|
| [dc2fc08] | 116 | $OUTPUT->set_env('pagecount', $pages); |
|---|
| [4e17e6c] | 117 | |
|---|
| [dc2fc08] | 118 | // update mailboxlist |
|---|
| [c321a955] | 119 | $mbox = $RCMAIL->storage->get_folder(); |
|---|
| 120 | $unseen_count = $msg_count ? $RCMAIL->storage->count($mbox, 'UNSEEN') : 0; |
|---|
| [b46edc0f] | 121 | $old_unseen = rcmail_get_unseen_count($mbox); |
|---|
| 122 | |
|---|
| [78925f8f] | 123 | if ($old_unseen != $unseen_count) { |
|---|
| 124 | $OUTPUT->command('set_unread_count', $mbox, $unseen_count, ($mbox == 'INBOX')); |
|---|
| [b46edc0f] | 125 | rcmail_set_unseen_count($mbox, $unseen_count); |
|---|
| [78925f8f] | 126 | } |
|---|
| [7902df4] | 127 | |
|---|
| [609d392] | 128 | if ($RCMAIL->action == 'moveto' && strlen($target)) { |
|---|
| [cbeea3d] | 129 | rcmail_send_unread_count($target, true); |
|---|
| [dc2fc08] | 130 | } |
|---|
| [4e17e6c] | 131 | |
|---|
| [5b3ed54] | 132 | $OUTPUT->command('set_quota', rcmail_quota_content()); |
|---|
| [bba2529] | 133 | $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count), $mbox); |
|---|
| [4e17e6c] | 134 | |
|---|
| [c321a955] | 135 | if ($threading) { |
|---|
| [f52c936f] | 136 | $count = get_input_value('_count', RCUBE_INPUT_POST); |
|---|
| [c321a955] | 137 | } |
|---|
| [f52c936f] | 138 | |
|---|
| [dc2fc08] | 139 | // add new rows from next page (if any) |
|---|
| [fb7ec57] | 140 | if ($addrows && $count && $uids != '*' && ($jump_back || $nextpage_count > 0)) { |
|---|
| [e090a1a] | 141 | $sort_col = isset($_SESSION['sort_col']) ? $_SESSION['sort_col'] : $CONFIG['message_sort_col']; |
|---|
| 142 | $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order']; |
|---|
| [34ebe0b] | 143 | |
|---|
| [c321a955] | 144 | $a_headers = $RCMAIL->storage->list_messages($mbox, NULL, $sort_col, $sort_order, |
|---|
| [a039c62] | 145 | $jump_back ? NULL : $count); |
|---|
| [34ebe0b] | 146 | |
|---|
| [e99d21b] | 147 | rcmail_js_message_list($a_headers, false); |
|---|
| [dc2fc08] | 148 | } |
|---|
| [f115416] | 149 | } |
|---|
| [4e17e6c] | 150 | |
|---|
| 151 | // send response |
|---|
| [f115416] | 152 | $OUTPUT->send(); |
|---|
| [dc2fc08] | 153 | |
|---|
| [b25dfd0] | 154 | |
|---|