]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/check_recent.inc
Imported Upstream version 0.2.1
[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-2009, 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: check_recent.inc 233 2006-06-26 17:31:20Z richs $
19
20 */
21
22 $a_mailboxes = $IMAP->list_mailboxes();
23 $check_all = (bool)$RCMAIL->config->get('check_all_folders');
24
25 foreach ($a_mailboxes as $mbox_name) {
26   if ($mbox_name == $IMAP->get_mailbox_name()) {
27     if ($recent_count = $IMAP->messagecount(NULL, 'RECENT', TRUE)) {
28       // refresh saved search set
29       if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && isset($_SESSION['search'][$search_request])) {
30         $_SESSION['search'][$search_request] = $IMAP->refresh_search();
31         $all_count = $IMAP->messagecount();
32       } else {
33         $all_count = $IMAP->messagecount(NULL, 'ALL', TRUE);
34       }
35       
36       $unread_count = $IMAP->messagecount(NULL, 'UNSEEN', TRUE);
37
38       $OUTPUT->set_env('messagecount', $all_count);
39       $OUTPUT->set_env('pagesize', $IMAP->page_size);
40       $OUTPUT->set_env('pagecount', ceil($all_count/$IMAP->page_size));
41       $OUTPUT->command('set_unread_count', $mbox_name, $unread_count, ($mbox_name == 'INBOX'));
42       $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($all_count));
43
44       if (rcmail::get_instance()->config->get('focus_on_new_message',true))
45         $OUTPUT->command('new_message_focus');
46
47       if (!empty($_GET['_quota']))
48         $OUTPUT->command('set_quota', rcmail_quota_content($IMAP->get_quota()));
49
50       // "No-list" mode, don't get messages
51       if (empty($_GET['_list']))
52         continue;
53
54       // use SEARCH/SORT to find recent messages
55       $search_str = 'RECENT';
56       if ($search_request)
57         $search_str .= ' '.$IMAP->search_string;
58
59       $result = $IMAP->search($mbox_name, $search_str, NULL, 'date');
60
61       if ($result) {
62         // get the headers
63         $result_h = $IMAP->list_headers($mbox_name, 1, 'date', 'DESC');
64         // add to the list
65         rcmail_js_message_list($result_h, TRUE);
66       }
67     }
68   }
69   else if ($unseen = $IMAP->messagecount($mbox_name, 'UNSEEN', $check_all)) {
70     $OUTPUT->command('set_unread_count', $mbox_name, $unseen);
71   }
72 }
73
74 $OUTPUT->send();
75
76 ?>