Roundcube Community Forum

 

New plugin: html5_notifier (desktop notification)

Started by tist, August 26, 2011, 10:27:23 AM

Previous topic - Next topic

Tayku

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. Maybe it's related. (Would be a pity and of course a need to improve RC.)

tist

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...

Tayku

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. :)

tist

check_recent.inc
Quote$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

tist

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

Tayku

Quote from: tist;36415This 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.

QuoteOh I hope my english is "understandable" :D
Yes, maybe better than mine (bin ja auch Urdeutsch).^^

corbosman

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.

Tayku

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.

thomasb

Hey Tilman, maybe you could integrate your work into the yet existing newmail_notifier plugin?

joksi

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
                ));
            }
        }

alec

Build-in newmail_notifier plugin supports desktop notifications and is compatible with 0.8.

joksi

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.

joksi

Is $RCMAIL->imap->search_once($args['mailbox'], 'RECENT', true); supported at all in RC 0.8.3?

joksi

Is it possible to use above code, possibly with some modifications, to make it work as intended?

Tayku

@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.