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]] [[package]]
name = "buzz" name = "buzz"
version = "1.1.5" version = "1.1.6"
dependencies = [ dependencies = [
"askama_escape 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",

View File

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

View File

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