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

Last change on this file since 4084 was 4084, checked in by alec, 3 years ago
  • Minimize session data size by storing only last search result and by removing search result from session after listing with empty search filter
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 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, Roundcube Dev. - Switzerland                 |
9 | Licensed under the GNU GPL                                            |
10 |                                                                       |
11 | PURPOSE:                                                              |
12 |   Check for recent messages, in all mailboxes                         |
13 |                                                                       |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16 +-----------------------------------------------------------------------+
17
18 $Id$
19
20*/
21
22$current = $IMAP->get_mailbox_name();
23$check_all = !empty($_GET['_refresh']) || (bool)$RCMAIL->config->get('check_all_folders');
24
25// list of folders to check
26if ($check_all) {
27    $a_mailboxes = $IMAP->list_mailboxes();
28}
29else {
30    $a_mailboxes = (array) $current;
31    if ($a_mailboxes[0] != 'INBOX')
32        $a_mailboxes[] = 'INBOX';
33}
34
35// check recent/unseen counts
36foreach ($a_mailboxes as $mbox_name) {
37    if ($mbox_name == $current && ($status = $IMAP->mailbox_status($mbox_name))) {
38
39        rcmail_send_unread_count($mbox_name, true);
40
41        // refresh saved search set
42        $search_request = get_input_value('_search', RCUBE_INPUT_GPC);
43        if ($search_request && isset($_SESSION['search'])
44            && $_SESSION['search_request'] == $search_request
45        ) {
46            $_SESSION['search'] = $IMAP->refresh_search();
47        }
48
49        if (!empty($_GET['_quota']))
50            $OUTPUT->command('set_quota', rcmail_quota_content());
51
52        // "No-list" mode, don't get messages
53        if (empty($_GET['_list']))
54            continue;
55
56        // get overall message count; allow caching because rcube_imap::mailbox_status() did a refresh
57        $all_count = $IMAP->messagecount(null, $IMAP->threading ? 'THREADS' : 'ALL');
58
59        // check current page if we're not on the first page
60        if ($all_count && $IMAP->list_page > 1) {
61            $remaining = $all_count - $IMAP->page_size * ($IMAP->list_page - 1);
62            if ($remaining <= 0) {
63                $IMAP->set_page($IMAP->list_page-1);
64                $_SESSION['page'] = $IMAP->list_page;
65            }
66        }
67
68        $OUTPUT->set_env('messagecount', $all_count);
69        $OUTPUT->set_env('pagecount', ceil($all_count/$IMAP->page_size));
70        $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($all_count));
71        $OUTPUT->set_env('current_page', $all_count ? $IMAP->list_page : 1);
72
73        if ($status & 1) {
74            if ($RCMAIL->config->get('focus_on_new_message', true))
75                $OUTPUT->command('new_message_focus');
76            // trigger plugin hook
77            $RCMAIL->plugins->exec_hook('new_messages', array('mailbox' => $mbox_name));
78        }
79
80        // remove old rows (and clear selection if new list is empty)
81        $OUTPUT->command('message_list.clear', $all_count ? false : true);
82
83        if ($all_count) {
84            $a_headers = $IMAP->list_headers($mbox_name, null, $_SESSION['sort_col'], $_SESSION['sort_order']);
85            // add message rows
86            rcmail_js_message_list($a_headers, false);
87            // remove messages that don't exists from list selection array
88            $OUTPUT->command('update_selection');
89        }
90    }
91    else {
92        rcmail_send_unread_count($mbox_name, true);
93    }
94}
95
96$OUTPUT->send();
Note: See TracBrowser for help on using the repository browser.