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) - Improve config compatibility on Windows [#111](https://github.com/soywod/himalaya/pull/111)
- Vim table containing emoji [#122] - Vim table containing emoji [#122]
- IDLE mode after network interruption [#123]
## [0.2.6] - 2021-04-17 ## [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 [#96]: https://github.com/soywod/himalaya/issues/96
[#100]: https://github.com/soywod/himalaya/issues/100 [#100]: https://github.com/soywod/himalaya/issues/100
[#122]: https://github.com/soywod/himalaya/issues/122 [#122]: https://github.com/soywod/himalaya/issues/122
[#123]: https://github.com/soywod/himalaya/issues/123
[#125]: https://github.com/soywod/himalaya/issues/125 [#125]: https://github.com/soywod/himalaya/issues/125
[#126]: https://github.com/soywod/himalaya/issues/126 [#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>> { fn search_new_msgs(&mut self) -> Result<Vec<u32>> {
debug!("[imap::model::search_new_msgs] begin"); let uids: Vec<u32> = self
let seqs: Vec<u32> = self
.sess .sess
.search("NEW") .uid_search("NEW")
.chain_err(|| "Could not search new messages")? .chain_err(|| "Could not search new messages")?
.into_iter() .into_iter()
.collect(); .collect();
debug!( debug!("found {} new messages", uids.len());
"[imap::model::search_new_msgs] found {} new messages", trace!("uids: {:?}", uids);
seqs.len()
);
trace!("[imap::model::search_new_msgs] {:?}", seqs);
Ok(seqs) Ok(uids)
} }
pub fn idle(&mut self, config: &Config, mbox: &str) -> Result<()> { pub fn idle(&mut self, config: &Config, mbox: &str) -> Result<()> {
debug!("begin"); debug!("examine mailbox: {}", mbox);
debug!("examine mailbox {}", mbox);
self.sess self.sess
.examine(mbox) .examine(mbox)
.chain_err(|| format!("Could not examine mailbox `{}`", mbox))?; .chain_err(|| format!("Could not examine mailbox `{}`", mbox))?;
debug!("init message hashset"); debug!("init messages hashset");
let mut msg_set: HashSet<u32> = HashSet::from_iter(self.search_new_msgs()?.iter().cloned()); let mut msgs_set: HashSet<u32> =
trace!("{:?}", msg_set); HashSet::from_iter(self.search_new_msgs()?.iter().cloned());
trace!("messages hashset: {:?}", msgs_set);
loop { loop {
debug!("begin loop"); debug!("begin loop");
self.sess self.sess
.idle() .idle()
.and_then(|idle| idle.wait_keepalive()) .and_then(|mut idle| {
.chain_err(|| "Could not enter in idle mode")?; 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()? .search_new_msgs()?
.into_iter() .into_iter()
.filter(|seq| msg_set.get(&seq).is_none()) .filter(|uid| msgs_set.get(&uid).is_none())
.collect(); .collect();
debug!("found {} new messages not in hashset", new_msgs.len()); debug!("found {} new messages not in hashset", uids.len());
trace!("messages: {:?}", new_msgs); trace!("messages hashet: {:?}", msgs_set);
if !new_msgs.is_empty() { if !uids.is_empty() {
let new_msgs = new_msgs let uids = uids
.iter() .iter()
.map(|seq| seq.to_string()) .map(|uid| uid.to_string())
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(","); .join(",");
let fetches = self let fetches = self
.sess .sess
.fetch(new_msgs, "(ENVELOPE)") .uid_fetch(uids, "(ENVELOPE)")
.chain_err(|| "Cannot fetch new messages enveloppe")?; .chain_err(|| "Could not fetch new messages enveloppe")?;
for fetch in fetches.iter() { for fetch in fetches.iter() {
let msg = Msg::from(fetch); 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)?; config.run_notify_cmd(&msg.subject, &msg.sender)?;
debug!("notify message {}", fetch.message); debug!("notify message: {}", uid);
trace!("message: {:?}", msg); trace!("message: {:?}", msg);
debug!("insert msg {} to hashset", fetch.message); debug!("insert message {} in hashset", uid);
msg_set.insert(fetch.message); msgs_set.insert(uid);
trace!("messages: {:?}", msg_set); trace!("messages hashset: {:?}", msgs_set);
} }
} }

2
wiki

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