[−][src]Struct async_imap::Client
An (unauthenticated) handle to talk to an IMAP server. This is what you get when first
connecting. A succesfull call to Client::login or Client::authenticate will return a
Session instance that provides the usual IMAP methods.
Methods
impl Client<TcpStream>[src]
pub async fn secure<S: AsRef<str>>(
__arg0: Self,
domain: S,
ssl_connector: TlsConnector
) -> Result<Client<TlsStream<TcpStream>>>[src]
__arg0: Self,
domain: S,
ssl_connector: TlsConnector
) -> Result<Client<TlsStream<TcpStream>>>
This will upgrade an IMAP client from using a regular TCP connection to use TLS.
The domain parameter is required to perform hostname verification.
impl<T: Read + Write + Unpin + Debug> Client<T>[src]
pub fn new(stream: T) -> Client<T>[src]
Creates a new client over the given stream.
For an example of how to use this method to provide a pure-Rust TLS integration, see the rustls.rs in the examples/ directory.
This method primarily exists for writing tests that mock the underlying transport, but can also be used to support IMAP over custom tunnels.
pub async fn login<U: AsRef<str>, P: AsRef<str>>(
__arg0: Self,
username: U,
password: P
) -> Result<Session<T>, (Error, Client<T>)>[src]
__arg0: Self,
username: U,
password: P
) -> Result<Session<T>, (Error, Client<T>)>
Log in to the IMAP server. Upon success a Session instance is
returned; on error the original Client instance is returned in addition to the error.
This is because login takes ownership of self, so in order to try again (e.g. after
prompting the user for credetials), ownership of the original Client needs to be
transferred back to the caller.
let tls = async_native_tls::TlsConnector::new(); let client = async_imap::connect( ("imap.example.org", 993), "imap.example.org", tls ).await?; match client.login("user", "pass").await { Ok(s) => { // you are successfully authenticated! }, Err((e, orig_client)) => { eprintln!("error logging in: {}", e); // prompt user and try again with orig_client here return Err(e); } }
pub async fn authenticate<'_, A: Authenticator, S: AsRef<str>>(
__arg0: Self,
auth_type: S,
authenticator: &'_ A
) -> Result<Session<T>, (Error, Client<T>)>[src]
__arg0: Self,
auth_type: S,
authenticator: &'_ A
) -> Result<Session<T>, (Error, Client<T>)>
Authenticate with the server using the given custom authenticator to handle the server's
challenge.
struct OAuth2 { user: String, access_token: String, } impl async_imap::Authenticator for OAuth2 { type Response = String; fn process(&self, _: &[u8]) -> Self::Response { format!( "user={}\x01auth=Bearer {}\x01\x01", self.user, self.access_token ) } } let auth = OAuth2 { user: String::from("me@example.com"), access_token: String::from("<access_token>"), }; let domain = "imap.example.com"; let tls = async_native_tls::TlsConnector::new(); let client = async_imap::connect((domain, 993), domain, tls).await?; match client.authenticate("XOAUTH2", &auth).await { Ok(session) => { // you are successfully authenticated! }, Err((err, orig_client)) => { eprintln!("error authenticating: {}", err); // prompt user and try again with orig_client here return Err(err); } };
Trait Implementations
impl<T: Debug + Read + Write + Unpin> Debug for Client<T>[src]
impl<T: Read + Write + Unpin + Debug> Deref for Client<T>[src]
type Target = Connection<T>
The resulting type after dereferencing.
fn deref(&self) -> &Connection<T>[src]
impl<T: Read + Write + Unpin + Debug> DerefMut for Client<T>[src]
impl<T: Read + Write + Unpin + Debug> Unpin for Client<T>[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Client<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Client<T> where
T: Send,
T: Send,
impl<T> Sync for Client<T> where
T: Sync,
T: Sync,
impl<T> UnwindSafe for Client<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,