Roundcube Community Forum

 

New plugin: html5_notifier (desktop notification)

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

Previous topic - Next topic

joksi

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.

joksi

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.

Tayku

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

joksi

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

swsystem

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

joksi

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

swsystem

Quote from: joksi on February 11, 2013, 12:17:42 PM
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);
    }

joksi

Great, that did the trick!

However, the issue with double notifications on the same messages still remains...

tist

#38
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/

darknior

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.

shearer


Tayku

#41
Quote from: tist on February 27, 2013, 12:12:38 PM
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 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.

Tayku

Ok, so I used the changes made by alec in the UNSEEN bug issue, 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.

tist

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/