The Handle struct allows a client to block and wait for changes to a remote mailbox using the IMAP IDLE command (RFC 2177).
Important Lifecycle Note:
To prevent being logged off by servers with inactivity timeouts, it is highly recommended to terminate and re-issue the IDLE command at least every 29 minutes. The Handle::wait() method automates this by using a 29-minute timeout.
Usage Workflow:
- Call
init() to send the IDLE command and establish the idle state. - Call
wait() or wait_with_timeout(duration) to start listening for server responses. - When you are finished, call
done() to send the DONE command and recover the underlying Session.
Constraints:
- As long as a
Handle is active, the mailbox cannot be otherwise accessed. wait() and wait_with_timeout() must be called after init().done() must be called after init().
// 1. Initialize the idle connection
handle.init().await?;
// 2. Wait for changes (automatically handles 29-minute re-issue logic)
let (fut, interrupt) = handle.wait();
// In a real application, you would select on 'fut' and your 'interrupt' token
match fut.await? {
IdleResponse::NewData(data) => println!("New data received: {:?}", data),
IdleResponse::Timeout => println!("Idle timed out"),
IdleResponse::ManualInterrupt => println!("Idle interrupted manually"),
}
// 3. Clean up and recover the session
let session = handle.done().await?;