imap: move IdleHandle from session.rs to idle.rs

This commit is contained in:
Alexander Krotov
2020-02-16 04:08:28 +03:00
committed by holger krekel
parent 4c42acc7e1
commit 793ebe1b0f
2 changed files with 25 additions and 22 deletions

View File

@@ -1,6 +1,8 @@
use super::Imap;
use async_imap::extensions::idle::IdleResponse;
use async_imap::extensions::idle::{Handle as ImapIdleHandle, IdleResponse};
use async_native_tls::TlsStream;
use async_std::net::TcpStream;
use async_std::prelude::*;
use async_std::task;
use std::sync::atomic::Ordering;
@@ -9,7 +11,7 @@ use std::time::{Duration, SystemTime};
use crate::context::Context;
use super::select_folder;
use super::session::{IdleHandle, Session};
use super::session::Session;
type Result<T> = std::result::Result<T, Error>;
@@ -37,6 +39,27 @@ impl From<select_folder::Error> for Error {
}
}
#[derive(Debug)]
pub(crate) enum IdleHandle {
Secure(ImapIdleHandle<TlsStream<TcpStream>>),
Insecure(ImapIdleHandle<TcpStream>),
}
impl Session {
pub fn idle(self) -> IdleHandle {
match self {
Session::Secure(i) => {
let h = i.idle();
IdleHandle::Secure(h)
}
Session::Insecure(i) => {
let h = i.idle();
IdleHandle::Insecure(h)
}
}
}
}
impl Imap {
pub fn can_idle(&self) -> bool {
task::block_on(async move { self.config.read().await.can_idle })