pub struct Session<State, Transport> {
pub capabilities: Capabilities,
/* private fields */
}Expand description
Generic session enforcing compile-time state transitions.
State is one of Unauthenticated, Authenticated, or Selected;
Transport is PlainText or Tls. The type parameters gate which
commands are callable — e.g. LOGIN only exists on
Session<Unauthenticated, Tls>.
Fields§
§capabilities: CapabilitiesServer capabilities known for this session, refreshed after STARTTLS and after authentication.
Implementations§
Source§impl<S, T> Session<S, T>
impl<S, T> Session<S, T>
Sourcepub fn transition_transport<NewTransport>(self) -> Session<S, NewTransport>
pub fn transition_transport<NewTransport>(self) -> Session<S, NewTransport>
Re-tag the session’s transport type parameter (e.g. PlainText → Tls
after a STARTTLS upgrade). Performs no I/O.
Sourcepub fn events(&self) -> Receiver<Vec<u8>>
pub fn events(&self) -> Receiver<Vec<u8>>
Subscribe to untagged server frames for this session
(see RawClient::events).
Sourcepub async fn refresh_capabilities(&mut self) -> Result<(), ClientError>
pub async fn refresh_capabilities(&mut self) -> Result<(), ClientError>
Issue an explicit CAPABILITY command and update the cached set.
Used after STARTTLS and after authentication when the OK response
did not carry a [CAPABILITY …] response code.
Source§impl<T> Session<Unauthenticated, T>
impl<T> Session<Unauthenticated, T>
Sourcepub fn new(raw: RawClient, capabilities: Capabilities) -> Self
pub fn new(raw: RawClient, capabilities: Capabilities) -> Self
Wrap a connected RawClient as a fresh, unauthenticated session with
the given initial capabilities.
Source§impl<S, T> Session<S, T>
impl<S, T> Session<S, T>
Sourcepub async fn logout(self) -> Result<(), ClientError>
pub async fn logout(self) -> Result<(), ClientError>
LOGOUT is valid in any state; the session is consumed because the
connection is closed afterwards.
Sourcepub async fn noop(&mut self) -> Result<(), ClientError>
pub async fn noop(&mut self) -> Result<(), ClientError>
NOOP keeps the connection alive and triggers status updates.
Source§impl Session<Unauthenticated, Tls>
impl Session<Unauthenticated, Tls>
Sourcepub async fn login(
self,
user: &str,
pass: Password,
) -> Result<Session<Authenticated, Tls>, ClientError>
pub async fn login( self, user: &str, pass: Password, ) -> Result<Session<Authenticated, Tls>, ClientError>
LOGIN over TLS. The username and password are sent as IMAP
quoted strings with proper escaping (", \).
Returns ClientError::CommandFailed if the credentials cannot be
represented as quoted strings (8-bit, control bytes, CR, LF). Use
Self::authenticate_plain in that case.
Sourcepub async fn authenticate_plain(
self,
user: &str,
pass: &Password,
) -> Result<Session<Authenticated, Tls>, ClientError>
pub async fn authenticate_plain( self, user: &str, pass: &Password, ) -> Result<Session<Authenticated, Tls>, ClientError>
AUTHENTICATE PLAIN (RFC 4616). Credentials travel as base64 over
the SASL exchange — no quoting limitations and 8-bit safe.
Source§impl<T> Session<Authenticated, T>
impl<T> Session<Authenticated, T>
Sourcepub async fn select(
self,
mailbox: &str,
) -> Result<Session<Selected, T>, ClientError>
pub async fn select( self, mailbox: &str, ) -> Result<Session<Selected, T>, ClientError>
SELECT — open a mailbox read-write and transition to Selected.
Source§impl<T> Session<Selected, T>
impl<T> Session<Selected, T>
Sourcepub async fn fetch_raw(
&mut self,
sequence_set: &str,
items: &str,
) -> Result<Vec<u8>, ClientError>
pub async fn fetch_raw( &mut self, sequence_set: &str, items: &str, ) -> Result<Vec<u8>, ClientError>
FETCH returning the raw tagged-response bytes.
Sourcepub async fn fetch(
&mut self,
sequence_set: &str,
items: &str,
) -> Result<Vec<FetchResult>, ClientError>
pub async fn fetch( &mut self, sequence_set: &str, items: &str, ) -> Result<Vec<FetchResult>, ClientError>
FETCH returning structured FetchResult entries derived from
the broadcast untagged FETCH frames.
Sourcepub async fn fetch_body(
&mut self,
sequence_set: &str,
) -> Result<Option<String>, ClientError>
pub async fn fetch_body( &mut self, sequence_set: &str, ) -> Result<Option<String>, ClientError>
Convenience: fetch the body of the first message in sequence_set.
Sourcepub async fn search(
&mut self,
query: SearchQuery,
) -> Result<Vec<u32>, ClientError>
pub async fn search( &mut self, query: SearchQuery, ) -> Result<Vec<u32>, ClientError>
SEARCH — return the message sequence numbers matching query.
Sourcepub async fn uid_search(
&mut self,
query: SearchQuery,
) -> Result<Vec<u32>, ClientError>
pub async fn uid_search( &mut self, query: SearchQuery, ) -> Result<Vec<u32>, ClientError>
UID SEARCH — return the message UIDs matching query.
Sourcepub async fn store(
&mut self,
sequence_set: &str,
action: StoreAction,
flags: &[Flag],
) -> Result<Vec<u8>, ClientError>
pub async fn store( &mut self, sequence_set: &str, action: StoreAction, flags: &[Flag], ) -> Result<Vec<u8>, ClientError>
STORE — apply a flag action (add / remove / set) to the messages in
sequence_set (a sequence-number set such as "1:5" or "1,3,5").
Sourcepub async fn uid_store(
&mut self,
uid_set: &str,
action: StoreAction,
flags: &[Flag],
) -> Result<Vec<u8>, ClientError>
pub async fn uid_store( &mut self, uid_set: &str, action: StoreAction, flags: &[Flag], ) -> Result<Vec<u8>, ClientError>
UID STORE — like store but addressed by UID set.
Sourcepub async fn expunge(&mut self) -> Result<Vec<u8>, ClientError>
pub async fn expunge(&mut self) -> Result<Vec<u8>, ClientError>
EXPUNGE — permanently remove messages flagged \Deleted from the
selected mailbox.
Sourcepub async fn close_mailbox(
self,
) -> Result<Session<Authenticated, T>, ClientError>
pub async fn close_mailbox( self, ) -> Result<Session<Authenticated, T>, ClientError>
CLOSE — implicitly expunges deleted messages and transitions back
to Authenticated.
Sourcepub async fn unselect(self) -> Result<Session<Authenticated, T>, ClientError>
pub async fn unselect(self) -> Result<Session<Authenticated, T>, ClientError>
UNSELECT (RFC 3691) — like CLOSE but without expunging. Errors
if the server has not advertised the UNSELECT capability.
Sourcepub async fn check(&mut self) -> Result<(), ClientError>
pub async fn check(&mut self) -> Result<(), ClientError>
CHECK — implementation-defined housekeeping checkpoint.
Sourcepub async fn idle(&mut self) -> Result<IdleHandle, ClientError>
pub async fn idle(&mut self) -> Result<IdleHandle, ClientError>
IDLE (RFC 2177). Returns an IdleHandle; call stop() on it
to gracefully terminate. Callers must re-issue IDLE at least every
~28 minutes — see crate::idle for details.
Sourcepub async fn move_messages(
&mut self,
sequence_set: &str,
mailbox: &str,
) -> Result<Vec<u8>, ClientError>
pub async fn move_messages( &mut self, sequence_set: &str, mailbox: &str, ) -> Result<Vec<u8>, ClientError>
MOVE (RFC 6851). Errors if the server has not advertised MOVE.