implement imape secure upgrade

This commit is contained in:
dignifiedquire
2020-03-25 15:41:27 +01:00
parent 3871c5a4a0
commit 97951aec15
3 changed files with 15 additions and 11 deletions

2
Cargo.lock generated
View File

@@ -93,7 +93,7 @@ dependencies = [
[[package]]
name = "async-imap"
version = "0.2.0"
source = "git+https://github.com/async-email/async-imap?branch=feat/send#be7b9cace12d0f323ef1e6e0a9fc698f4e26b64d"
source = "git+https://github.com/async-email/async-imap?branch=feat/send#94a48158d6cc622aa0ed99d10b84088e9e53eb2f"
dependencies = [
"async-native-tls 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"async-std 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@@ -120,21 +120,24 @@ impl Client {
pub async fn secure<S: AsRef<str>>(
self,
_domain: S,
_certificate_checks: CertificateChecks,
domain: S,
certificate_checks: CertificateChecks,
) -> ImapResult<Client> {
if self.is_secure {
Ok(self)
} else {
unimplemented!()
// let Client { inner, .. } = self;
// let tls = dc_build_tls(certificate_checks);
// let client_sec = inner.secure(domain, tls).await?;
let Client { mut inner, .. } = self;
let tls = dc_build_tls(certificate_checks);
inner.run_command_and_check_ok("STARTTLS", None).await?;
// Ok(Client {
// is_secure: true,
// inner: client_sec,
// })
let stream = inner.into_inner();
let ssl_stream = tls.connect(domain.as_ref(), stream).await?;
let boxed: Box<dyn SessionStream> = Box::new(ssl_stream);
Ok(Client {
is_secure: true,
inner: ImapClient::new(boxed),
})
}
}
}

View File

@@ -14,6 +14,7 @@ pub(crate) trait SessionStream:
{
}
impl SessionStream for TlsStream<Box<dyn SessionStream>> {}
impl SessionStream for TlsStream<TcpStream> {}
impl SessionStream for TcpStream {}