]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/check_recent.inc
Imported Upstream version 0.7
[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 5266 2011-09-22 07:49:33Z alec $
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     $is_current = $mbox_name == $current;
38     if ($is_current) {
39         // Synchronize mailbox cache, handle flag changes
40         $IMAP->mailbox_sync($mbox_name);
41     }
42
43     // Get mailbox status
44     $status = $IMAP->mailbox_status($mbox_name);
45
46     if ($status & 1) {
47         // trigger plugin hook
48         $RCMAIL->plugins->exec_hook('new_messages',
49             array('mailbox' => $mbox_name, 'is_current' => $is_current));
50     }
51
52     rcmail_send_unread_count($mbox_name, true);
53
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
59         ) {
60             $_SESSION['search'] = $IMAP->refresh_search();
61         }
62
63         if (!empty($_GET['_quota']))
64             $OUTPUT->command('set_quota', rcmail_quota_content());
65
66         // "No-list" mode, don't get messages
67         if (empty($_GET['_list']))
68             continue;
69
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');
72
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;
79             }
80         }
81
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);
86
87         // remove old rows (and clear selection if new list is empty)
88         $OUTPUT->command('message_list.clear', $all_count ? false : true);
89
90         if ($all_count) {
91             $a_headers = $IMAP->list_headers($mbox_name, null, $_SESSION['sort_col'], $_SESSION['sort_order']);
92             // add message rows
93             rcmail_js_message_list($a_headers, false);
94             // remove messages that don't exists from list selection array
95             $OUTPUT->command('update_selection');
96         }
97     }
98 }
99
100 $RCMAIL->plugins->exec_hook('keep_alive', array());
101
102 $OUTPUT->send();