Don't re-notify if there's nothing new
This commit is contained in:
parent
89b98c8299
commit
874c5a609f
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -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)",
|
||||
|
|
|
@ -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"
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -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")?
|
||||
|
|
Loading…
Reference in New Issue
Block a user