summaryrefslogtreecommitdiff
path: root/plugins/newmail_notifier
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2011-10-19 15:28:11 +0000
committerthomascube <thomas@roundcube.net>2011-10-19 15:28:11 +0000
commit5da48a95224e925f4b070f2581a121516df33829 (patch)
treefadc87888faae54cdb1efc6f7b73fbfce79e0fe7 /plugins/newmail_notifier
parentb03854de3a36a322bf98c733ed9b75d996694e38 (diff)
Copy plugins to release branch
Diffstat (limited to 'plugins/newmail_notifier')
-rw-r--r--plugins/newmail_notifier/config.inc.php.dist12
-rw-r--r--plugins/newmail_notifier/favicon.icobin0 -> 1734 bytes
-rw-r--r--plugins/newmail_notifier/localization/de_CH.inc13
-rw-r--r--plugins/newmail_notifier/localization/de_DE.inc13
-rw-r--r--plugins/newmail_notifier/localization/en_US.inc13
-rw-r--r--plugins/newmail_notifier/localization/pl_PL.inc13
-rw-r--r--plugins/newmail_notifier/localization/pt_BR.inc13
-rw-r--r--plugins/newmail_notifier/localization/ru_RU.inc21
-rw-r--r--plugins/newmail_notifier/mail.pngbin0 -> 1408 bytes
-rw-r--r--plugins/newmail_notifier/newmail_notifier.js120
-rw-r--r--plugins/newmail_notifier/newmail_notifier.php155
-rw-r--r--plugins/newmail_notifier/sound.wavbin0 -> 10444 bytes
12 files changed, 373 insertions, 0 deletions
diff --git a/plugins/newmail_notifier/config.inc.php.dist b/plugins/newmail_notifier/config.inc.php.dist
new file mode 100644
index 000000000..067fe19f1
--- /dev/null
+++ b/plugins/newmail_notifier/config.inc.php.dist
@@ -0,0 +1,12 @@
+<?php
+
+// Enables basic notification
+$rcmail_config['newmail_notifier_basic'] = false;
+
+// Enables sound notification
+$rcmail_config['newmail_notifier_sound'] = false;
+
+// Enables desktop notification
+$rcmail_config['newmail_notifier_desktop'] = false;
+
+?>
diff --git a/plugins/newmail_notifier/favicon.ico b/plugins/newmail_notifier/favicon.ico
new file mode 100644
index 000000000..86e10c1c7
--- /dev/null
+++ b/plugins/newmail_notifier/favicon.ico
Binary files differ
diff --git a/plugins/newmail_notifier/localization/de_CH.inc b/plugins/newmail_notifier/localization/de_CH.inc
new file mode 100644
index 000000000..55cfd7136
--- /dev/null
+++ b/plugins/newmail_notifier/localization/de_CH.inc
@@ -0,0 +1,13 @@
+<?php
+
+$labels['basic'] = 'Anzeige im Browser bei neuer Nachricht';
+$labels['sound'] = 'Akustische Meldung bei neuer Nachricht';
+$labels['desktop'] = 'Desktop-Benachrichtigung bei neuer Nachricht';
+$labels['test'] = 'Test';
+$labels['title'] = 'Neue E-Mail!';
+$labels['body'] = 'Sie haben eine neue Nachricht';
+$labels['testbody'] = 'Dies ist eine Testbenachrichtigung';
+$labels['desktopdisabled'] = 'Desktop-Benachrichtigungen sind deaktiviert.';
+$labels['desktopunsupported'] = 'Ihr Browser unterstützt keine Desktop-Benachrichtigungen.';
+
+?>
diff --git a/plugins/newmail_notifier/localization/de_DE.inc b/plugins/newmail_notifier/localization/de_DE.inc
new file mode 100644
index 000000000..65381ca35
--- /dev/null
+++ b/plugins/newmail_notifier/localization/de_DE.inc
@@ -0,0 +1,13 @@
+<?php
+
+$labels['basic'] = 'Benachrichtigung im Browser bei neuer Nachricht';
+$labels['sound'] = 'Akustische Meldung bei neuer Nachricht';
+$labels['desktop'] = 'Desktop-Benachrichtigung bei neuer Nachricht';
+$labels['test'] = 'Test';
+$labels['title'] = 'Neue E-Mail!';
+$labels['body'] = 'Sie haben eine neue Nachricht';
+$labels['testbody'] = 'Dies ist eine Testbenachrichtigung';
+$labels['desktopdisabled'] = 'Desktop-Benachrichtigungen sind deaktiviert.';
+$labels['desktopunsupported'] = 'Ihr Browser unterstützt keine Desktop-Benachrichtigungen.';
+
+?>
diff --git a/plugins/newmail_notifier/localization/en_US.inc b/plugins/newmail_notifier/localization/en_US.inc
new file mode 100644
index 000000000..3017c43dc
--- /dev/null
+++ b/plugins/newmail_notifier/localization/en_US.inc
@@ -0,0 +1,13 @@
+<?php
+
+$labels['basic'] = 'Display browser notifications on new message';
+$labels['desktop'] = 'Display desktop notifications on new message';
+$labels['sound'] = 'Play the sound on new message';
+$labels['test'] = 'Test';
+$labels['title'] = 'New Email!';
+$labels['body'] = 'You\'ve received a new message.';
+$labels['testbody'] = 'This is a test notification.';
+$labels['desktopdisabled'] = 'Desktop notifications are disabled in your browser.';
+$labels['desktopunsupported'] = 'Your browser does not support desktop notifications.';
+
+?>
diff --git a/plugins/newmail_notifier/localization/pl_PL.inc b/plugins/newmail_notifier/localization/pl_PL.inc
new file mode 100644
index 000000000..d95e658af
--- /dev/null
+++ b/plugins/newmail_notifier/localization/pl_PL.inc
@@ -0,0 +1,13 @@
+<?php
+
+$labels['basic'] = 'Wyświetlaj powiadomienia o nadejściu nowej wiadomości w przeglądarce';
+$labels['sound'] = 'Odtwarzaj dźwięk o nadejściu nowej wiadomości';
+$labels['desktop'] = 'Wyświetlaj powiadomienia o nadejściu nowej wiadomości na pulpicie';
+$labels['test'] = 'Testuj powiadomienie';
+$labels['title'] = 'Nowa wiadomość!';
+$labels['body'] = 'Nadeszła nowa wiadomość.';
+$labels['testbody'] = 'To jest testowe powiadomienie.';
+$labels['desktopdisabled'] = 'Powiadomienia na pulpicie zostały zablokowane w twojej przeglądarce.';
+$labels['desktopunsupported'] = 'Twoja przeglądarka nie obsługuje powiadomień na pulpicie.';
+
+?>
diff --git a/plugins/newmail_notifier/localization/pt_BR.inc b/plugins/newmail_notifier/localization/pt_BR.inc
new file mode 100644
index 000000000..66f8e936e
--- /dev/null
+++ b/plugins/newmail_notifier/localization/pt_BR.inc
@@ -0,0 +1,13 @@
+<?php
+
+$labels['basic'] = 'Exibir notificação quando uma nova mensagem chegar';
+$labels['desktop'] = 'Exibir notificação no desktop quando uma nova mensagem chegar';
+$labels['sound'] = 'Alerta sonoro quando uma nova mensagem chegar';
+$labels['test'] = 'Testar';
+$labels['title'] = 'Novo Email!';
+$labels['body'] = 'Você recebeu uma nova mensagem.';
+$labels['testbody'] = 'Essa é uma notificação de teste.';
+$labels['desktopdisabled'] = 'As notificações no desktop estão desabilitadas no seu navegador.';
+$labels['desktopunsupported'] = 'Seu navegador não suporta notificações no desktop';
+
+?>
diff --git a/plugins/newmail_notifier/localization/ru_RU.inc b/plugins/newmail_notifier/localization/ru_RU.inc
new file mode 100644
index 000000000..65abb7437
--- /dev/null
+++ b/plugins/newmail_notifier/localization/ru_RU.inc
@@ -0,0 +1,21 @@
+<?php
+
+/*
++-----------------------------------------------------------------------+
+| language/ru_RU/labels.inc |
+| |
+| Language file of the RoundCube Webmail client |
+| Copyright (C) 2008-2011, RoundQube Dev. - Switzerland |
+| Licensed under the GNU GPL |
+| |
++-----------------------------------------------------------------------+
+| Author: Doubrovine S. |
++-----------------------------------------------------------------------+
+
+*/
+
+$labels = array();
+$labels['basic'] = 'Визуальное уведомление по приходу нового сообщения';
+$labels['sound'] = 'Звуковое уведомление по приходу нового сообщения';
+
+?> \ No newline at end of file
diff --git a/plugins/newmail_notifier/mail.png b/plugins/newmail_notifier/mail.png
new file mode 100644
index 000000000..79f3a5311
--- /dev/null
+++ b/plugins/newmail_notifier/mail.png
Binary files differ
diff --git a/plugins/newmail_notifier/newmail_notifier.js b/plugins/newmail_notifier/newmail_notifier.js
new file mode 100644
index 000000000..16e3edd42
--- /dev/null
+++ b/plugins/newmail_notifier/newmail_notifier.js
@@ -0,0 +1,120 @@
+/**
+ * New Mail Notifier plugin script
+ *
+ * @version 0.3
+ * @author Aleksander Machniak <alec@alec.pl>
+ */
+
+if (window.rcmail && rcmail.env.task == 'mail') {
+ rcmail.addEventListener('plugin.newmail_notifier', newmail_notifier_run);
+ rcmail.addEventListener('actionbefore', newmail_notifier_stop);
+ rcmail.addEventListener('init', function() {
+ // bind to messages list select event, so favicon will be reverted on message preview too
+ if (rcmail.message_list)
+ rcmail.message_list.addEventListener('select', newmail_notifier_stop);
+ });
+}
+
+// Executes notification methods
+function newmail_notifier_run(prop)
+{
+ if (prop.basic)
+ newmail_notifier_basic();
+ if (prop.sound)
+ newmail_notifier_sound();
+ if (prop.desktop)
+ newmail_notifier_desktop(rcmail.gettext('body', 'newmail_notifier'));
+}
+
+// Stops notification
+function newmail_notifier_stop(prop)
+{
+ // revert original favicon
+ if (rcmail.env.favicon_href && (!prop || prop.action != 'check-recent')) {
+ $('<link rel="shortcut icon" href="'+rcmail.env.favicon_href+'"/>').replaceAll('link[rel="shortcut icon"]');
+ rcmail.env.favicon_href = null;
+ }
+}
+
+// Basic notification: window.focus and favicon change
+function newmail_notifier_basic()
+{
+ var w = rcmail.is_framed() ? window.parent : window;
+
+ w.focus();
+
+ // we cannot simply change a href attribute, we must to replace the link element (at least in FF)
+ var link = $('<link rel="shortcut icon" href="plugins/newmail_notifier/favicon.ico"/>'),
+ oldlink = $('link[rel="shortcut icon"]', w.document);
+
+ rcmail.env.favicon_href = oldlink.attr('href');
+ link.replaceAll(oldlink);
+}
+
+// Sound notification
+function newmail_notifier_sound()
+{
+ var elem, src = 'plugins/newmail_notifier/sound.wav';
+
+ // HTML5
+ try {
+ elem = $('<audio src="' + src + '" />');
+ elem.get(0).play();
+ }
+ // old method
+ catch (e) {
+ elem = $('<embed id="sound" src="' + src + '" hidden=true autostart=true loop=false />');
+ elem.appendTo($('body'));
+ window.setTimeout("$('#sound').remove()", 5000);
+ }
+}
+
+// Desktop notification (need Chrome or Firefox with a plugin)
+function newmail_notifier_desktop(body)
+{
+ var dn = window.webkitNotifications;
+
+ if (dn && !dn.checkPermission()) {
+ if (rcmail.newmail_popup)
+ rcmail.newmail_popup.cancel();
+ var popup = window.webkitNotifications.createNotification('plugins/newmail_notifier/mail.png',
+ rcmail.gettext('title', 'newmail_notifier'), body);
+ popup.onclick = function() {
+ this.cancel();
+ }
+ popup.show();
+ setTimeout(function() { popup.cancel(); }, 10000); // close after 10 seconds
+ rcmail.newmail_popup = popup;
+ return true;
+ }
+
+ return false;
+}
+
+function newmail_notifier_test_desktop()
+{
+ var dn = window.webkitNotifications,
+ txt = rcmail.gettext('testbody', 'newmail_notifier');
+
+ if (dn) {
+ if (!dn.checkPermission())
+ newmail_notifier_desktop(txt);
+ else
+ dn.requestPermission(function() {
+ if (!newmail_notifier_desktop(txt))
+ rcmail.display_message(rcmail.gettext('desktopdisabled', 'newmail_notifier'), 'error');
+ });
+ }
+ else
+ rcmail.display_message(rcmail.gettext('desktopunsupported', 'newmail_notifier'), 'error');
+}
+
+function newmail_notifier_test_basic()
+{
+ newmail_notifier_basic();
+}
+
+function newmail_notifier_test_sound()
+{
+ newmail_notifier_sound();
+}
diff --git a/plugins/newmail_notifier/newmail_notifier.php b/plugins/newmail_notifier/newmail_notifier.php
new file mode 100644
index 000000000..1f1df9e75
--- /dev/null
+++ b/plugins/newmail_notifier/newmail_notifier.php
@@ -0,0 +1,155 @@
+<?php
+
+/**
+ * New Mail Notifier plugin
+ *
+ * Supports two methods of notification:
+ * 1. Basic - focus browser window and change favicon
+ * 2. Sound - play wav file
+ * 3. Desktop - display desktop notification (using webkitNotifications feature,
+ * supported by Chrome and Firefox with 'HTML5 Notifications' plugin)
+ *
+ * @version 0.3
+ * @author Aleksander Machniak <alec@alec.pl>
+ *
+ *
+ * Copyright (C) 2011, Kolab Systems AG
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+class newmail_notifier extends rcube_plugin
+{
+ public $task = 'mail|settings';
+
+ private $rc;
+ private $notified;
+
+ /**
+ * Plugin initialization
+ */
+ function init()
+ {
+ $this->rc = rcmail::get_instance();
+
+ // Preferences hooks
+ if ($this->rc->task == 'settings') {
+ $this->add_hook('preferences_list', array($this, 'prefs_list'));
+ $this->add_hook('preferences_save', array($this, 'prefs_save'));
+ }
+ else { // if ($this->rc->task == 'mail') {
+ $this->add_hook('new_messages', array($this, 'notify'));
+ // add script when not in ajax and not in frame
+ if (is_a($this->rc->output, 'rcube_template') && empty($_REQUEST['_framed'])) {
+ $this->add_texts('localization/');
+ $this->rc->output->add_label('newmail_notifier.title', 'newmail_notifier.body');
+ $this->include_script('newmail_notifier.js');
+ }
+ }
+ }
+
+ /**
+ * Handler for user preferences form (preferences_list hook)
+ */
+ function prefs_list($args)
+ {
+ if ($args['section'] != 'mailbox') {
+ return $args;
+ }
+
+ // Load configuration
+ $this->load_config();
+
+ // Load localization and configuration
+ $this->add_texts('localization/');
+
+ if (!empty($_REQUEST['_framed'])) {
+ $this->rc->output->add_label('newmail_notifier.title', 'newmail_notifier.testbody',
+ 'newmail_notifier.desktopunsupported', 'newmail_notifier.desktopenabled', 'newmail_notifier.desktopdisabled');
+ $this->include_script('newmail_notifier.js');
+ }
+
+ // Check that configuration is not disabled
+ $dont_override = (array) $this->rc->config->get('dont_override', array());
+
+ foreach (array('basic', 'desktop', 'sound') as $type) {
+ $key = 'newmail_notifier_' . $type;
+ if (!in_array($key, $dont_override)) {
+ $field_id = '_' . $key;
+ $input = new html_checkbox(array('name' => $field_id, 'id' => $field_id, 'value' => 1));
+ $content = $input->show($this->rc->config->get($key))
+ . ' ' . html::a(array('href' => '#', 'onclick' => 'newmail_notifier_test_'.$type.'()'),
+ $this->gettext('test'));
+
+ $args['blocks']['new_message']['options'][$key] = array(
+ 'title' => html::label($field_id, Q($this->gettext($type))),
+ 'content' => $content
+ );
+ }
+ }
+
+ return $args;
+ }
+
+ /**
+ * Handler for user preferences save (preferences_save hook)
+ */
+ function prefs_save($args)
+ {
+ if ($args['section'] != 'mailbox') {
+ return $args;
+ }
+
+ // Load configuration
+ $this->load_config();
+
+ // Check that configuration is not disabled
+ $dont_override = (array) $this->rc->config->get('dont_override', array());
+
+ foreach (array('basic', 'desktop', 'sound') as $type) {
+ $key = 'newmail_notifier_' . $type;
+ if (!in_array($key, $dont_override)) {
+ $args['prefs'][$key] = get_input_value('_'.$key, RCUBE_INPUT_POST) ? true : false;
+ }
+ }
+
+ return $args;
+ }
+
+ /**
+ * Handler for new message action (new_messages hook)
+ */
+ function notify($args)
+ {
+ if ($this->notified) {
+ return $args;
+ }
+
+ $this->notified = true;
+
+ // Load configuration
+ $this->load_config();
+
+ $basic = $this->rc->config->get('newmail_notifier_basic');
+ $sound = $this->rc->config->get('newmail_notifier_sound');
+ $desktop = $this->rc->config->get('newmail_notifier_desktop');
+
+ if ($basic || $sound || $desktop) {
+ $this->rc->output->command('plugin.newmail_notifier',
+ array('basic' => $basic, 'sound' => $sound, 'desktop' => $desktop));
+ }
+
+ return $args;
+ }
+}
diff --git a/plugins/newmail_notifier/sound.wav b/plugins/newmail_notifier/sound.wav
new file mode 100644
index 000000000..72d3dd857
--- /dev/null
+++ b/plugins/newmail_notifier/sound.wav
Binary files differ