]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/check_recent.inc
Imported Upstream version 0.3
[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       // trigger plugin hook
51       $RCMAIL->plugins->exec_hook('new_messages', array('mailbox' => $mbox_name, 'count' => $unread_count));
52
53       // "No-list" mode, don't get messages
54       if (empty($_GET['_list']))
55         continue;
56
57       // use SEARCH/SORT to find recent messages
58       $search_str = 'RECENT';
59       if ($search_request)
60         $search_str .= ' '.$IMAP->search_string;
61
62       $result = $IMAP->search($mbox_name, $search_str, NULL, 'date');
63
64       if ($result) {
65         // get the headers
66         $result_h = $IMAP->list_headers($mbox_name, 1, 'date', 'DESC');
67         // add to the list
68         rcmail_js_message_list($result_h, true, false);
69       }
70     }
71   }
72   else if ($unseen = $IMAP->messagecount($mbox_name, 'UNSEEN', $check_all)) {
73     $OUTPUT->command('set_unread_count', $mbox_name, $unseen);
74   }
75 }
76
77 $OUTPUT->send();
78
79 ?>