pub struct ImapClientStd {
pub stream: Box<dyn ImapStream>,
pub fragmentizer: Fragmentizer,
pub auto_id: Option<Vec<(IString<'static>, NString<'static>)>>,
pub pre_authenticated: bool,
}client only.Expand description
Blocking IMAP client: a stream, the connection-wide Fragmentizer
and one method per coroutine.
Fields§
§stream: Box<dyn ImapStream>The stream carrying the connection to the IMAP server.
fragmentizer: FragmentizerThe connection-wide parser buffer shared by every coroutine run on this connection.
auto_id: Option<Vec<(IString<'static>, NString<'static>)>>ID parameters consumed by every auth_*/login call; required by a few providers (mail.qq.com, fastmail).
None skips, Some(empty) sends ID NIL, Some(params)
sends ID (k v ...).
pre_authenticated: boolWhether the server greeting was PREAUTH: the session opened
already authenticated (a socket proxy such as sirup), so
connect skipped the SASL step. Stays false
on a freshly-opened connection.
Implementations§
Source§impl ImapClientStd
impl ImapClientStd
Sourcepub fn connect(
url: &Url,
tls: &Tls,
sasl: Option<impl Into<Sasl>>,
opts: ImapSessionOpenOptions,
) -> Result<(Self, Vec<Capability<'static>>), ImapClientError>
Available on crate features native-tls or rustls-aws or rustls-ring only.
pub fn connect( url: &Url, tls: &Tls, sasl: Option<impl Into<Sasl>>, opts: ImapSessionOpenOptions, ) -> Result<(Self, Vec<Capability<'static>>), ImapClientError>
native-tls or rustls-aws or rustls-ring only.End-to-end connect: TCP/TLS, optional STARTTLS, greeting, optional SASL.
imap:// is plain TCP (143), imaps:// is implicit TLS (993),
unix:// is a local socket. opts.starttls = true is only valid
on a cleartext transport. Pass None as sasl to skip auth.
SCRAM credentials carrying an empty nonce are given one drawn here, an empty nonce being no nonce at all as far as RFC 5802 is concerned; a caller wanting its own passes it in the credentials.
Every protocol decision belongs to ImapSessionOpen; this
method only answers its transport requests with Stream. A
caller on another runtime pumps the same coroutine with its own
sockets.
Source§impl ImapClientStd
impl ImapClientStd
Sourcepub fn new<S: ImapStream + 'static>(stream: S) -> Self
pub fn new<S: ImapStream + 'static>(stream: S) -> Self
Caller is responsible for opening the connection (TCP, TLS, STARTTLS).
Sourcepub fn set_stream<S: ImapStream + 'static>(&mut self, stream: S)
pub fn set_stream<S: ImapStream + 'static>(&mut self, stream: S)
Useful after a STARTTLS upgrade or on reconnection.
Sourcepub fn watch_mailbox(
self,
mailbox: Mailbox<'static>,
capability: &[Capability<'static>],
opts: ImapMailboxWatchStreamOptions,
) -> Result<ImapMailboxWatchStream, ImapClientError>
pub fn watch_mailbox( self, mailbox: Mailbox<'static>, capability: &[Capability<'static>], opts: ImapMailboxWatchStreamOptions, ) -> Result<ImapMailboxWatchStream, ImapClientError>
Consumes the client into a background watcher.
Drop the returned stream (or call its close) to wind down.
capability selects the QRESYNC path or the whole-mailbox
fallback, and opts.shutdown_poll how long winding down may
take.
Sourcepub fn fetch_body_stream(
&mut self,
id: NonZeroU32,
uid: bool,
sink: impl Write,
) -> Result<(), ImapClientError>
pub fn fetch_body_stream( &mut self, id: NonZeroU32, uid: bool, sink: impl Write, ) -> Result<(), ImapClientError>
FETCH <id> (BODY.PEEK[]) streaming the message body straight
into sink; the body never lands in memory whole.
Peek leaves \Seen untouched. Returns once the tagged response
is parsed; a missing id completes with an empty sink.
Sourcepub fn fetch_bodies_stream<S: Write>(
&mut self,
sequence_set: SequenceSet,
uid: bool,
open: impl FnMut(u32) -> Result<S>,
done: impl FnMut(u32, S) -> Result<()>,
) -> Result<(), ImapClientError>
pub fn fetch_bodies_stream<S: Write>( &mut self, sequence_set: SequenceSet, uid: bool, open: impl FnMut(u32) -> Result<S>, done: impl FnMut(u32, S) -> Result<()>, ) -> Result<(), ImapClientError>
UID FETCH <set> (UID BODY.PEEK[]) streaming every message body in one
command — N bodies for one round trip. Each message is routed to its own
sink: open(uid) returns a fresh sink when a message begins, its body is
streamed into it, and done(uid, sink) commits it when the message ends.
No body is held in memory whole. A requested UID absent on the server
simply never calls open/done.
Sourcepub fn append_stream(
&mut self,
mailbox: Mailbox<'static>,
source: impl Read,
len: usize,
opts: ImapMessageAppendOptions,
) -> Result<ImapMessageAppendOutput, ImapClientError>
pub fn append_stream( &mut self, mailbox: Mailbox<'static>, source: impl Read, len: usize, opts: ImapMessageAppendOptions, ) -> Result<ImapMessageAppendOutput, ImapClientError>
APPEND streaming len octets from source straight to the
socket; the body never lands in memory whole.
len must match the source exactly: IMAP declares the octet
count up front, so a shorter source poisons the connection.
Synchronising by default so the server can reject before the
body is sent; set opts.non_sync to skip the wait.
Trait Implementations§
Source§impl Debug for ImapClientStd
impl Debug for ImapClientStd
Source§impl ImapClient for ImapClientStd
impl ImapClient for ImapClientStd
Source§fn run<C, T, E>(&mut self, coroutine: C) -> Result<T, ImapClientError>
fn run<C, T, E>(&mut self, coroutine: C) -> Result<T, ImapClientError>
Source§fn greeting(&mut self) -> Result<ImapGreetingOk, ImapClientError>
fn greeting(&mut self) -> Result<ImapGreetingOk, ImapClientError>
Source§fn starttls(&mut self) -> Result<Vec<u8>, ImapClientError>
fn starttls(&mut self) -> Result<Vec<u8>, ImapClientError>
STARTTLS. Caller still has to upgrade the socket and refresh
capabilities. Read moreSource§fn auth_anonymous(
&mut self,
message: Option<&str>,
opts: ImapAuthAnonymousOptions,
) -> Result<Vec<Capability<'static>>, ImapClientError>
fn auth_anonymous( &mut self, message: Option<&str>, opts: ImapAuthAnonymousOptions, ) -> Result<Vec<Capability<'static>>, ImapClientError>
AUTHENTICATE ANONYMOUS.Source§fn auth_login(
&mut self,
user: &str,
password: &str,
opts: ImapAuthLoginOptions,
) -> Result<Vec<Capability<'static>>, ImapClientError>
fn auth_login( &mut self, user: &str, password: &str, opts: ImapAuthLoginOptions, ) -> Result<Vec<Capability<'static>>, ImapClientError>
AUTHENTICATE LOGIN (legacy). Prefer auth_plain or
auth_scram_sha256 when supported.Source§fn auth_plain(
&mut self,
authzid: Option<&str>,
authcid: &str,
password: &str,
opts: ImapAuthPlainOptions,
) -> Result<Vec<Capability<'static>>, ImapClientError>
fn auth_plain( &mut self, authzid: Option<&str>, authcid: &str, password: &str, opts: ImapAuthPlainOptions, ) -> Result<Vec<Capability<'static>>, ImapClientError>
AUTHENTICATE PLAIN.Source§fn auth_oauthbearer(
&mut self,
user: &str,
host: &str,
port: u16,
token: &str,
opts: ImapAuthOauthbearerOptions,
) -> Result<Vec<Capability<'static>>, ImapClientError>
fn auth_oauthbearer( &mut self, user: &str, host: &str, port: u16, token: &str, opts: ImapAuthOauthbearerOptions, ) -> Result<Vec<Capability<'static>>, ImapClientError>
AUTHENTICATE OAUTHBEARER. Channel must be TLS-protected.Source§fn auth_xoauth2(
&mut self,
user: &str,
token: &str,
opts: ImapAuthXoauth2Options,
) -> Result<Vec<Capability<'static>>, ImapClientError>
fn auth_xoauth2( &mut self, user: &str, token: &str, opts: ImapAuthXoauth2Options, ) -> Result<Vec<Capability<'static>>, ImapClientError>
AUTHENTICATE XOAUTH2 (Google’s pre-standard mechanism).
Prefer auth_oauthbearer when supported.Source§fn auth_scram_sha256(
&mut self,
creds: SaslScramCreds,
opts: ImapAuthScramSha256Options,
) -> Result<Vec<Capability<'static>>, ImapClientError>
fn auth_scram_sha256( &mut self, creds: SaslScramCreds, opts: ImapAuthScramSha256Options, ) -> Result<Vec<Capability<'static>>, ImapClientError>
scram only.AUTHENTICATE SCRAM-SHA-256. Read moreSource§fn capability(&mut self) -> Result<Vec<Capability<'static>>, ImapClientError>
fn capability(&mut self) -> Result<Vec<Capability<'static>>, ImapClientError>
CAPABILITY; returns the advertised capabilities.Source§fn noop(&mut self) -> Result<(), ImapClientError>
fn noop(&mut self) -> Result<(), ImapClientError>
NOOP; round-trips to keep the connection alive or poll for
updates.Source§fn id(
&mut self,
opts: ImapServerIdOptions,
) -> Result<Option<Vec<(IString<'static>, NString<'static>)>>, ImapClientError>
fn id( &mut self, opts: ImapServerIdOptions, ) -> Result<Option<Vec<(IString<'static>, NString<'static>)>>, ImapClientError>
ID. An opts.parameters of None sends ID NIL.Source§fn enable(
&mut self,
capabilities: Vec1<CapabilityEnable<'static>>,
) -> Result<Option<Vec<CapabilityEnable<'static>>>, ImapClientError>
fn enable( &mut self, capabilities: Vec1<CapabilityEnable<'static>>, ) -> Result<Option<Vec<CapabilityEnable<'static>>>, ImapClientError>
ENABLE; returns the capabilities the server confirmed enabling.Source§fn list(
&mut self,
reference: Mailbox<'static>,
pattern: ListMailbox<'static>,
) -> Result<ImapMailboxListing, ImapClientError>
fn list( &mut self, reference: Mailbox<'static>, pattern: ListMailbox<'static>, ) -> Result<ImapMailboxListing, ImapClientError>
LIST; returns the mailboxes matching reference and pattern.Source§fn lsub(
&mut self,
reference: Mailbox<'static>,
pattern: ListMailbox<'static>,
) -> Result<ImapMailboxListing, ImapClientError>
fn lsub( &mut self, reference: Mailbox<'static>, pattern: ListMailbox<'static>, ) -> Result<ImapMailboxListing, ImapClientError>
LSUB; returns the subscribed mailboxes matching reference and
pattern.Source§fn status(
&mut self,
mailbox: Mailbox<'static>,
item_names: Cow<'static, [StatusDataItemName]>,
) -> Result<Vec<StatusDataItem>, ImapClientError>
fn status( &mut self, mailbox: Mailbox<'static>, item_names: Cow<'static, [StatusDataItemName]>, ) -> Result<Vec<StatusDataItem>, ImapClientError>
STATUS; returns the requested status items for mailbox.Source§fn create(&mut self, mailbox: Mailbox<'static>) -> Result<(), ImapClientError>
fn create(&mut self, mailbox: Mailbox<'static>) -> Result<(), ImapClientError>
CREATE; creates mailbox.Source§fn delete(&mut self, mailbox: Mailbox<'static>) -> Result<(), ImapClientError>
fn delete(&mut self, mailbox: Mailbox<'static>) -> Result<(), ImapClientError>
DELETE; deletes mailbox.Source§fn rename(
&mut self,
from: Mailbox<'static>,
to: Mailbox<'static>,
) -> Result<(), ImapClientError>
fn rename( &mut self, from: Mailbox<'static>, to: Mailbox<'static>, ) -> Result<(), ImapClientError>
RENAME; renames mailbox from to to.Source§fn subscribe(
&mut self,
mailbox: Mailbox<'static>,
) -> Result<(), ImapClientError>
fn subscribe( &mut self, mailbox: Mailbox<'static>, ) -> Result<(), ImapClientError>
SUBSCRIBE; subscribes to mailbox.Source§fn unsubscribe(
&mut self,
mailbox: Mailbox<'static>,
) -> Result<(), ImapClientError>
fn unsubscribe( &mut self, mailbox: Mailbox<'static>, ) -> Result<(), ImapClientError>
UNSUBSCRIBE; unsubscribes from mailbox.Source§fn select(
&mut self,
mailbox: Mailbox<'static>,
opts: ImapMailboxSelectOptions,
) -> Result<ImapMailboxSelectData, ImapClientError>
fn select( &mut self, mailbox: Mailbox<'static>, opts: ImapMailboxSelectOptions, ) -> Result<ImapMailboxSelectData, ImapClientError>
SELECT; opens mailbox for read-write and returns its state.Source§fn examine(
&mut self,
mailbox: Mailbox<'static>,
opts: ImapMailboxExamineOptions,
) -> Result<ImapMailboxSelectData, ImapClientError>
fn examine( &mut self, mailbox: Mailbox<'static>, opts: ImapMailboxExamineOptions, ) -> Result<ImapMailboxSelectData, ImapClientError>
EXAMINE; opens mailbox read-only and returns its state.Source§fn close(&mut self) -> Result<(), ImapClientError>
fn close(&mut self) -> Result<(), ImapClientError>
CLOSE; expunges deleted messages and unselects the mailbox.Source§fn unselect(&mut self) -> Result<(), ImapClientError>
fn unselect(&mut self) -> Result<(), ImapClientError>
UNSELECT; unselects the mailbox without expunging.Source§fn expunge(&mut self) -> Result<Vec<NonZeroU32>, ImapClientError>
fn expunge(&mut self) -> Result<Vec<NonZeroU32>, ImapClientError>
EXPUNGE; returns the expunged sequence numbers.Source§fn uid_expunge(
&mut self,
sequence_set: SequenceSet,
) -> Result<Vec<NonZeroU32>, ImapClientError>
fn uid_expunge( &mut self, sequence_set: SequenceSet, ) -> Result<Vec<NonZeroU32>, ImapClientError>
UID EXPUNGE <sequence_set> (RFC 4315); permanently removes only
the \Deleted messages whose UID is in sequence_set, leaving
any other \Deleted message untouched. Read moreSource§fn fetch(
&mut self,
sequence_set: SequenceSet,
items: MacroOrMessageDataItemNames<'static>,
opts: ImapMessageFetchOptions,
) -> Result<BTreeMap<NonZeroU32, Vec1<MessageDataItem<'static>>>, ImapClientError>
fn fetch( &mut self, sequence_set: SequenceSet, items: MacroOrMessageDataItemNames<'static>, opts: ImapMessageFetchOptions, ) -> Result<BTreeMap<NonZeroU32, Vec1<MessageDataItem<'static>>>, ImapClientError>
FETCH; returns the requested items keyed by message id.Source§fn search(
&mut self,
criteria: Vec1<SearchKey<'static>>,
opts: ImapMessageSearchOptions,
) -> Result<Vec<NonZeroU32>, ImapClientError>
fn search( &mut self, criteria: Vec1<SearchKey<'static>>, opts: ImapMessageSearchOptions, ) -> Result<Vec<NonZeroU32>, ImapClientError>
SEARCH; returns the ids matching criteria.Source§fn store(
&mut self,
sequence_set: SequenceSet,
kind: StoreType,
flags: Vec<Flag<'static>>,
opts: ImapMessageStoreOptions,
) -> Result<BTreeMap<NonZeroU32, Vec1<MessageDataItem<'static>>>, ImapClientError>
fn store( &mut self, sequence_set: SequenceSet, kind: StoreType, flags: Vec<Flag<'static>>, opts: ImapMessageStoreOptions, ) -> Result<BTreeMap<NonZeroU32, Vec1<MessageDataItem<'static>>>, ImapClientError>
STORE (echo variant); returns the server-reported FETCH echoes.Source§fn copy(
&mut self,
sequence_set: SequenceSet,
mailbox: Mailbox<'static>,
opts: ImapMessageCopyOptions,
) -> Result<ImapCopyUid, ImapClientError>
fn copy( &mut self, sequence_set: SequenceSet, mailbox: Mailbox<'static>, opts: ImapMessageCopyOptions, ) -> Result<ImapCopyUid, ImapClientError>
COPY; copies messages to mailbox and returns the optional
COPYUID pair.Source§fn move(
&mut self,
sequence_set: SequenceSet,
mailbox: Mailbox<'static>,
opts: ImapMessageMoveOptions,
) -> Result<ImapCopyUid, ImapClientError>
fn move( &mut self, sequence_set: SequenceSet, mailbox: Mailbox<'static>, opts: ImapMessageMoveOptions, ) -> Result<ImapCopyUid, ImapClientError>
MOVE; moves messages to mailbox and returns the optional
COPYUID pair.Source§fn append(
&mut self,
mailbox: Mailbox<'static>,
message: &[u8],
opts: ImapMessageAppendOptions,
) -> Result<ImapMessageAppendOutput, ImapClientError>
fn append( &mut self, mailbox: Mailbox<'static>, message: &[u8], opts: ImapMessageAppendOptions, ) -> Result<ImapMessageAppendOutput, ImapClientError>
APPEND; returns the optional EXISTS count and APPENDUID pair. Read moreSource§fn sort(
&mut self,
sort_criteria: Vec1<SortCriterion>,
search_criteria: Vec1<SearchKey<'static>>,
opts: ImapMessageSortOptions,
) -> Result<Vec<NonZeroU32>, ImapClientError>
fn sort( &mut self, sort_criteria: Vec1<SortCriterion>, search_criteria: Vec1<SearchKey<'static>>, opts: ImapMessageSortOptions, ) -> Result<Vec<NonZeroU32>, ImapClientError>
SORT with a client-side fallback. Read moreSource§fn thread(
&mut self,
algorithm: ThreadingAlgorithm<'static>,
search_criteria: Vec1<SearchKey<'static>>,
opts: ImapMessageThreadOptions,
) -> Result<Vec<Thread>, ImapClientError>
fn thread( &mut self, algorithm: ThreadingAlgorithm<'static>, search_criteria: Vec1<SearchKey<'static>>, opts: ImapMessageThreadOptions, ) -> Result<Vec<Thread>, ImapClientError>
THREAD; returns the message threads matching search_criteria.Source§fn login(
&mut self,
user: &str,
password: &str,
opts: ImapLoginOptions,
) -> Result<Vec<Capability<'static>>, ImapClientError>
fn login( &mut self, user: &str, password: &str, opts: ImapLoginOptions, ) -> Result<Vec<Capability<'static>>, ImapClientError>
LOGIN. Channel must be TLS-protected.Source§fn raw(&mut self, command: &[u8]) -> Result<String, ImapClientError>
fn raw(&mut self, command: &[u8]) -> Result<String, ImapClientError>
Source§fn select_qresync(
&mut self,
mailbox: Mailbox<'static>,
uid_validity: NonZeroU32,
highest_mod_seq: u64,
capability: &[Capability<'static>],
) -> Result<ImapMailboxSelectData, ImapClientError>
fn select_qresync( &mut self, mailbox: Mailbox<'static>, uid_validity: NonZeroU32, highest_mod_seq: u64, capability: &[Capability<'static>], ) -> Result<ImapMailboxSelectData, ImapClientError>
SELECT <mailbox> (QRESYNC ...). Read more