]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/check_recent.inc
Imported Upstream version 0.3.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       $_SESSION['unseen_count'][$mbox_name] = $unread_count;
38
39       $OUTPUT->set_env('messagecount', $all_count);
40       $OUTPUT->set_env('pagesize', $IMAP->page_size);
41       $OUTPUT->set_env('pagecount', ceil($all_count/$IMAP->page_size));
42       $OUTPUT->command('set_unread_count', $mbox_name, $unread_count, ($mbox_name == 'INBOX'));
43       $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($all_count));
44
45       if (rcmail::get_instance()->config->get('focus_on_new_message',true))
46         $OUTPUT->command('new_message_focus');
47
48       if (!empty($_GET['_quota']))
49         $OUTPUT->command('set_quota', rcmail_quota_content($IMAP->get_quota()));
50
51       // trigger plugin hook
52       $RCMAIL->plugins->exec_hook('new_messages', array('mailbox' => $mbox_name, 'count' => $unread_count));
53
54       // "No-list" mode, don't get messages
55       if (empty($_GET['_list']))
56         continue;
57
58       // use SEARCH/SORT to find recent messages
59       $search_str = 'RECENT';
60       if ($search_request)
61         $search_str .= ' '.$IMAP->search_string;
62
63       $result = $IMAP->search($mbox_name, $search_str, NULL, 'date');
64
65       if ($result) {
66         // get the headers
67         $result_h = $IMAP->list_headers($mbox_name, 1, 'date', 'DESC');
68         // add to the list
69         rcmail_js_message_list($result_h, true, false);
70       }
71     }
72     else {
73       rcmail_send_unread_count($mbox_name, true);
74     }
75   }
76   else if ($check_all) {
77     rcmail_send_unread_count($mbox_name, true);
78   }
79 }
80
81 $OUTPUT->send();
82
83 ?>