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