AsyncClient

Struct AsyncClient 

Source
pub struct AsyncClient { /* private fields */ }
Expand description

The key structure for the crate, delineating capabilities of the POP3 client as per the protocol RFC

§Errors and problems

All the methods this Client has are susceptible to errors. The common reasons for those are:

  • Not possible to establish connection
  • The server does not support the protocol
  • Connection aborted
  • Some data got lost or modified, and now it’s not possible to decode the obtained message
  • The server does not recognize the command. This might happen even if by RFC, the command is mandatory, as most of the servers do not follow the protocol letter by letter
  • The command was sent on the wrong stage. In other words, you tried to do something before you authorized.
  • The server returned an error response. We’ll look at those within each separate method

To find out more, read the output of the error you’ve got – it’s always a string!

Implementations§

Source§

impl AsyncClient

Source

pub async fn connect(host: &str, port: u16) -> Result<Self>

Connect to given host and port.

This is the simplest way to initiate connection, so it’s preferable to use it in a straightforward manner unless you have specific ClientConfig reservations.

§Example
let client = AsyncClient::connect("pop3.mailtrap.io", 1100).await?;
Source

pub async fn login(&mut self, username: &str, password: &str) -> Result<()>

Authorization through plaintext login and password

§Example
client.login("sweet_username", "very_secret_password").await?;
§Errors

The server may return an error response if:

  • the username was not found
  • the password does not match the username
  • the connection to this mailbox has been locked by another device – so you won’t be able to connect until the lock is released.
Source

pub async fn quit(self) -> Result<()>

End the session, consuming the client

§Example
client.quit()?;
client.noop()?; // Shouldn't compile, as the client has been consumed upon quitting
Source

pub async fn stat(&mut self) -> Result<(u64, u64)>

Display the statistics for the mailbox (that’s what the STAT command does).

In the resulting u32 tuple, the first number is the number of messages, and the second one is number of octets in those messages.

§Example
let (messages, octets) = client.stat().await?;
assert_eq!(messages, 2);
assert_eq!(octets, 340);
Source

pub async fn list(&mut self, id: Option<u64>) -> Result<Response>

Show the statistical information on a chosen letter, or all letters. The information in question always required to start with the letter size, but use of additional stats is not regimented in any way.

§Example
let single_stats = client.list(Some(1)).await?; // show info on the letter number 1
let all_stats = client.list(None).await?; // show info on all letters
§Errors

The server may return an error response if:

  • The letter under the given index does not exist in the mailbox
  • The letter under the given index has been marked deleted
Source

pub async fn retr(&mut self, id: u64) -> Result<Bytes>

Show the full content of the chosen message

§Example
let letter_content = client.retr(5).await?;
§Errors

The server may return an error response if:

  • The letter under the given index does not exist in the mailbox
  • The letter under the given index has been marked deleted
Source

pub async fn dele(&mut self, id: u64) -> Result<Response>

Mark the chosen message as deleted

§Example
client.dele(3).await?; // now, the THIRD message is marked as deleted, and no new manipulations on it are possible
§Errors

The server may return an error response if:

  • The letter under the given index does not exist in the mailbox
  • The letter under the given index has been marked deleted
Source

pub async fn noop(&mut self) -> Result<()>

Do nothing and return a positive response

§Example
assert!(client.noop().await.is_ok());
Source

pub async fn rset(&mut self) -> Result<Response>

Reset the session state, unmarking the items marked as deleted

§Example
client.dele(3).await?;
client.dele(4).await?;
client.rset().await?; // undo all the previous deletions
Source

pub async fn top(&mut self, id: u64, lines: u64) -> Result<Response>

Show top n lines of a chosen message

§Example
let top = client.top(1, 2).await?; // Get TWO first lines of the FIRST message
§Errors

The server may return an error response if:

  • The letter under the given index does not exist in the mailbox
  • The letter under the given index has been marked deleted
Source

pub async fn uidl(&mut self, id: Option<u64>) -> Result<Response>

Show the unique ID listing for the chosen message or for all the messages. Unlike message numbering, this ID does not change between sessions.

§Example
let uidl_all = client.uidl(None).await?;
let uidl_one = client.uidl(Some(1)).await?;
§Errors

The server may return an error response if:

  • The letter under the given index does not exist in the mailbox
  • The letter under the given index has been marked deleted
Source

pub async fn apop(&mut self, id: &str, token: &str) -> Result<Response>

Authorise using the APOP method

Refer to the POP3 RFC for details.

§Example
client.apop("another_sweet_username", "c4c9334bac560ecc979e58001b3e22fb").await?;
§Errors

The server will return error if permission was denied.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.