Struct imap::ClientBuilder
source · [−]Expand description
A convenience builder for Client
structs over various encrypted transports.
Creating a Client
using native-tls
transport is straightforward:
let client = ClientBuilder::new("imap.example.com", 993).native_tls()?;
Similarly, if using the rustls-tls
feature you can create a Client
using rustls:
let client = ClientBuilder::new("imap.example.com", 993).rustls()?;
To use STARTTLS
, just call starttls()
before one of the Client
-yielding
functions:
let client = ClientBuilder::new("imap.example.com", 993)
.starttls()
.rustls()?;
The returned Client
is unauthenticated; to access session-related methods (through
Session
), use Client::login
or Client::authenticate
.
Implementations
sourceimpl<D> ClientBuilder<D> where
D: AsRef<str>,
impl<D> ClientBuilder<D> where
D: AsRef<str>,
sourcepub fn new(domain: D, port: u16) -> Self
pub fn new(domain: D, port: u16) -> Self
Make a new ClientBuilder
using the given domain and port.
sourcepub fn native_tls(&mut self) -> Result<Client<TlsStream<TcpStream>>>
pub fn native_tls(&mut self) -> Result<Client<TlsStream<TcpStream>>>
Return a new Client
using a native-tls
transport.
sourcepub fn connect<F, C>(&mut self, handshake: F) -> Result<Client<C>> where
F: FnOnce(&str, TcpStream) -> Result<C>,
C: Read + Write,
pub fn connect<F, C>(&mut self, handshake: F) -> Result<Client<C>> where
F: FnOnce(&str, TcpStream) -> Result<C>,
C: Read + Write,
Make a Client
using a custom TLS initialization. This function is intended
to be used if your TLS setup requires custom work such as adding private CAs
or other specific TLS parameters.
The handshake
argument should accept two parameters:
and yield a Result<C>
where C
is Read + Write
. It should only perform
TLS initialization over the given tcp
socket and return the encrypted stream
object, such as a native_tls::TlsStream
or a [rustls_connector::TlsStream
].
If the caller is using STARTTLS
and previously called starttls
then the tcp
socket given to the handshake
function will be connected and will
have initiated the STARTTLS
handshake.
let client = ClientBuilder::new("imap.example.com", 993)
.starttls()
.connect(|domain, tcp| {
let ssl_conn = RustlsConnector::new_with_native_certs()?;
Ok(ssl_conn.connect(domain, tcp)?)
})?;
Auto Trait Implementations
impl<D> RefUnwindSafe for ClientBuilder<D> where
D: RefUnwindSafe,
impl<D> Send for ClientBuilder<D> where
D: Send,
impl<D> Sync for ClientBuilder<D> where
D: Sync,
impl<D> Unpin for ClientBuilder<D> where
D: Unpin,
impl<D> UnwindSafe for ClientBuilder<D> where
D: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more