source: subversion/trunk/roundcubemail/program/steps/mail/check_recent.inc

Last change on this file was 5858, checked in by alec, 16 months ago
  • Workaround IMAP server issue when THREAD command returns less messages than exist in a folder: don't update folder status in second count() call
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
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-2010, 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 $Id$
22
23*/
24
25$current = $RCMAIL->storage->get_folder();
26$check_all = !empty($_GET['_refresh']) || (bool)$RCMAIL->config->get('check_all_folders');
27
28// list of folders to check
29if ($check_all) {
30    $a_mailboxes = $RCMAIL->storage->list_folders_subscribed('', '*', 'mail');
31}
32else {
33    $a_mailboxes = (array) $current;
34    if ($a_mailboxes[0] != 'INBOX')
35        $a_mailboxes[] = 'INBOX';
36}
37
38// check recent/unseen counts
39foreach ($a_mailboxes as $mbox_name) {
40    $is_current = $mbox_name == $current;
41    if ($is_current) {
42        // Synchronize mailbox cache, handle flag changes
43        $RCMAIL->storage->folder_sync($mbox_name);
44    }
45
46    // Get mailbox status
47    $status = $RCMAIL->storage->folder_status($mbox_name);
48
49    if ($status & 1) {
50        // trigger plugin hook
51        $RCMAIL->plugins->exec_hook('new_messages',
52            array('mailbox' => $mbox_name, 'is_current' => $is_current));
53    }
54
55    rcmail_send_unread_count($mbox_name, true, null,
56      (!$is_current && ($status & 1)) ? 'recent' : '');
57
58    if ($status && $is_current) {
59        // refresh saved search set
60        $search_request = get_input_value('_search', RCUBE_INPUT_GPC);
61        if ($search_request && isset($_SESSION['search'])
62            && $_SESSION['search_request'] == $search_request
63        ) {
64            $_SESSION['search'] = $RCMAIL->storage->refresh_search();
65        }
66
67        if (!empty($_GET['_quota']))
68            $OUTPUT->command('set_quota', rcmail_quota_content());
69
70        // "No-list" mode, don't get messages
71        if (empty($_GET['_list']))
72            continue;
73
74        // get overall message count; allow caching because rcube_storage::folder_status() did a refresh
75        $list_mode = $RCMAIL->storage->get_threading() ? 'THREADS' : 'ALL';
76        $all_count = $RCMAIL->storage->count(null, $list_mode, false, false);
77        $page      = $RCMAIL->storage->get_page();
78        $page_size = $RCMAIL->storage->get_pagesize();
79
80        // check current page if we're not on the first page
81        if ($all_count && $page > 1) {
82            $remaining = $all_count - $page_size * ($page - 1);
83            if ($remaining <= 0) {
84                $page -= 1;
85                $RCMAIL->storage->set_page($page);
86                $_SESSION['page'] = $page;
87            }
88        }
89
90        $OUTPUT->set_env('messagecount', $all_count);
91        $OUTPUT->set_env('pagecount', ceil($all_count/$page_size));
92        $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($all_count), $mbox_name);
93        $OUTPUT->set_env('current_page', $all_count ? $page : 1);
94
95        // remove old rows (and clear selection if new list is empty)
96        $OUTPUT->command('message_list.clear', $all_count ? false : true);
97
98        if ($all_count) {
99            $a_headers = $RCMAIL->storage->list_messages($mbox_name, null, $_SESSION['sort_col'], $_SESSION['sort_order']);
100            // add message rows
101            rcmail_js_message_list($a_headers, false);
102            // remove messages that don't exists from list selection array
103            $OUTPUT->command('update_selection');
104        }
105    }
106}
107
108$RCMAIL->plugins->exec_hook('keep_alive', array());
109
110$OUTPUT->send();
Note: See TracBrowser for help on using the repository browser.