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