-
-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Description
An email client will most of the time use an IDLE loop to get the new messages/deleted messages events in real time.
What would be the best way to do this with async-imap as the session is borrowed by idle?
I have stored a session in a struct:
pub struct ImapClient {
session: async_imap::Session<async_native_tls::TlsStream<TcpStream>>
}That session is initialized with a try_new method.
Then I have a method that makes an idle wait. It returns the number of fetched messages.
pub async fn wait_for_new_messages(&mut self) -> Result<usize> {
self.session.select("INBOX").await.unwrap();
let mut idle = self.session.idle(); // boom: self.session moved due to this method call
idle.init().await?
// code for idle/fetch EXISTS
}cf this file
The caller is responsible to loop like:
loop {
match imap_client.wait_for_new_messages().await {
Ok(nb) => debug!("received {} messages", nb),
Err(err) => error!("{:?}", err)
}
}I understand that the session moves to the idle Handler, to return it when idle is done.
How could I use the session instance with idle?
(@hpk42 I will push a doc PR with my findings, I just want to reach a working example)
Thank you for your answers.
What I tried:
- encapsulate idle handler in the struct ImapClient but when creating the session, same issue is happening with self
- encapsulate the
Clientand recreating a session each time but that means re-authenticate at each idle loop step thus having an unnecessary network overhead - encapsulate the Client and making the idle loop inside the ImapClient. But same issue happens with the borrow in the loop
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels