Aleksander Machniak
2014-12-17 2ae677afd7b5644eb3f163ce237acab0dc735ab2
program/steps/mail/check_recent.inc
@@ -21,12 +21,15 @@
// If there's no folder or messages list, there's nothing to update
// This can happen on 'refresh' request
if (empty($_REQUEST['_folderlist']) && empty($_REQUEST['_list'])) {
if (empty($_POST['_folderlist']) && empty($_POST['_list'])) {
    return;
}
$trash     = $RCMAIL->config->get('trash_mbox');
$current   = $RCMAIL->storage->get_folder();
$check_all = $RCMAIL->action != 'refresh' || (bool)$RCMAIL->config->get('check_all_folders');
$page      = $RCMAIL->storage->get_page();
$page_size = $RCMAIL->storage->get_pagesize();
// list of folders to check
if ($check_all) {
@@ -52,12 +55,12 @@
    }
    // Get mailbox status
    $status = $RCMAIL->storage->folder_status($mbox_name);
    $status = $RCMAIL->storage->folder_status($mbox_name, $diff);
    if ($status & 1) {
        // trigger plugin hook
        $RCMAIL->plugins->exec_hook('new_messages',
            array('mailbox' => $mbox_name, 'is_current' => $is_current));
            array('mailbox' => $mbox_name, 'is_current' => $is_current, 'diff' => $diff));
    }
    rcmail_send_unread_count($mbox_name, true, null,
@@ -65,27 +68,28 @@
    if ($status && $is_current) {
        // refresh saved search set
        $search_request = get_input_value('_search', RCUBE_INPUT_GPC);
        $search_request = rcube_utils::get_input_value('_search', rcube_utils::INPUT_GPC);
        if ($search_request && isset($_SESSION['search'])
            && $_SESSION['search_request'] == $search_request
        ) {
            $_SESSION['search'] = $RCMAIL->storage->refresh_search();
        }
        if (!empty($_GET['_quota']))
            $OUTPUT->command('set_quota', rcmail_quota_content());
        if (!empty($_POST['_quota'])) {
            $OUTPUT->command('set_quota', $RCMAIL->quota_content());
        }
        $OUTPUT->set_env('exists', $RCMAIL->storage->count($mbox_name, 'EXISTS'));
        // "No-list" mode, don't get messages
        if (empty($_GET['_list']))
        if (empty($_POST['_list'])) {
            continue;
        }
        // get overall message count; allow caching because rcube_storage::folder_status() did a refresh
        // get overall message count; allow caching because rcube_storage::folder_status()
        // did a refresh but only in list mode
        $list_mode = $RCMAIL->storage->get_threading() ? 'THREADS' : 'ALL';
        $all_count = $RCMAIL->storage->count($mbox_name, $list_mode, false, false);
        $page      = $RCMAIL->storage->get_page();
        $page_size = $RCMAIL->storage->get_pagesize();
        $all_count = $RCMAIL->storage->count($mbox_name, $list_mode, $list_mode == 'THREADS', false);
        // check current page if we're not on the first page
        if ($all_count && $page > 1) {
@@ -113,6 +117,32 @@
            $OUTPUT->command('update_selection');
        }
    }
    // handle flag updates
    else if ($is_current && ($uids = rcube_utils::get_input_value('_uids', rcube_utils::INPUT_GPC))) {
        $data = $RCMAIL->storage->folder_data($mbox_name);
        if (empty($_SESSION['list_mod_seq']) || $_SESSION['list_mod_seq'] != $data['HIGHESTMODSEQ']) {
            $flags = $RCMAIL->storage->list_flags($mbox_name, explode(',', $uids), $_SESSION['list_mod_seq']);
            foreach ($flags as $idx => $row) {
                $flags[$idx] = array_change_key_case(array_map('intval', $row));
            }
            // remember last HIGHESTMODSEQ value (if supported)
            if (!empty($data['HIGHESTMODSEQ'])) {
                $_SESSION['list_mod_seq'] = $data['HIGHESTMODSEQ'];
            }
            $RCMAIL->output->set_env('recent_flags', $flags);
        }
    }
    // set trash folder state
    if ($mbox_name === $trash) {
        $OUTPUT->command('set_trash_count', $RCMAIL->storage->count($mbox_name, 'EXISTS'));
    }
}
// trigger refresh hook
$RCMAIL->plugins->exec_hook('refresh', array());
$OUTPUT->send();