Mercurial > hg > rc2
comparison program/steps/mail/check_recent.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/check_recent.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 | Check for recent messages, in all mailboxes | | |
16 | | | |
17 +-----------------------------------------------------------------------+ | |
18 | Author: Thomas Bruederli <roundcube@gmail.com> | | |
19 +-----------------------------------------------------------------------+ | |
20 */ | |
21 | |
22 // If there's no folder or messages list, there's nothing to update | |
23 // This can happen on 'refresh' request | |
24 if (empty($_POST['_folderlist']) && empty($_POST['_list'])) { | |
25 return; | |
26 } | |
27 | |
28 $trash = $RCMAIL->config->get('trash_mbox'); | |
29 $current = $RCMAIL->storage->get_folder(); | |
30 $check_all = $RCMAIL->action != 'refresh' || (bool)$RCMAIL->config->get('check_all_folders'); | |
31 $page = $RCMAIL->storage->get_page(); | |
32 $page_size = $RCMAIL->storage->get_pagesize(); | |
33 | |
34 $search_request = rcube_utils::get_input_value('_search', rcube_utils::INPUT_GPC); | |
35 if ($search_request && $_SESSION['search_request'] != $search_request) { | |
36 $search_request = null; | |
37 } | |
38 | |
39 // list of folders to check | |
40 if ($check_all) { | |
41 $a_mailboxes = $RCMAIL->storage->list_folders_subscribed('', '*', 'mail'); | |
42 } | |
43 else if ($search_request && is_object($_SESSION['search'][1])) { | |
44 $a_mailboxes = (array) $_SESSION['search'][1]->get_parameters('MAILBOX'); | |
45 } | |
46 else { | |
47 $a_mailboxes = (array) $current; | |
48 if ($current != 'INBOX') { | |
49 $a_mailboxes[] = 'INBOX'; | |
50 } | |
51 } | |
52 | |
53 // Control folders list from a plugin | |
54 $plugin = $RCMAIL->plugins->exec_hook('check_recent', array('folders' => $a_mailboxes, 'all' => $check_all)); | |
55 $a_mailboxes = $plugin['folders']; | |
56 | |
57 // check recent/unseen counts | |
58 foreach ($a_mailboxes as $mbox_name) { | |
59 $is_current = $mbox_name == $current || ($search_request && is_object($_SESSION['search'][1]) && in_array($mbox_name, (array)$_SESSION['search'][1]->get_parameters('MAILBOX'))); | |
60 if ($is_current) { | |
61 // Synchronize mailbox cache, handle flag changes | |
62 $RCMAIL->storage->folder_sync($mbox_name); | |
63 } | |
64 | |
65 // Get mailbox status | |
66 $status = $RCMAIL->storage->folder_status($mbox_name, $diff); | |
67 | |
68 if ($status & 1) { | |
69 // trigger plugin hook | |
70 $RCMAIL->plugins->exec_hook('new_messages', | |
71 array('mailbox' => $mbox_name, 'is_current' => $is_current, 'diff' => $diff)); | |
72 } | |
73 | |
74 rcmail_send_unread_count($mbox_name, true, null, | |
75 (!$is_current && ($status & 1)) ? 'recent' : ''); | |
76 | |
77 if ($status && $is_current) { | |
78 // refresh saved search set | |
79 if ($search_request && isset($_SESSION['search'])) { | |
80 unset($search_request); // only do this once | |
81 $_SESSION['search'] = $RCMAIL->storage->refresh_search(); | |
82 if ($_SESSION['search'][1]->multi) { | |
83 $mbox_name = ''; | |
84 } | |
85 } | |
86 | |
87 if (!empty($_POST['_quota'])) { | |
88 $OUTPUT->command('set_quota', $RCMAIL->quota_content(null, $mbox_name)); | |
89 } | |
90 | |
91 $OUTPUT->set_env('exists', $RCMAIL->storage->count($mbox_name, 'EXISTS', true)); | |
92 | |
93 // "No-list" mode, don't get messages | |
94 if (empty($_POST['_list'])) { | |
95 continue; | |
96 } | |
97 | |
98 // get overall message count; allow caching because rcube_storage::folder_status() | |
99 // did a refresh but only in list mode | |
100 $list_mode = $RCMAIL->storage->get_threading() ? 'THREADS' : 'ALL'; | |
101 $all_count = $RCMAIL->storage->count($mbox_name, $list_mode, $list_mode == 'THREADS', false); | |
102 | |
103 // check current page if we're not on the first page | |
104 if ($all_count && $page > 1) { | |
105 $remaining = $all_count - $page_size * ($page - 1); | |
106 if ($remaining <= 0) { | |
107 $page -= 1; | |
108 $RCMAIL->storage->set_page($page); | |
109 $_SESSION['page'] = $page; | |
110 } | |
111 } | |
112 | |
113 $OUTPUT->set_env('messagecount', $all_count); | |
114 $OUTPUT->set_env('pagecount', ceil($all_count/$page_size)); | |
115 $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($all_count), $mbox_name); | |
116 $OUTPUT->set_env('current_page', $all_count ? $page : 1); | |
117 | |
118 // remove old rows (and clear selection if new list is empty) | |
119 $OUTPUT->command('message_list.clear', $all_count ? false : true); | |
120 | |
121 if ($all_count) { | |
122 $a_headers = $RCMAIL->storage->list_messages($mbox_name, null, rcmail_sort_column(), rcmail_sort_order()); | |
123 // add message rows | |
124 rcmail_js_message_list($a_headers, false); | |
125 // remove messages that don't exists from list selection array | |
126 $OUTPUT->command('update_selection'); | |
127 } | |
128 } | |
129 // handle flag updates | |
130 else if ($is_current && ($uids = rcube_utils::get_input_value('_uids', rcube_utils::INPUT_GPC)) && empty($search_request)) { | |
131 $data = $RCMAIL->storage->folder_data($mbox_name); | |
132 | |
133 if (empty($_SESSION['list_mod_seq']) || $_SESSION['list_mod_seq'] != $data['HIGHESTMODSEQ']) { | |
134 $flags = $RCMAIL->storage->list_flags($mbox_name, explode(',', $uids), $_SESSION['list_mod_seq']); | |
135 foreach ($flags as $idx => $row) { | |
136 $flags[$idx] = array_change_key_case(array_map('intval', $row)); | |
137 } | |
138 | |
139 // remember last HIGHESTMODSEQ value (if supported) | |
140 if (!empty($data['HIGHESTMODSEQ'])) { | |
141 $_SESSION['list_mod_seq'] = $data['HIGHESTMODSEQ']; | |
142 } | |
143 | |
144 $RCMAIL->output->set_env('recent_flags', $flags); | |
145 } | |
146 } | |
147 | |
148 // set trash folder state | |
149 if ($mbox_name === $trash) { | |
150 $OUTPUT->command('set_trash_count', $RCMAIL->storage->count($mbox_name, 'EXISTS', true)); | |
151 } | |
152 } | |
153 | |
154 // trigger refresh hook | |
155 $RCMAIL->plugins->exec_hook('refresh', array()); | |
156 | |
157 $OUTPUT->send(); |