fix idle mode after network interruption (#123)

This commit is contained in:
Clément DOUIN 2021-04-25 16:20:24 +02:00
parent e2ef1ef586
commit 06f628c33b
No known key found for this signature in database
GPG key ID: 69C9B9CFFDEE2DEF
3 changed files with 34 additions and 33 deletions

View file

@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improve config compatibility on Windows [#111](https://github.com/soywod/himalaya/pull/111)
- Vim table containing emoji [#122]
- IDLE mode after network interruption [#123]
## [0.2.6] - 2021-04-17
@ -203,5 +204,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#96]: https://github.com/soywod/himalaya/issues/96
[#100]: https://github.com/soywod/himalaya/issues/100
[#122]: https://github.com/soywod/himalaya/issues/122
[#123]: https://github.com/soywod/himalaya/issues/123
[#125]: https://github.com/soywod/himalaya/issues/125
[#126]: https://github.com/soywod/himalaya/issues/126

View file

@ -95,71 +95,70 @@ impl<'ic> ImapConnector<'ic> {
}
fn search_new_msgs(&mut self) -> Result<Vec<u32>> {
debug!("[imap::model::search_new_msgs] begin");
let seqs: Vec<u32> = self
let uids: Vec<u32> = self
.sess
.search("NEW")
.uid_search("NEW")
.chain_err(|| "Could not search new messages")?
.into_iter()
.collect();
debug!(
"[imap::model::search_new_msgs] found {} new messages",
seqs.len()
);
trace!("[imap::model::search_new_msgs] {:?}", seqs);
debug!("found {} new messages", uids.len());
trace!("uids: {:?}", uids);
Ok(seqs)
Ok(uids)
}
pub fn idle(&mut self, config: &Config, mbox: &str) -> Result<()> {
debug!("begin");
debug!("examine mailbox {}", mbox);
debug!("examine mailbox: {}", mbox);
self.sess
.examine(mbox)
.chain_err(|| format!("Could not examine mailbox `{}`", mbox))?;
debug!("init message hashset");
let mut msg_set: HashSet<u32> = HashSet::from_iter(self.search_new_msgs()?.iter().cloned());
trace!("{:?}", msg_set);
debug!("init messages hashset");
let mut msgs_set: HashSet<u32> =
HashSet::from_iter(self.search_new_msgs()?.iter().cloned());
trace!("messages hashset: {:?}", msgs_set);
loop {
debug!("begin loop");
self.sess
.idle()
.and_then(|idle| idle.wait_keepalive())
.chain_err(|| "Could not enter in idle mode")?;
.and_then(|mut idle| {
idle.set_keepalive(std::time::Duration::new(300, 0));
idle.wait_keepalive()
})
.chain_err(|| "Could not start the idle mode")?;
let new_msgs: Vec<u32> = self
let uids: Vec<u32> = self
.search_new_msgs()?
.into_iter()
.filter(|seq| msg_set.get(&seq).is_none())
.filter(|uid| msgs_set.get(&uid).is_none())
.collect();
debug!("found {} new messages not in hashset", new_msgs.len());
trace!("messages: {:?}", new_msgs);
debug!("found {} new messages not in hashset", uids.len());
trace!("messages hashet: {:?}", msgs_set);
if !new_msgs.is_empty() {
let new_msgs = new_msgs
if !uids.is_empty() {
let uids = uids
.iter()
.map(|seq| seq.to_string())
.map(|uid| uid.to_string())
.collect::<Vec<_>>()
.join(",");
let fetches = self
.sess
.fetch(new_msgs, "(ENVELOPE)")
.chain_err(|| "Cannot fetch new messages enveloppe")?;
.uid_fetch(uids, "(ENVELOPE)")
.chain_err(|| "Could not fetch new messages enveloppe")?;
for fetch in fetches.iter() {
let msg = Msg::from(fetch);
let uid = fetch.uid.ok_or_else(|| {
format!("Could not retrieve message {}'s UID", fetch.message)
})?;
config.run_notify_cmd(&msg.subject, &msg.sender)?;
debug!("notify message {}", fetch.message);
debug!("notify message: {}", uid);
trace!("message: {:?}", msg);
debug!("insert msg {} to hashset", fetch.message);
msg_set.insert(fetch.message);
trace!("messages: {:?}", msg_set);
debug!("insert message {} in hashset", uid);
msgs_set.insert(uid);
trace!("messages hashset: {:?}", msgs_set);
}
}

2
wiki

@ -1 +1 @@
Subproject commit a022c9580de7f4837cd1e6b028f8da7be96787b8
Subproject commit 0befc18a2857a97d3adf2b11f5c1d6233c9cf8c6