4 * New Mail Notifier plugin
6 * Supports two methods of notification:
7 * 1. Basic - focus browser window and change favicon
8 * 2. Sound - play wav file
11 * @author Aleksander Machniak <alec@alec.pl>
14 * Copyright (C) 2011, Kolab Systems AG
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2
18 * as published by the Free Software Foundation.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, write to the Free Software Foundation, Inc.,
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 class newmail_notifier extends rcube_plugin
32 public $task = 'mail|settings';
37 * Plugin initialization
41 $this->rc = rcmail::get_instance();
44 if ($this->rc->task == 'settings') {
45 $this->add_hook('preferences_list', array($this, 'prefs_list'));
46 $this->add_hook('preferences_save', array($this, 'prefs_save'));
48 else { // if ($this->rc->task == 'mail') {
49 $this->add_hook('new_messages', array($this, 'notify'));
50 // add script when not in ajax and not in frame
51 if (is_a($this->rc->output, 'rcube_template') && empty($_REQUEST['_framed'])) {
52 $this->include_script('newmail_notifier.js');
58 * Handler for user preferences form (preferences_list hook)
60 function prefs_list($args)
62 if ($args['section'] != 'mailbox') {
69 // Load localization and configuration
70 $this->add_texts('localization/');
72 // Check that configuration is not disabled
73 $dont_override = (array) $this->rc->config->get('dont_override', array());
74 $basic_override = in_array('newmail_notifier_basic', $dont_override);
75 $sound_override = in_array('newmail_notifier_sound', $dont_override);
77 if (!$basic_override) {
78 $field_id = '_newmail_notifier_basic';
79 $input = new html_checkbox(array('name' => $field_id, 'id' => $field_id, 'value' => 1));
80 $args['blocks']['new_message']['options']['newmail_notifier_basic'] = array(
81 'title' => html::label($field_id, Q($this->gettext('basic'))),
82 'content' => $input->show($this->rc->config->get('newmail_notifier_basic')),
86 if (!$sound_override) {
87 $field_id = '_newmail_notifier_sound';
88 $input = new html_checkbox(array('name' => $field_id, 'id' => $field_id, 'value' => 1));
89 $args['blocks']['new_message']['options']['newmail_notifier_sound'] = array(
90 'title' => html::label($field_id, Q($this->gettext('sound'))),
91 'content' => $input->show($this->rc->config->get('newmail_notifier_sound')),
99 * Handler for user preferences save (preferences_save hook)
101 function prefs_save($args)
103 if ($args['section'] != 'mailbox') {
107 // Load configuration
108 $this->load_config();
110 // Check that configuration is not disabled
111 $dont_override = (array) $this->rc->config->get('dont_override', array());
112 $basic_override = in_array('newmail_notifier_basic', $dont_override);
113 $sound_override = in_array('newmail_notifier_sound', $dont_override);
115 if (!$basic_override) {
116 $key = 'newmail_notifier_basic';
117 $args['prefs'][$key] = get_input_value('_'.$key, RCUBE_INPUT_POST) ? true : false;
119 if (!$sound_override) {
120 $key = 'newmail_notifier_sound';
121 $args['prefs'][$key] = get_input_value('_'.$key, RCUBE_INPUT_POST) ? true : false;
128 * Handler for new message action (new_messages hook)
130 function notify($args)
132 // Load configuration
133 $this->load_config();
135 $basic = $this->rc->config->get('newmail_notifier_basic');
136 $sound = $this->rc->config->get('newmail_notifier_sound');
138 if ($basic || $sound) {
139 $this->rc->output->command('plugin.newmail_notifier',
140 array('basic' => $basic, 'sound' => $sound));