Roundcube Community Forum
Third Party Contributions => API Based Plugins => Topic started by: tist on August 26, 2011, 10:27:23 AM
-
Hi there :D
The last two days I developed a new plugin for roundcube. It displays desktop notifications like the ones you might know from Google Mail. Just keep RC open in a (minimized) tab and enjoy getting notifications every time a new mail arrives.
http://stremlau.net/html5_notifier/
Here is a screenshot:
(http://stremlau.net/html5_notifier/screenshot1.png)
Of course it just work in Google Chrome or SRWare Iron, because it's a new feature in HTML5.
Sorry for my bad english, I'm not a native speaker. If someone post a corrected version of the english language-files, I would be pleased.
Regards,
Tilman Stremlau
-
Great idea! I'll try it out with my next RC install, the english language files look good to me.
-
I'd definitely consider this if it supported more browsers. Or to be more precise, if more browsers had good HTML5 support.
-
Hello! This looks like a very convenient plugin. With a popup window, one of the last advantages of Thunderbird (or any desktop mailer) vanishes. And it even looks good.
But unfortunately I can’t get it running. I installed the plugin and activated in the settings. I whitelisted it in SRWare Iron and clicked on test: the test popup works. But I do not get any notification for new mails. What can I do? I also allowed popups for every website but that did not solve it.
Though it is a very nice plugin. I was just on the search for something that gives me a notification, and two days ago you published this. Good timing! :)
-
Hello!
I use the Plugin hook "new messages" like the sound_notifier Module. This hook is just fired, if the mail arrives in the opened mailbox. So it is necessary to have the inbox opened.
On my opinion this hook should be fired every time you get a mail in any mailbox, because it doesn't make any sense this way. I hope they will change it there is no other possible hook.
Thank you for your good feedback! :D
-
Hello!
I use the Plugin hook "new messages" like the sound_notifier Module does. This hook is just fired if the mail arrives in the opened mailbox. So it is necessary to have the inbox opened.
On my opinion this hook should be fired every time you get a mail in any mailbox, because it doesn't make any sense this way. I hope they will change it, there is no other possible hook. Another way is to send an extra request to the server, but this would be my last choice :-/
Thank you for your good feedback! :D
-
I had the inbox open, the window was just minimized. I did not get a notification, no matter if the browser window is active or not. How can I test that the plugin “fires”? Could you create a kind of debug version which just puts a message alert or changes the tab title?
Does it work with Roundcube 0.5.4?
-
Double post – please delete
-
Maybe you have to set "Check all folders for new messages" to true.
You could debug it by adding "alert('debug');" in the html5_notifier.js after
"function rcmail_show_notification(message)
{"
then a normal Popup should open if the Plugin is fired :D
Could anybody other please test the plugin?
Regards,
Tilman
-
The checkbox was already checked. But I think this is only important if you use mail filters which put the new mails in other folders than inbox. I have such filters, but my test mails were always put in inbox.
I added the alert function to rcmail_show_notification() but it wasn’t called. It’s not fired. :( Perhaps something’s not right in the show_notification function in html5_notifier.php, something that does not work in my configuration.
-
Try adding
"$RCMAIL->output->command("plugin.showNotification", array(
'subject' => "It's a test...",
'from' => "Peter",
'uid' => "10"
));"
after "$RCMAIL = ..." in show_notification() in html5_notifier.php
I don't know how RC manage it, but I read that the RECENT flag doesn't work correct with some IMAP Clients. I could implement a notification showing "You have X new messages" instead of the messages. This sould work, because RC has a special function for this.
Regards,
Tilman
-
So, now that works. :) The notification is fired (with both the debug alert from above and the popup), displaying the test message.
Is it possible not to check the recent flag but to list all unread messages? Or is there another possibility to get the content of the new messages? I mean, if RC has a special function for the number of (really) new messages, why not give the detail information about them?
(But for now, a popup with “x new messages” is better than nothing …)
-
Ok... to list all unread messages is possible, but I don't know if this would be reasonable... RC compares the higest (newest) IDs of the messages with the last call and get the number of the recent mails this way. Today I will check, if it's possible to use this to show these messages...
-
@tist:
It works! I’m so sorry, I tested the wrong way. :(
I always send a mail from me to me, but in that case, my provider may not have set the recent flag. Now today there was an incoming mail with the popup. Then I tested by sending me a mail from another provider. Works like a charm. :) I’d like to thank you for your patience and tries to find another way.
Now I have to remove the test popup.^^
Is there a way to raise the duration until the popup vanishes? I had a look in Iron’s settings, but could not find one.
Edit: I had a look in html5_notifier.js. There is the popup time. Very nice.
-
Thats good :D
What a duration do you prefer? I add to my todo-list to add an option for the duration in the settings :D
-
No hurry, I can manage to change a number in source code myself. :cool:
But what I just discovered, the notification will only apply for new mails in inbox. I have a presorting on my mail server, so new mails will arrive already in appropriate folders (as roundcube does not have sorting function itself), but then the notification is not fired. There is also a problem with the title bar mail count described here (http://www.roundcubeforum.net/5-release-support/16-requests/8708-count-unread-messages-title.html). Maybe it’s related. (Would be a pity and of course a need to improve RC.)
-
Thats what I said in #5 the "new_messages" Hook is just fired, if you have opened the right mailbox... I think it's a bug in RC, because it doesn't make any sense...
-
Yes you said this, but generally it won’t work with other folders than inbox. Even if I have opend the folder “private/family” and a mail comes in there, I won’t get no notification. Same as I won’t get a title bar change to “(1) Roundcube”.
I think the failure lies in the new messages check itself: only new mails in inbox are counted, only those are notified by hook. That’s a pity and discourages pre-sorting of mails.
For now I do not sort mails that could be important. I have to sort by hand, but at least I have a nice notification. :)
-
check_recent.inc
$check_all = !empty($_GET['_refresh']) || (bool)$RCMAIL->config->get('check_all_folders');
// list of folders to check
if ($check_all) {
$a_mailboxes = $IMAP->list_mailboxes();
}
else {
$a_mailboxes = (array) $current;
if ($a_mailboxes[0] != 'INBOX')
$a_mailboxes[] = 'INBOX';
}
// check recent/unseen counts
foreach ($a_mailboxes as $mbox_name) {
if ($mbox_name == $current && ($status = $IMAP->mailbox_status($mbox_name))) {
This is the important code... if check_all_folders is set to true AND "private/family" is your current mailbox, it should work... but as I mentioned, in my opinion, the check ""mbox_name == $current" should be later and the hook should be fired by any mailbox (a current-check could be done - if necessary - in the plugin itself).
Oh I hope my english is "understandable" :D
Regards,
Tilman Stremlau
-
New Version 0.2 available (download-link in first post)
changes:
- added Listbox to select showing duration
- added color to browser-conf-button
Have Fun :P
-
This is the important code... if check_all_folders is set to true AND "private/family" is your current mailbox, it should work... but as I mentioned, in my opinion, the check ""mbox_name == $current" should be later and the hook should be fired by any mailbox (a current-check could be done - if necessary - in the plugin itself).
That seems reasonable. I’m not firm in PHP, JavaScript or Roundcube. If you have some solution or hack, I can patch my version of Roundcube, but I’m not able to play with the code.
Oh I hope my english is "understandable" :D
Yes, maybe better than mine (bin ja auch Urdeutsch).^^
-
Checking all mailboxes for unseen messages is probably unreasonable. You can have hundreds of folders. Checking them all for unseen messages is probably not going to work well.
-
So what do I do if I want automatically sorted mails? Roundcube does not offer such a possibility, so I’m using procmailrc offered by my mail provider. Roundcube also does not offer to check some preselected folders the same way like inbox. Thunderbird does have such an option: I will be notified by popup if there’s a new mail in any of those folders.
-
Hey Tilman, maybe you could integrate your work into the yet existing newmail_notifier plugin?
-
I have problems with this plugin, I have checked and my server do support the RECENT-flag but still no notifications are shown.
Maybe its a cmpatibility issue with Roundcube 0.8+?
It seems this part is the problem:
(array) $uids = $RCMAIL->imap->search_once($args['mailbox'], 'RECENT', true);
foreach($uids as $uid) {
$message = new rcube_message($uid);
$from = $message->sender['name'] ? $message->sender['name'] : $message->sender['mailto'];
$subject = $message->subject;
if(strtolower($_SESSION['username']) == strtolower($RCMAIL->user->data['username']))
{
$RCMAIL->output->command("plugin.showNotification", array(
'duration' => $RCMAIL->config->get('html5_notifier_duration'),
'subject' => $subject,
'from' => $from,
'uid' => $uid
));
}
}
-
Build-in newmail_notifier plugin supports desktop notifications and is compatible with 0.8.
-
Yes, I know, however that version just notifies that there is new mail, but this one does like Gmail with info in the notifications who sent the mail and the subject. I think that looks better and more informative, so that's why I would like to use this one but it seems that the code above doesnt get the e-mails with the RECENT-flag.
-
Is $RCMAIL->imap->search_once($args['mailbox'], 'RECENT', true); supported at all in RC 0.8.3?
-
Is it possible to use above code, possibly with some modifications, to make it work as intended?
-
@joksi:
Using your idea, I have borrowed the responsible code for including sender/subject into the notification from the HTML5 notifier plugin. Then I inserted it into newmail_notifier. Maybe it won’t work for you because I use Roundcube 0.7.2, but the HTML5 notifier did not work either since the upgrade from 0.7 (or 0.7.1) …
The attached modified newmail_notifier does the same as html5_notifier before. The attached version has the following enhancements compared to the current newmail_notifier (from Roundcube 0.7.2, but it’s the same in 0.8.4):
- Set duration of desktop notification
- Clicking on the notification opens the new mail in a new window
- display of mail sender in notification title
- display of subject in notification message
- display of all new messages as separate notifications (up to three in my Chrome) – useful if you get more than one message since the last check.
-
Hi!
Thanks for your help, but it looks like it doesnt work.
I minimized the window but no notification shows when receiving a new mail?
I have of course enabled it in the settings.
-
It seems the same part of the code is the problem.
(array) $uids = $this->rc->imap->search_once($args['mailbox'], 'RECENT', true);
foreach($uids as $uid) {
$message = new rcube_message($uid);
$from = $message->sender['name'] ? $message->sender['name'] : $message->sender['mailto'];
$subject = $message->subject;
if(strtolower($_SESSION['username']) == strtolower($this->rc->user->data['username']))
{
if ($basic || $sound || $desktop) {
$this->rc->output->command('plugin.newmail_notifier',
array('basic' => $basic, 'sound' => $sound, 'desktop' => $desktop,
'duration' => $this->rc->config->get('newmail_notifier_duration'),
'from' => $from,
'subject' => $subject,
'uid' => $uid));
}
}
}
The foreach doesnt run at all.
-
I’m sure there is another possibility to get the information … but I’m no expert (my modified newmail_notify is try/error and merging from both plugins).
-
Alec who wrote in this post earlier is a Roundcube developer, so I'm hoping he will have the time to answer.
I'm sure the problem lies in this specific row
$uids = $this->rc->imap->search_once($args['mailbox'], 'RECENT', true);
It seems it doesnt get the what it's supposed to...
-
After a bit of trying to figure out what was going on with the search_once I switched my code over to doing a search and generating an array of uids to minimise code changes in the future.
Replacing
(array) $uids = $RCMAIL->imap->search_once($args['mailbox'], 'RECENT', true);
With
$msgs = array();
$uids = array();
$RCMAIL->storage->set_mailbox($args['mailbox']);
$RCMAIL->storage->search($args['mailbox'], "RECENT", null);
$msgs = $RCMAIL->storage->list_headers($args['mailbox']);
foreach ($msgs as $msg) {
$uids[]=$msg->uid;
}
Seems to have this working for me on roundcube version 0.8.1, I've not checked other versions.
EDIT
swapped from $RCMAIL->imap to $RCMAIL->storage as it would change the mailbox to only display the notified messages.
-
Hi
Works almost great, although I have 0.8.4 and I have tried with both ->imap and ->storage, in both cases when there is a new e-mail and you go back to Roundcube it have updated the listview only showing the new e-mail in the inbox. Can this be changed somehow?
Also it seems not really stable, sometimes the same message gets notified two times in a row (even if it has been already marked as read).
-
Hi
Works almost great, although I have 0.8.4 and I have tried with both ->imap and ->storage, in both cases when there is a new e-mail and you go back to Roundcube it have updated the listview only showing the new e-mail in the inbox. Can this be changed somehow?
Also it seems not really stable, sometimes the same message gets notified two times in a row (even if it has been already marked as read).
This is due to the search being set to RECENT, changing to to ALL at the end of the function seems to fix it.
Put the below as the last thing the show_notification function does.
$RCMAIL->storage->search($args['mailbox'], "ALL", null);
Here's my full show_notification function.
function show_notification($args)
{
$RCMAIL = rcmail::get_instance();
$msgs = array();
$uids = array();
$RCMAIL->storage->set_mailbox($args['mailbox']);
$RCMAIL->storage->search($args['mailbox'], "RECENT", null);
$msgs = $RCMAIL->storage->list_headers($args['mailbox']);
foreach ($msgs as $msg) {
$uids[]=$msg->uid;
}
foreach($uids as $uid) {
$message = new rcube_message($uid);
$from = $message->sender['name'] ? $message->sender['name'] : $message->sender['mailto'];
$subject = str_replace(".", ">", $args['mailbox']).": ".$message->subject;
if(strtolower($_SESSION['username']) == strtolower($RCMAIL->user->data['username']))
{
$RCMAIL->output->command("plugin.showNotification", array(
'duration' => $RCMAIL->config->get('html5_notifier_duration'),
'subject' => $subject,
'from' => $from,
'uid' => $uid."&_mbox=".$args['mailbox'],
));
}
}
$RCMAIL->storage->search($args['mailbox'], "ALL", null);
}
-
Great, that did the trick!
However, the issue with double notifications on the same messages still remains...
-
Hi there,
I updated the code and built in the display of the mailbox name (like swsystem did) :D
Maybe it's a problem of roundcube or imap, but the storage->search just works with all mailboxes except INBOX, does anybody has an idea? Otherwise I will post it in the developer-mailing-list.
http://www.stremlau.net/html5_notifier/
-
Thanks a lot for this update :D
Now it works fine for me ...
I can see the Desktop notification ;)
Here the translation of the end of the file :
$labels['no_mailbox'] = 'ne pas montrer le message';
$labels['short_mailbox'] = 'montrer un apperçu du message';
$labels['full_mailbox'] = 'montrer tout le message';
Think to register the file in UTF-8.
-
how do i activate this ?
-
Hi there,
I updated the code and built in the display of the mailbox name (like swsystem did) :D
Maybe it's a problem of roundcube or imap, but the storage->search just works with all mailboxes except INBOX, does anybody has an idea? Otherwise I will post it in the developer-mailing-list.
Hm, since updating to version 0.3 I experienced two problems. The first is that the subject is not correctly encoding. It seems that it just prints the raw string from the subject, something like “=?UTF-8?Q?Test1_mit_B=C3=A4umen=2E?=” (should be “Test1 mit Bäumen.”). Is there a way to encode properly before returning the string?
The second problem is that the notifier notifies about any mail that is moved to another folder. Every time I move a mail, I got a notification. After sending an e-mail, I got a notification (because it’s moved automatically from Drafts to Sent). That’s not the intention of the plugin …
Could you modify the plugin such that the notification only triggers for unread mails? That would be perfect I think.
Edit:
I tested the provided newmail_notifier plugin. Unfortunately it shows the same behaviour (concerning the second problem). So the notification method in Roundcube 0.9 is broken? Hm, have to search the bugtracker for it. (Edit2:) Found it (http://trac.roundcube.net/ticket/1488965) Seems like it will find its way into 0.9-final. Unfortunately it does not work. With the patch I’m getting no notifications at all (using newmail_notifier). Damn.
-
Ok, so I used the changes made by alec in the UNSEEN bug issue (http://trac.roundcube.net/ticket/1488965), that works wonderful. But it’s only for RC1.0, though I don’t have any other problems. (Maybe lefoyers initially provided patch would work on RC0.9.)
Now I have merged the HTML5 notifier functionality into the newmail notifier (for RC1.0 of course). That means: information about sender and subject, multiple popups, configurable time for displaying the popup. Also I added a proper MIME decoding. Now everything is fine. If someone is interested in the modified version, let me know.
-
New Version available
- added support for Firefox and other Browsers using the new Notification API
- UFT8 issues fixed
Download at: http://stremlau.net/html5_notifier/