diff --git a/plugins/newmail_notifier/newmail_notifier.js b/plugins/newmail_notifier/newmail_notifier.js index f8e1edd52c0..0b066808a9e 100644 --- a/plugins/newmail_notifier/newmail_notifier.js +++ b/plugins/newmail_notifier/newmail_notifier.js @@ -37,7 +37,17 @@ function newmail_notifier_run(prop) { newmail_notifier_sound(); } if (prop.desktop) { - newmail_notifier_desktop(rcmail.get_label('body', 'newmail_notifier')); + var title; + var body; + if (prop.count === 1) { + title = prop.from || rcmail.get_label('title', 'newmail_notifier'); + body = prop.subject || rcmail.get_label('body', 'newmail_notifier'); + } else { + title = '(' + prop.count + ') ' + rcmail.get_label('title', 'newmail_notifier'); + body = rcmail.get_label('body', 'newmail_notifier'); + } + + newmail_notifier_desktop(title, body); } } @@ -96,11 +106,11 @@ function newmail_notifier_sound() { // Desktop notification // - Require window.Notification API support (Chrome 22+ or Firefox 22+) -function newmail_notifier_desktop(body, disabled_callback) { +function newmail_notifier_desktop(title, body, disabled_callback) { var timeout = rcmail.env.newmail_notifier_timeout || 10, icon = rcmail.assets_path('plugins/newmail_notifier/mail.png'), success_callback = function () { - var popup = new window.Notification(rcmail.get_label('title', 'newmail_notifier'), { + var popup = new window.Notification(title, { dir: 'auto', lang: '', body: body, diff --git a/plugins/newmail_notifier/newmail_notifier.php b/plugins/newmail_notifier/newmail_notifier.php index cccf0fe207f..2f5f3c43d46 100644 --- a/plugins/newmail_notifier/newmail_notifier.php +++ b/plugins/newmail_notifier/newmail_notifier.php @@ -203,12 +203,36 @@ public function notify($args) if ($unseen->count()) { $this->notified = true; + $from = null; + $subject = null; + // Attempt to fetch headers for the latest unseen message + $latest_uid = $unseen->max(); + if ($latest_uid !== null) { + $headers = $storage->fetch_headers($mbox, [$latest_uid]); + // fetch_headers returns an array, but we only care about the first one. + $headers = array_first($headers); + if ($headers !== null) { + $subject = trim( + rcube_mime::decode_header($headers->subject, $headers->charset) + ); + $from_details = array_first( + rcube_mime::decode_address_list($headers->from, 1, true, $headers->charset) + ); + $from = $from_details['name']; + } + } + $this->rc->output->set_env('newmail_notifier_timeout', $this->rc->config->get('newmail_notifier_desktop_timeout')); $this->rc->output->command('plugin.newmail_notifier', [ + // Config 'basic' => $this->opt['basic'], 'sound' => $this->opt['sound'], 'desktop' => $this->opt['desktop'], + // Data + 'from' => $from, + 'subject' => $subject, + 'count' => $unseen->count(), ] ); }