Don't re-notify if there's nothing new

This commit is contained in:
Jon Gjengset 2019-02-19 12:18:58 -05:00
parent 89b98c8299
commit 874c5a609f
No known key found for this signature in database
GPG Key ID: D64AC9D67176DC71
3 changed files with 9 additions and 10 deletions

2
Cargo.lock generated
View File

@ -151,7 +151,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "buzz"
version = "1.1.5"
version = "1.1.6"
dependencies = [
"askama_escape 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -1,6 +1,6 @@
[package]
name = "buzz"
version = "1.1.5"
version = "1.1.6"
description = "A simple system tray application for notifying about unseen e-mail"
readme = "README.md"

View File

@ -99,18 +99,17 @@ impl<T: Read + Write + imap::extensions::idle::SetReadTimeout> Connection<T> {
loop {
// check current state of inbox
let mut num_unseen = 0;
let uids = self.socket.uid_search("UNSEEN 1:*")?;
for &uid in &uids {
if uid > last_notified {
last_notified = uid;
}
num_unseen += 1;
let mut uids = self.socket.uid_search("UNSEEN 1:*")?;
let num_unseen = uids.len();
if uids.iter().all(|&uid| uid <= last_notified) {
// there are no messages we haven't already notified about
uids.clear();
}
let uids: Vec<_> = uids.into_iter().map(|v: u32| format!("{}", v)).collect();
last_notified = std::cmp::max(last_notified, uids.iter().cloned().max().unwrap_or(0));
let mut subjects = BTreeMap::new();
if !uids.is_empty() {
let uids: Vec<_> = uids.into_iter().map(|v: u32| format!("{}", v)).collect();
for msg in self
.socket
.uid_fetch(&uids.join(","), "RFC822.HEADER")?