diff --git a/plugins/html5_notifier/.gitignore b/plugins/html5_notifier/.gitignore new file mode 100644 index 00000000..13d7c5db --- /dev/null +++ b/plugins/html5_notifier/.gitignore @@ -0,0 +1 @@ +/config/config.inc.php diff --git a/plugins/html5_notifier/LICENSE b/plugins/html5_notifier/LICENSE new file mode 100644 index 00000000..e13283af --- /dev/null +++ b/plugins/html5_notifier/LICENSE @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2013 Tilman Stremlau + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + diff --git a/plugins/html5_notifier/README.md b/plugins/html5_notifier/README.md new file mode 100644 index 00000000..5dd9000b --- /dev/null +++ b/plugins/html5_notifier/README.md @@ -0,0 +1,8 @@ +![ScreenShot](/screenshot.png) + +HTML5_Notifier is a Roundcube plugin. + +It displays Desktop Notifications like the ones you might know from Google Mail. Just keep Roundcube opened in a (minimized) tab and enjoy getting notifications every time a new mail arrives. + +It just works in modern browsers like Google Chrome, SRWare Iron or Firefox, because "Desktop Notification" is a new feature in HTML5. + diff --git a/plugins/html5_notifier/changelog.txt b/plugins/html5_notifier/changelog.txt new file mode 100644 index 00000000..fdd85f3d --- /dev/null +++ b/plugins/html5_notifier/changelog.txt @@ -0,0 +1,14 @@ +0.2 +- added Listbox to select showing duration +- added color to browser-conf-button + +0.3 +- updated to work with roundcube 0.8 and 0.9 +- added display of mailbox + +0.4 +- updated to work with Firefox and the new Notification API +- fixed UTF-8 issues + +0.5 (thanks to nicolas-joubert!) +- add ability to exclude some directories diff --git a/plugins/html5_notifier/composer.json b/plugins/html5_notifier/composer.json new file mode 100644 index 00000000..a2df0f2a --- /dev/null +++ b/plugins/html5_notifier/composer.json @@ -0,0 +1,31 @@ +{ + "name": "kitist/html5_notifier", + "type": "roundcube-plugin", + "description": "Desktop Notifications for Roundcube", + "keywords": ["notification","desktop","mail"], + "homepage": "https://github.com/kitist/html5_notifier", + "license": "GPL-3.0+", + "authors": [ + { + "name": "Tilman Stremlau", + "email": "tilman@stremlau.net", + "homepage": "http://stremlau.net", + "role": "Developer" + } + ], + "repositories": [ + { + "type": "composer", + "url": "http://plugins.roundcube.net" + } + ], + "require": { + "php": ">=5.3.0", + "roundcube/plugin-installer": ">=0.1.3" + }, + "extra": { + "roundcube": { + "min-version": "0.8.0" + } + } +} diff --git a/plugins/html5_notifier/html5_notifier.js b/plugins/html5_notifier/html5_notifier.js new file mode 100644 index 00000000..5a5f8131 --- /dev/null +++ b/plugins/html5_notifier/html5_notifier.js @@ -0,0 +1,145 @@ +/** + * html5_notifier + * Shows a desktop notification every time a new (recent) mail comes in + * + * @version 0.5.0 - 19.12.2013 + * @author Tilman Stremlau + * @website stremlau.net/html5_notifier + * @licence GNU GPL + * + **/ + +function rcmail_show_notification(message) +{ + if (use_notifications) + { + if ("Notification" in window) { + var notification = new Notification(rcmail.gettext('notification_title', 'html5_notifier').replace('[from]', message.from), { + icon: './plugins/html5_notifier/images/new_mail.png', + body: message.subject + }); + notification.onclick = function() { + if(message.opentype == '1') { + rcmail.open_window('?_task=mail&_action=show&_uid='+message.uid); + } else { + window.open('?_task=mail&_action=show&_extwin=1&_uid='+message.uid); + } + } + if (parseInt(message.duration) > 0) + { + setTimeout(function(){ notification.close(); }, (parseInt(message.duration)*1000)); + } + } + } +} + +function rcmail_browser_notifications() +{ + if ("Notification" in window && Notification.permission) { + if (Notification.permission === "granted") { + rcmail.display_message(rcmail.gettext('ok_notifications', 'html5_notifier'), 'notice'); + } + else { + Notification.requestPermission(rcmail_check_notifications); + } + } + else if (window.webkitNotifications) { + if (window.webkitNotifications.checkPermission() == 0) + { + rcmail.display_message(rcmail.gettext('ok_notifications', 'html5_notifier'), 'notice'); + } + else + { + window.webkitNotifications.requestPermission(rcmail_check_notifications); + } + } + else + { + rcmail.display_message(rcmail.gettext('no_notifications', 'html5_notifier'), 'error'); + } +} + +function rcmail_browser_notifications_test() { + if (use_notifications) + { + rcmail.display_message(rcmail.gettext('check_ok', 'html5_notifier'), 'notice'); + + var message = new Object(); + message.duration = 8; + message.uid = 0; + message.subject = 'It Works!'; + message.from = 'TESTMAN'; + message.opentype = $('select[name=_html5_notifier_popuptype]').val(); + rcmail_show_notification(message); + } + else + { + if ("Notification" in window && Notification.permission) { + if (Notification.permission == 'denied') { + rcmail.display_message(rcmail.gettext('check_fail_blocked', 'html5_notifier'), 'error'); + return false; + } + } + else if (window.webkitNotifications) + { + if (window.webkitNotifications.checkPermission() == 2) + { + rcmail.display_message(rcmail.gettext('check_fail_blocked', 'html5_notifier'), 'error'); + return false; + } + } + rcmail.display_message(rcmail.gettext('check_fail', 'html5_notifier'), 'error'); + } +} + +function rcmail_browser_notifications_colorate() { + if ("Notification" in window && Notification.permission) { + var broco = $('#rcmfd_html5_notifier_browser_conf'); + if (broco) + { + switch (Notification.permission) + { + case 'granted': broco.css('color', 'green'); break; + case 'default': broco.css('color', 'orange'); break; + case 'denied': broco.css('color', 'red'); break; + } + } + } + else if (window.webkitNotifications) + { + var broco = $('#rcmfd_html5_notifier_browser_conf'); + if (broco) + { + switch (window.webkitNotifications.checkPermission()) + { + case 0: broco.css('color', 'green'); break; + case 1: broco.css('color', 'orange'); break; + case 2: broco.css('color', 'red'); break; + } + } + } +} + +var use_notifications = false; + +var rcmail_check_notifications = function(e) +{ + if ("Notification" in window && Notification.permission) { + if (Notification.permission === "granted") { + use_notifications = true; + } + } + else if (window.webkitNotifications) + { + if (window.webkitNotifications.checkPermission() == 0) { + use_notifications = true; + } + } + rcmail_browser_notifications_colorate(); +} + +if (window.rcmail) +{ + rcmail.addEventListener('plugin.showNotification', rcmail_show_notification); + rcmail.addEventListener('init', rcmail_check_notifications); +} diff --git a/plugins/html5_notifier/html5_notifier.php b/plugins/html5_notifier/html5_notifier.php new file mode 100644 index 00000000..7a53bb55 --- /dev/null +++ b/plugins/html5_notifier/html5_notifier.php @@ -0,0 +1,146 @@ + + * @website stremlau.net/html5_notifier + * @licence GNU GPL + * + **/ + +class html5_notifier extends rcube_plugin +{ + public $task = '?(?!login|logout).*'; + + function init() + { + $RCMAIL = rcmail::get_instance(); + + if(file_exists("./plugins/html5_notifier/config/config.inc.php")) + { + $this->load_config('config/config.inc.php'); + } + + $this->add_hook('preferences_list', array($this, 'prefs_list')); + $this->add_hook('preferences_save', array($this, 'prefs_save')); + + if ($RCMAIL->config->get('html5_notifier_duration').'' != '0') + { + $this->add_hook('new_messages', array($this, 'show_notification')); + } + + $this->include_script("html5_notifier.js"); + + if ($RCMAIL->action != 'check-recent') + { + $this->add_texts('localization', array('notification_title', 'ok_notifications', 'no_notifications', 'check_ok', 'check_fail', 'check_fail_blocked')); //PR�ZESIEREN + } + } + + function show_notification($args) + { + $RCMAIL = rcmail::get_instance(); + + //$search = $RCMAIL->config->get('html5_notifier_only_new', false) ?'NEW' : 'RECENT'; + $deleted = $RCMAIL->config->get('skip_deleted') ? 'UNDELETED ' : ''; + $search = $deleted . 'UNSEEN UID ' . $args['diff']['new']; + + $RCMAIL->storage->set_folder($args['mailbox']); + $RCMAIL->storage->search($args['mailbox'], $search, null); + $msgs = (array) $RCMAIL->storage->list_messages($args['mailbox']); + $excluded_directories = preg_split("/(,|;| )+/", $RCMAIL->config->get('html5_notifier_excluded_directories')); + + foreach ($msgs as $msg) { + $from = $msg->get('from'); + $mbox = ''; + switch ($RCMAIL->config->get('html5_notifier_smbox')) { + case 1: $mbox = array_pop(explode('.', str_replace('INBOX.', '', $args['mailbox']))); break; + case 2: $mbox = str_replace('.', '/', str_replace('INBOX.', '', $args['mailbox'])); break; + } + $subject = ((!empty($mbox)) ? rcube_charset::convert($mbox, 'UTF7-IMAP') . ': ' : '') . $msg->get('subject'); + + if(strtolower($_SESSION['username']) == strtolower($RCMAIL->user->data['username']) && !in_array($args['mailbox'], $excluded_directories)) + { + $RCMAIL->output->command("plugin.showNotification", array( + 'duration' => $RCMAIL->config->get('html5_notifier_duration'), + 'opentype' => $RCMAIL->config->get('html5_notifier_popuptype'), + 'subject' => $subject, + 'from' => $from, + 'uid' => $msg->uid.'&_mbox='.$args['mailbox'], + )); + } + } + $RCMAIL->storage->search($args['mailbox'], "ALL", null); + } + + function prefs_list($args) + { + if($args['section'] == 'mailbox') + { + $RCMAIL = rcmail::get_instance(); + + $field_id = 'rcmfd_html5_notifier'; + + $select_duration = new html_select(array('name' => '_html5_notifier_duration', 'id' => $field_id)); + $select_duration->add($this->gettext('off'), '0'); + $times = array('3', '5', '8', '10', '12', '15', '20', '25', '30'); + foreach ($times as $time) + $select_duration->add($time.' '.$this->gettext('seconds'), $time); + $select_duration->add($this->gettext('durable'), '-1'); + + $select_smbox = new html_select(array('name' => '_html5_notifier_smbox', 'id' => $field_id)); + $select_smbox->add($this->gettext('no_mailbox'), '0'); + $select_smbox->add($this->gettext('short_mailbox'), '1'); + $select_smbox->add($this->gettext('full_mailbox'), '2'); + + $content = $select_duration->show($RCMAIL->config->get('html5_notifier_duration').''); + $content .= $select_smbox->show($RCMAIL->config->get('html5_notifier_smbox').''); + $content .= html::a(array('href' => '#', 'id' => 'rcmfd_html5_notifier_browser_conf', 'onclick' => 'rcmail_browser_notifications(); return false;'), $this->gettext('conf_browser')).' '; + $content .= html::a(array('href' => '#', 'onclick' => 'rcmail_browser_notifications_test(); return false;'), $this->gettext('test_browser')); + $args['blocks']['new_message']['options']['html5_notifier'] = array( + 'title' => html::label($field_id, rcube::Q($this->gettext('shownotifies'))), + 'content' => $content, + ); + + $check_only_new = new html_checkbox(array('name' => '_html5_notifier_only_new', 'id' => $field_id . '_only_new', 'value' => 1)); + $content = $check_only_new->show($RCMAIL->config->get('html5_notifier_only_new', false)); + $args['blocks']['new_message']['options']['html5_notifier_only_new'] = array( + 'title' => html::label($field_id, rcube::Q($this->gettext('onlynew'))), + 'content' => $content, + ); + + $input_excluded = new html_inputfield(array('name' => '_html5_notifier_excluded_directories', 'id' => $field_id . '_excluded')); + $args['blocks']['new_message']['options']['html5_notifier_excluded_directories'] = array( + 'title' => html::label($field_id, rcube::Q($this->gettext('excluded_directories'))), + 'content' => $input_excluded->show($RCMAIL->config->get('html5_notifier_excluded_directories').''), + ); + + $select_type = new html_select(array('name' => '_html5_notifier_popuptype', 'id' => $field_id . '_popuptype')); + $select_type->add($this->gettext('new_tab'), '0'); + $select_type->add($this->gettext('new_window'), '1'); + $args['blocks']['new_message']['options']['html5_notifier_popuptype'] = array( + 'title' => html::label($field_id, rcube::Q($this->gettext('notifier_popuptype'))), + 'content' => $select_type->show($RCMAIL->config->get('html5_notifier_popuptype').'') + ); + + $RCMAIL->output->add_script("$(document).ready(function(){ rcmail_browser_notifications_colorate(); });"); + } + return $args; + } + + function prefs_save($args) + { + if($args['section'] == 'mailbox') + { + $args['prefs']['html5_notifier_only_new'] = !empty($_POST['_html5_notifier_only_new']); + $args['prefs']['html5_notifier_duration'] = rcube_utils::get_input_value('_html5_notifier_duration', rcube_utils::INPUT_POST); + $args['prefs']['html5_notifier_smbox'] = rcube_utils::get_input_value('_html5_notifier_smbox', rcube_utils::INPUT_POST); + $args['prefs']['html5_notifier_excluded_directories'] = rcube_utils::get_input_value('_html5_notifier_excluded_directories', rcube_utils::INPUT_POST); + $args['prefs']['html5_notifier_popuptype'] = rcube_utils::get_input_value('_html5_notifier_popuptype', rcube_utils::INPUT_POST); + return $args; + } + } +} +?> diff --git a/plugins/html5_notifier/images/new_mail.png b/plugins/html5_notifier/images/new_mail.png new file mode 100644 index 00000000..e31f2a49 Binary files /dev/null and b/plugins/html5_notifier/images/new_mail.png differ diff --git a/plugins/html5_notifier/localization/cs_CZ.inc b/plugins/html5_notifier/localization/cs_CZ.inc new file mode 100644 index 00000000..99404a95 --- /dev/null +++ b/plugins/html5_notifier/localization/cs_CZ.inc @@ -0,0 +1,26 @@ + diff --git a/plugins/html5_notifier/localization/de_DE.inc b/plugins/html5_notifier/localization/de_DE.inc new file mode 100644 index 00000000..d07d4064 --- /dev/null +++ b/plugins/html5_notifier/localization/de_DE.inc @@ -0,0 +1,26 @@ + diff --git a/plugins/html5_notifier/localization/en_US.inc b/plugins/html5_notifier/localization/en_US.inc new file mode 100644 index 00000000..ce714e3e --- /dev/null +++ b/plugins/html5_notifier/localization/en_US.inc @@ -0,0 +1,26 @@ + diff --git a/plugins/html5_notifier/localization/es_ES.inc b/plugins/html5_notifier/localization/es_ES.inc new file mode 100644 index 00000000..23f6f80a --- /dev/null +++ b/plugins/html5_notifier/localization/es_ES.inc @@ -0,0 +1,23 @@ + diff --git a/plugins/html5_notifier/localization/fr_FR.inc b/plugins/html5_notifier/localization/fr_FR.inc new file mode 100644 index 00000000..31ad4449 --- /dev/null +++ b/plugins/html5_notifier/localization/fr_FR.inc @@ -0,0 +1,22 @@ + diff --git a/plugins/html5_notifier/localization/it_IT.inc b/plugins/html5_notifier/localization/it_IT.inc new file mode 100644 index 00000000..3f135ea1 --- /dev/null +++ b/plugins/html5_notifier/localization/it_IT.inc @@ -0,0 +1,21 @@ + diff --git a/plugins/html5_notifier/localization/ja_JP.inc b/plugins/html5_notifier/localization/ja_JP.inc new file mode 100644 index 00000000..18a8ded2 --- /dev/null +++ b/plugins/html5_notifier/localization/ja_JP.inc @@ -0,0 +1,22 @@ + diff --git a/plugins/html5_notifier/localization/nl_NL.inc b/plugins/html5_notifier/localization/nl_NL.inc new file mode 100644 index 00000000..8e236521 --- /dev/null +++ b/plugins/html5_notifier/localization/nl_NL.inc @@ -0,0 +1,22 @@ + diff --git a/plugins/html5_notifier/localization/pl_PL.inc b/plugins/html5_notifier/localization/pl_PL.inc new file mode 100644 index 00000000..179479c8 --- /dev/null +++ b/plugins/html5_notifier/localization/pl_PL.inc @@ -0,0 +1,25 @@ + diff --git a/plugins/html5_notifier/localization/ru_RU.inc b/plugins/html5_notifier/localization/ru_RU.inc new file mode 100644 index 00000000..69ae721a --- /dev/null +++ b/plugins/html5_notifier/localization/ru_RU.inc @@ -0,0 +1,26 @@ + diff --git a/plugins/html5_notifier/localization/sk_SK.inc b/plugins/html5_notifier/localization/sk_SK.inc new file mode 100644 index 00000000..b1359e43 --- /dev/null +++ b/plugins/html5_notifier/localization/sk_SK.inc @@ -0,0 +1,22 @@ + diff --git a/plugins/html5_notifier/localization/zh_CN.inc b/plugins/html5_notifier/localization/zh_CN.inc new file mode 100644 index 00000000..ef785b00 --- /dev/null +++ b/plugins/html5_notifier/localization/zh_CN.inc @@ -0,0 +1,26 @@ + diff --git a/plugins/html5_notifier/screenshot.png b/plugins/html5_notifier/screenshot.png new file mode 100644 index 00000000..512fa8dd Binary files /dev/null and b/plugins/html5_notifier/screenshot.png differ diff --git a/version.php b/version.php index 763a50cb..0b4f2d08 100644 --- a/version.php +++ b/version.php @@ -2,5 +2,5 @@ return [ 'patch' => '2020.03.13', - 'version' => '0.0.86' + 'version' => '0.0.87' ];