From 874c5a609f258cfcdefc37aed55278acfef81694 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Tue, 19 Feb 2019 12:18:58 -0500 Subject: [PATCH] Don't re-notify if there's nothing new --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 15 +++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dd060c5..fdace3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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)", diff --git a/Cargo.toml b/Cargo.toml index 1082418..f85851f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/main.rs b/src/main.rs index dcbf323..945e6fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -99,18 +99,17 @@ impl Connection { 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")?