duesee / imap-next

Apache License 2.0
11 stars 3 forks source link

Support for different runtimes and TLS libraries #169

Open jakoschiko opened 6 months ago

jakoschiko commented 6 months ago

With the introduction of sans I/O (see #158) we are now able to support different runtimes (std, tokio, async-std) and TLS libraries (native TLS, rustls) easily. Currently we only support tokio and rustls by providing the type stream::Stream. In the future we might add more similar implementations. But this raises couple of questions:

See this discussion.

duesee commented 6 months ago

We have ...

TLS backends are mostly implemented using traits from the runtime, e.g., std::io::{Read,Write}, tokio::Async{Read,Write} or async_std::Async{Read,Write}.

This means that we probably want to write sans I/O adapters that use a runtimes read/write traits (to support most tls backends).

More questions:

soywod commented 1 week ago

I wanted to share a bit what I've been attempted so far with pimalaya/core/start-tls:

Basically, the right .prepared() fn is inferred (either blocking or async), which makes the API easy to use:

// .prepare() for blocking environment (std)
let tcp_stream = std::net::TcpStream::connect(…)
let spec = ImapStartTls::new(&mut tcp_stream);
StartTls::new(spec).prepare().unwrap();

// .prepare().await for async runtime (futures)
let tcp_stream = async_std::net::TcpStream::connect(…)
let spec = SmtpStartTls::new(&mut tcp_stream);
StartTls::new(spec).prepare().await.unwrap();

Examples can be found here:

$ RUST_LOG=debug HOST=posteo.de PORT=25 cargo run --example smtp-std
$ RUST_LOG=debug HOST=posteo.de PORT=143 cargo run --example imap-futures

Keep in mind that this is just an experiment, I would appreciate any feedback on it.

soywod commented 1 week ago

I ran into several issues with the previous implementation. After digging a lot, I unfortunately came to the conclusion that separated structs/traits for sync and async is the actual way to go. There is no happy path ATM.

The actual proposition is the following: