|
|
@ -35,6 +35,9 @@ class newmail_notifier extends rcube_plugin
|
|
|
|
|
|
|
|
|
|
|
|
private $rc;
|
|
|
|
private $rc;
|
|
|
|
private $notified;
|
|
|
|
private $notified;
|
|
|
|
|
|
|
|
private $opt = array();
|
|
|
|
|
|
|
|
private $exceptions = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Plugin initialization
|
|
|
|
* Plugin initialization
|
|
|
@ -49,13 +52,34 @@ class newmail_notifier extends rcube_plugin
|
|
|
|
$this->add_hook('preferences_save', array($this, 'prefs_save'));
|
|
|
|
$this->add_hook('preferences_save', array($this, 'prefs_save'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // if ($this->rc->task == 'mail') {
|
|
|
|
else { // if ($this->rc->task == 'mail') {
|
|
|
|
$this->add_hook('new_messages', array($this, 'notify'));
|
|
|
|
|
|
|
|
// add script when not in ajax and not in frame
|
|
|
|
// add script when not in ajax and not in frame
|
|
|
|
if ($this->rc->output->type == 'html' && empty($_REQUEST['_framed'])) {
|
|
|
|
if ($this->rc->output->type == 'html' && empty($_REQUEST['_framed'])) {
|
|
|
|
$this->add_texts('localization/');
|
|
|
|
$this->add_texts('localization/');
|
|
|
|
$this->rc->output->add_label('newmail_notifier.title', 'newmail_notifier.body');
|
|
|
|
$this->rc->output->add_label('newmail_notifier.title', 'newmail_notifier.body');
|
|
|
|
$this->include_script('newmail_notifier.js');
|
|
|
|
$this->include_script('newmail_notifier.js');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->rc->action == 'refresh') {
|
|
|
|
|
|
|
|
// Load configuration
|
|
|
|
|
|
|
|
$this->load_config();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->opt['basic'] = $this->rc->config->get('newmail_notifier_basic');
|
|
|
|
|
|
|
|
$this->opt['sound'] = $this->rc->config->get('newmail_notifier_sound');
|
|
|
|
|
|
|
|
$this->opt['desktop'] = $this->rc->config->get('newmail_notifier_desktop');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($this->opt)) {
|
|
|
|
|
|
|
|
// Get folders to skip checking for
|
|
|
|
|
|
|
|
$exceptions = array('drafts_mbox', 'sent_mbox', 'trash_mbox');
|
|
|
|
|
|
|
|
foreach ($exceptions as $folder) {
|
|
|
|
|
|
|
|
$folder = $this->rc->config->get($folder);
|
|
|
|
|
|
|
|
if (strlen($folder) && $folder != 'INBOX') {
|
|
|
|
|
|
|
|
$this->exceptions[] = $folder;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->add_hook('new_messages', array($this, 'notify'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -132,43 +156,30 @@ class newmail_notifier extends rcube_plugin
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function notify($args)
|
|
|
|
function notify($args)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Already notified or non-automatic check
|
|
|
|
// Already notified or unexpected input
|
|
|
|
if ($this->notified || !empty($_GET['_refresh'])) {
|
|
|
|
if ($this->notified || empty($args['diff']['new'])) {
|
|
|
|
return $args;
|
|
|
|
return $args;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get folders to skip checking for
|
|
|
|
$mbox = $args['mailbox'];
|
|
|
|
if (empty($this->exceptions)) {
|
|
|
|
$storage = $this->rc->get_storage();
|
|
|
|
$this->delimiter = $this->rc->storage->get_hierarchy_delimiter();
|
|
|
|
$delimiter = $storage->get_hierarchy_delimiter();
|
|
|
|
|
|
|
|
|
|
|
|
$exceptions = array('drafts_mbox', 'sent_mbox', 'trash_mbox');
|
|
|
|
|
|
|
|
foreach ($exceptions as $folder) {
|
|
|
|
|
|
|
|
$folder = $this->rc->config->get($folder);
|
|
|
|
|
|
|
|
if (strlen($folder) && $folder != 'INBOX') {
|
|
|
|
|
|
|
|
$this->exceptions[] = $folder;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$mbox = $args['mailbox'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Skip exception (sent/drafts) folders (and their subfolders)
|
|
|
|
// Skip exception (sent/drafts) folders (and their subfolders)
|
|
|
|
foreach ($this->exceptions as $folder) {
|
|
|
|
foreach ($this->exceptions as $folder) {
|
|
|
|
if (strpos($mbox.$this->delimiter, $folder.$this->delimiter) === 0) {
|
|
|
|
if (strpos($mbox.$delimiter, $folder.$delimiter) === 0) {
|
|
|
|
return $args;
|
|
|
|
return $args;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->notified = true;
|
|
|
|
// Check if any of new messages is UNSEEN
|
|
|
|
|
|
|
|
$deleted = $this->rc->config->get('skip_deleted') ? 'UNDELETED ' : '';
|
|
|
|
// Load configuration
|
|
|
|
$search = $deleted . 'UNSEEN UID ' . $args['diff']['new'];
|
|
|
|
$this->load_config();
|
|
|
|
$unseen = $storage->search_once($mbox, $search);
|
|
|
|
|
|
|
|
|
|
|
|
$basic = $this->rc->config->get('newmail_notifier_basic');
|
|
|
|
if ($unseen->count()) {
|
|
|
|
$sound = $this->rc->config->get('newmail_notifier_sound');
|
|
|
|
$this->notified = true;
|
|
|
|
$desktop = $this->rc->config->get('newmail_notifier_desktop');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($basic || $sound || $desktop) {
|
|
|
|
|
|
|
|
$this->rc->output->command('plugin.newmail_notifier',
|
|
|
|
$this->rc->output->command('plugin.newmail_notifier',
|
|
|
|
array('basic' => $basic, 'sound' => $sound, 'desktop' => $desktop));
|
|
|
|
array('basic' => $basic, 'sound' => $sound, 'desktop' => $desktop));
|
|
|
|
}
|
|
|
|
}
|
|
|
|