4 +-----------------------------------------------------------------------+
5 | program/steps/mail/check_recent.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2010, The Roundcube Dev Team |
9 | Licensed under the GNU GPL |
12 | Check for recent messages, in all mailboxes |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: check_recent.inc 5266 2011-09-22 07:49:33Z alec $
22 $current = $IMAP->get_mailbox_name();
23 $check_all = !empty($_GET['_refresh']) || (bool)$RCMAIL->config->get('check_all_folders');
25 // list of folders to check
27 $a_mailboxes = $IMAP->list_mailboxes('', '*', 'mail');
30 $a_mailboxes = (array) $current;
31 if ($a_mailboxes[0] != 'INBOX')
32 $a_mailboxes[] = 'INBOX';
35 // check recent/unseen counts
36 foreach ($a_mailboxes as $mbox_name) {
37 $is_current = $mbox_name == $current;
39 // Synchronize mailbox cache, handle flag changes
40 $IMAP->mailbox_sync($mbox_name);
44 $status = $IMAP->mailbox_status($mbox_name);
47 // trigger plugin hook
48 $RCMAIL->plugins->exec_hook('new_messages',
49 array('mailbox' => $mbox_name, 'is_current' => $is_current));
52 rcmail_send_unread_count($mbox_name, true);
54 if ($status && $is_current) {
55 // refresh saved search set
56 $search_request = get_input_value('_search', RCUBE_INPUT_GPC);
57 if ($search_request && isset($_SESSION['search'])
58 && $_SESSION['search_request'] == $search_request
60 $_SESSION['search'] = $IMAP->refresh_search();
63 if (!empty($_GET['_quota']))
64 $OUTPUT->command('set_quota', rcmail_quota_content());
66 // "No-list" mode, don't get messages
67 if (empty($_GET['_list']))
70 // get overall message count; allow caching because rcube_imap::mailbox_status() did a refresh
71 $all_count = $IMAP->messagecount(null, $IMAP->threading ? 'THREADS' : 'ALL');
73 // check current page if we're not on the first page
74 if ($all_count && $IMAP->list_page > 1) {
75 $remaining = $all_count - $IMAP->page_size * ($IMAP->list_page - 1);
76 if ($remaining <= 0) {
77 $IMAP->set_page($IMAP->list_page-1);
78 $_SESSION['page'] = $IMAP->list_page;
82 $OUTPUT->set_env('messagecount', $all_count);
83 $OUTPUT->set_env('pagecount', ceil($all_count/$IMAP->page_size));
84 $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($all_count), $mbox_name);
85 $OUTPUT->set_env('current_page', $all_count ? $IMAP->list_page : 1);
87 // remove old rows (and clear selection if new list is empty)
88 $OUTPUT->command('message_list.clear', $all_count ? false : true);
91 $a_headers = $IMAP->list_headers($mbox_name, null, $_SESSION['sort_col'], $_SESSION['sort_order']);
93 rcmail_js_message_list($a_headers, false);
94 // remove messages that don't exists from list selection array
95 $OUTPUT->command('update_selection');
100 $RCMAIL->plugins->exec_hook('keep_alive', array());