source: github/program/steps/mail/check_recent.inc @ 5e9a566

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since 5e9a566 was 5e9a566, checked in by thomascube <thomas@…>, 3 years ago

Fix checking for new mail (#1485794)

  • Property mode set to 100644
File size: 3.6 KB
Line 
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$
19
20*/
21
22$a_mailboxes = $IMAP->list_mailboxes();
23$check_all = (bool)$RCMAIL->config->get('check_all_folders');
24
25// check if unread count of INBOX changed and refresh message list if so
26if (!empty($_GET['_refresh'])) {
27  $unread_count = $IMAP->messagecount('INBOX', 'UNSEEN', TRUE);
28  if ($unread_count > $_SESSION['unseen_count']['INBOX']) {
29    $OUTPUT->command('set_unread_count', 'INBOX', $unread_count, true);
30    $OUTPUT->command('list_mailbox', 'INBOX', 1);  // let the client switch to INBOX and get the message list
31    $OUTPUT->send();
32  }
33}
34
35// check recent/unseen counts for all mailboxes
36foreach ($a_mailboxes as $mbox_name) {
37  if ($mbox_name == $IMAP->get_mailbox_name()) {
38    if ($recent_count = $IMAP->messagecount(NULL, 'RECENT', TRUE)) {
39      // refresh saved search set
40      if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && isset($_SESSION['search'][$search_request])) {
41        $_SESSION['search'][$search_request] = $IMAP->refresh_search();
42        $all_count = $IMAP->messagecount();
43      } else {
44        $all_count = $IMAP->messagecount(NULL, 'ALL', TRUE);
45      }
46     
47      $unread_count = $IMAP->messagecount(NULL, 'UNSEEN', TRUE);
48      $_SESSION['unseen_count'][$mbox_name] = $unread_count;
49
50      $OUTPUT->set_env('messagecount', $all_count);
51      $OUTPUT->set_env('pagesize', $IMAP->page_size);
52      $OUTPUT->set_env('pagecount', ceil($all_count/$IMAP->page_size));
53      $OUTPUT->command('set_unread_count', $mbox_name, $unread_count, ($mbox_name == 'INBOX'));
54      $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($all_count));
55
56      if (rcmail::get_instance()->config->get('focus_on_new_message',true))
57        $OUTPUT->command('new_message_focus');
58
59      if (!empty($_GET['_quota']))
60        $OUTPUT->command('set_quota', rcmail_quota_content());
61
62      // trigger plugin hook
63      $RCMAIL->plugins->exec_hook('new_messages', array('mailbox' => $mbox_name, 'count' => $unread_count));
64
65      // "No-list" mode, don't get messages
66      if (empty($_GET['_list']))
67        continue;
68
69      // use SEARCH/SORT to find recent messages
70      $search_str = 'RECENT';
71      if ($search_request)
72        $search_str .= ' '.$IMAP->search_string;
73
74      $result = $IMAP->search($mbox_name, $search_str, NULL, 'date');
75
76      if ($result) {
77        // get the headers
78        $result_h = $IMAP->list_headers($mbox_name, 1, 'date', 'DESC');
79        // add to the list
80        rcmail_js_message_list($result_h, true, false);
81      }
82    }
83    else {
84      rcmail_send_unread_count($mbox_name, true);
85    }
86  }
87  else if ($check_all) {
88    rcmail_send_unread_count($mbox_name, true);
89  }
90}
91
92$OUTPUT->send();
93
94?>
Note: See TracBrowser for help on using the repository browser.