Mercurial > hg > rc2
comparison program/steps/mail/mark.inc @ 0:4681f974d28b
vanilla 1.3.3 distro, I hope
author | Charlie Root |
---|---|
date | Thu, 04 Jan 2018 15:52:31 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4681f974d28b |
---|---|
1 <?php | |
2 | |
3 /** | |
4 +-----------------------------------------------------------------------+ | |
5 | program/steps/mail/mark.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 | Mark the submitted messages with the specified flag | | |
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 $threading = (bool) $RCMAIL->storage->get_threading(); | |
28 $skip_deleted = (bool) $RCMAIL->config->get('skip_deleted'); | |
29 $read_deleted = (bool) $RCMAIL->config->get('read_when_deleted'); | |
30 | |
31 $a_flags_map = array( | |
32 'undelete' => 'UNDELETED', | |
33 'delete' => 'DELETED', | |
34 'read' => 'SEEN', | |
35 'unread' => 'UNSEEN', | |
36 'flagged' => 'FLAGGED', | |
37 'unflagged' => 'UNFLAGGED', | |
38 ); | |
39 | |
40 $_uids = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST); | |
41 $flag = rcube_utils::get_input_value('_flag', rcube_utils::INPUT_POST); | |
42 $folders = rcube_utils::get_input_value('_folders', rcube_utils::INPUT_POST); | |
43 $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST); | |
44 | |
45 if ($_uids && $flag) { | |
46 $flag = $a_flags_map[$flag] ?: strtoupper($flag); | |
47 | |
48 if ($flag == 'DELETED' && $skip_deleted && $_POST['_from'] != 'show') { | |
49 // count messages before changing anything | |
50 $old_count = $RCMAIL->storage->count(NULL, $threading ? 'THREADS' : 'ALL'); | |
51 $old_pages = ceil($old_count / $RCMAIL->storage->get_pagesize()); | |
52 } | |
53 | |
54 if ($folders == 'all') { | |
55 $mboxes = $RCMAIL->storage->list_folders_subscribed('', '*', 'mail'); | |
56 $input = array_combine($mboxes, array_fill(0, count($mboxes), '*')); | |
57 } | |
58 else if ($folders == 'sub') { | |
59 $delim = $RCMAIL->storage->get_hierarchy_delimiter(); | |
60 $mboxes = $RCMAIL->storage->list_folders_subscribed($mbox . $delim, '*', 'mail'); | |
61 array_unshift($mboxes, $mbox); | |
62 $input = array_combine($mboxes, array_fill(0, count($mboxes), '*')); | |
63 } | |
64 else if ($folders == 'cur') { | |
65 $input = array($mbox => '*'); | |
66 } | |
67 else { | |
68 $input = rcmail::get_uids(); | |
69 } | |
70 | |
71 foreach ($input as $mbox => $uids) { | |
72 $marked += (int)$RCMAIL->storage->set_flag($uids, $flag, $mbox); | |
73 $count += count($uids); | |
74 } | |
75 | |
76 if (!$marked) { | |
77 // send error message | |
78 if ($_POST['_from'] != 'show') { | |
79 $OUTPUT->command('list_mailbox'); | |
80 } | |
81 | |
82 $RCMAIL->display_server_error('errormarking'); | |
83 $OUTPUT->send(); | |
84 exit; | |
85 } | |
86 else if (empty($_POST['_quiet'])) { | |
87 $OUTPUT->show_message('messagemarked', 'confirmation'); | |
88 } | |
89 | |
90 if ($flag == 'DELETED' && $read_deleted && !empty($_POST['_ruid'])) { | |
91 $ruids = rcube_utils::get_input_value('_ruid', rcube_utils::INPUT_POST); | |
92 foreach (rcmail::get_uids($ruids) as $mbox => $uids) { | |
93 $read += (int)$RCMAIL->storage->set_flag($uids, 'SEEN', $mbox); | |
94 } | |
95 | |
96 if ($read && !$skip_deleted) { | |
97 $OUTPUT->command('flag_deleted_as_read', $ruids); | |
98 } | |
99 } | |
100 | |
101 if ($flag == 'SEEN' || $flag == 'UNSEEN' || ($flag == 'DELETED' && !$skip_deleted)) { | |
102 foreach ($input as $mbox => $uids) { | |
103 rcmail_send_unread_count($mbox); | |
104 } | |
105 | |
106 $OUTPUT->set_env('last_flag', $flag); | |
107 } | |
108 else if ($flag == 'DELETED' && $skip_deleted) { | |
109 if ($_POST['_from'] == 'show') { | |
110 if ($next = rcube_utils::get_input_value('_next_uid', rcube_utils::INPUT_GPC)) | |
111 $OUTPUT->command('show_message', $next); | |
112 else | |
113 $OUTPUT->command('command', 'list'); | |
114 } | |
115 else { | |
116 $search_request = rcube_utils::get_input_value('_search', rcube_utils::INPUT_GPC); | |
117 | |
118 // refresh saved search set after moving some messages | |
119 if ($search_request && $RCMAIL->storage->get_search_set()) { | |
120 $_SESSION['search'] = $RCMAIL->storage->refresh_search(); | |
121 } | |
122 | |
123 $msg_count = $RCMAIL->storage->count(NULL, $threading ? 'THREADS' : 'ALL'); | |
124 $page_size = $RCMAIL->storage->get_pagesize(); | |
125 $page = $RCMAIL->storage->get_page(); | |
126 $pages = ceil($msg_count / $page_size); | |
127 $nextpage_count = $old_count - $page_size * $page; | |
128 $remaining = $msg_count - $page_size * ($page - 1); | |
129 | |
130 // jump back one page (user removed the whole last page) | |
131 if ($page > 1 && $remaining == 0) { | |
132 $page -= 1; | |
133 $RCMAIL->storage->set_page($page); | |
134 $_SESSION['page'] = $page; | |
135 $jump_back = true; | |
136 } | |
137 | |
138 // update message count display | |
139 $OUTPUT->set_env('messagecount', $msg_count); | |
140 $OUTPUT->set_env('current_page', $page); | |
141 $OUTPUT->set_env('pagecount', $pages); | |
142 | |
143 // update mailboxlist | |
144 $mbox = $RCMAIL->storage->get_folder(); | |
145 $unseen_count = $msg_count ? $RCMAIL->storage->count($mbox, 'UNSEEN') : 0; | |
146 $old_unseen = rcmail_get_unseen_count($mbox); | |
147 | |
148 if ($old_unseen != $unseen_count) { | |
149 $OUTPUT->command('set_unread_count', $mbox, $unseen_count, ($mbox == 'INBOX')); | |
150 rcmail_set_unseen_count($mbox, $unseen_count); | |
151 } | |
152 | |
153 $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count), $mbox); | |
154 | |
155 if ($threading) { | |
156 $count = rcube_utils::get_input_value('_count', rcube_utils::INPUT_POST); | |
157 } | |
158 | |
159 // add new rows from next page (if any) | |
160 if ($old_count && $_uids != '*' && ($jump_back || $nextpage_count > 0)) { | |
161 // #5862: Don't add more rows than it was on the next page | |
162 $count = $jump_back ? null : min($nextpage_count, $count); | |
163 | |
164 $a_headers = $RCMAIL->storage->list_messages($mbox, null, | |
165 rcmail_sort_column(), rcmail_sort_order(), $count); | |
166 | |
167 rcmail_js_message_list($a_headers, false); | |
168 } | |
169 } | |
170 } | |
171 } | |
172 else { | |
173 $OUTPUT->show_message('internalerror', 'error'); | |
174 } | |
175 | |
176 $OUTPUT->send(); |