Skip to content

Commit

Permalink
Code review comments
Browse files Browse the repository at this point in the history
 - Show "(2) New Mail!" when there's more than one email
 - Decode from and subject headers

Signed-off-by: Daniel Lo Nigro <[email protected]>
  • Loading branch information
Daniel15 committed Jul 8, 2024
1 parent a4dd7e5 commit ce5a26f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
20 changes: 9 additions & 11 deletions plugins/newmail_notifier/newmail_notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,16 @@ function newmail_notifier_run(prop) {
newmail_notifier_sound();
}
if (prop.desktop) {
var title = prop.from || rcmail.get_label('title', 'newmail_notifier');
var body = prop.subject || rcmail.get_label('body', 'newmail_notifier');

// If there's more than one unread email, show the number of other emails
var otherCount = prop.count - 1;
if (otherCount >= 1) {
title += prop.from
// Have sender name, e.g. "Daniel L +3"
? ' +' +otherCount
// No sender name, e.g. "New Mail! (3)
: '('+otherCount + ')';
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);
}
}
Expand Down
11 changes: 8 additions & 3 deletions plugins/newmail_notifier/newmail_notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,15 @@ public function notify($args)
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_shift($headers);
$headers = array_first($headers);
if ($headers !== null) {
$from = $headers->from;
$subject = $headers->subject;
$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'];
}
}

Expand Down

0 comments on commit ce5a26f

Please sign in to comment.