]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/check_recent.inc
f3c9be0805d3f1c6a4babda60ed57ea8b6f4be0e
[roundcube.git] / program / steps / mail / check_recent.inc
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  | 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: check_recent.inc 4872 2011-06-22 05:52:48Z thomasb $
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
26 if ($check_all) {
27     $a_mailboxes = $IMAP->list_mailboxes('', '*', 'mail');
28 }
29 else {
30     $a_mailboxes = (array) $current;
31     if ($a_mailboxes[0] != 'INBOX')
32         $a_mailboxes[] = 'INBOX';
33 }
34
35 // check recent/unseen counts
36 foreach ($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             // trigger plugin hook
75             $RCMAIL->plugins->exec_hook('new_messages', array('mailbox' => $mbox_name));
76         }
77
78         // remove old rows (and clear selection if new list is empty)
79         $OUTPUT->command('message_list.clear', $all_count ? false : true);
80
81         if ($all_count) {
82             $a_headers = $IMAP->list_headers($mbox_name, null, $_SESSION['sort_col'], $_SESSION['sort_order']);
83             // add message rows
84             rcmail_js_message_list($a_headers, false);
85             // remove messages that don't exists from list selection array
86             $OUTPUT->command('update_selection');
87         }
88     }
89     else {
90         rcmail_send_unread_count($mbox_name, true);
91     }
92 }
93
94 $RCMAIL->plugins->exec_hook('keep_alive', array());
95
96 $OUTPUT->send();