Skip to main content

JmapClientStd

Struct JmapClientStd 

Source
pub struct JmapClientStd {
    pub inner: JmapClientStd,
    pub identity_id: Option<String>,
    pub drafts_mailbox_id: Option<String>,
}
Available on crate features client and jmap only.
Expand description

Light JMAP client built on top of the io-jmap type-erased inner.

Unlike IMAP, JMAP carries no auto_select (destroys are global) and no separate capability list (capabilities are exposed via the inner client’s cached JmapSession).

Two extra options are required for Self::send_message: the JMAP identity to submit under (Identity/get type=role:identity) and the drafts mailbox id (Mailbox/query role: drafts). Populate them after Self::session_get when sending is in scope.

Fields§

§inner: JmapClientStd§identity_id: Option<String>§drafts_mailbox_id: Option<String>

Implementations§

Source§

impl JmapClientStd

Source

pub fn new<S: Read + Write + Send + 'static>( stream: S, http_auth: SecretString, ) -> Self

Wraps an already-connected stream with the bearer / basic HTTP credential. The session must be discovered via Self::session_get before any shared-API method is called.

Source

pub fn run<C, T, E>(&mut self, coroutine: C) -> Result<T, JmapClientError>
where C: JmapCoroutine<Yield = JmapYield, Return = Result<T, E>>, JmapClientError: From<E>,

Pumps any standard-shape JMAP coroutine (Yield = JmapYield, Return = Result<T, E>) against the inner client’s stream until it terminates.

Reaches into Self::inner for raw field access rather than delegating to InnerJmapClientStd::run so error variants route through JmapClientError directly.

Source

pub fn session_get(&mut self, url: &Url) -> Result<(), JmapClientError>

Discovers the JMAP session against url and caches it on the inner client. Pass either a base URL for /.well-known/jmap discovery or a direct session endpoint URL.

Source

pub fn list_mailboxes( &mut self, with_counts: bool, ) -> Result<Vec<Mailbox>, JmapClientError>

Lists every JMAP mailbox visible to the session’s primary mail account. When with_counts is set, includes totalEmails / unreadEmails (still one round-trip; JMAP returns counts inline).

Source

pub fn list_envelopes( &mut self, mailbox: &str, page: Option<u32>, page_size: Option<u32>, ) -> Result<Vec<Envelope>, JmapClientError>

Lists envelopes from mailbox. page = None and page_size = None fetch the whole mailbox.

Source

pub fn search_envelopes( &mut self, mailbox: &str, query: Option<&SearchEmailsQuery>, page: Option<u32>, page_size: Option<u32>, ) -> Result<Vec<Envelope>, JmapClientError>

Available on crate feature search only.

Searches envelopes in mailbox against the shared query. Pagination is applied to the SORT-ordered id list; date predicates are re-checked client-side because JMAP filters on receivedAt while the shared DSL targets sentAt.

Source

pub fn store_flags( &mut self, mailbox: &str, ids: &[&str], flags: &[Flag], op: FlagOp, ) -> Result<(), JmapClientError>

Adds, sets, or removes flags (JMAP keywords) on a JMAP email id set. mailbox is unused: JMAP keywords are global per email, not per mailbox.

Source

pub fn get_message( &mut self, mailbox: &str, id: &str, ) -> Result<Vec<u8>, JmapClientError>

Fetches one message’s raw RFC 5322 bytes via Email/get (resolving the blob id) then Blob/download.

Source

pub fn add_message( &mut self, mailbox: &str, flags: &[Flag], raw: Vec<u8>, ) -> Result<String, JmapClientError>

Uploads raw as a blob then imports it into mailbox with the requested keywords. Returns the created email id.

Source

pub fn create_mailbox(&mut self, name: &str) -> Result<(), JmapClientError>

Creates name as a top-level JMAP mailbox.

Source

pub fn delete_mailbox(&mut self, name: &str) -> Result<(), JmapClientError>

Deletes the JMAP mailbox named name; drops every email that lives only in that mailbox (onDestroyRemoveEmails: true).

Source

pub fn delete_message( &mut self, mailbox: &str, id: &str, ) -> Result<(), JmapClientError>

Destroys the JMAP email by id (global delete; removes the email from every mailbox it references).

Source

pub fn copy_messages( &mut self, from: &str, to: &str, ids: &[&str], ) -> Result<(), JmapClientError>

Copies a JMAP email id set into to by adding to’s mailbox-id reference to each email. The from argument is part of the shared signature for symmetry with IMAP / Maildir but unused: existing mailboxIds carry the source reference.

Source

pub fn move_messages( &mut self, from: &str, to: &str, ids: &[&str], ) -> Result<(), JmapClientError>

Moves a JMAP email id set from from to to; adds to’s id and removes from’s id in the same Email/set patch.

Source

pub fn send_message(&mut self, raw: Vec<u8>) -> Result<(), JmapClientError>

Queues raw for delivery via EmailSubmission/set. Requires Self::identity_id and Self::drafts_mailbox_id to be populated.

Source

pub fn watch_mailbox( &mut self, mailbox: &str, shutdown: Arc<AtomicBool>, tx: Sender<WatchEvent>, ) -> Result<(), JmapClientError>

Watches mailbox for envelope-level deltas via the JMAP EventSource (closeafter=state) + Email/changes + Email/get loop, forwarding every event through tx.

Blocks the current thread. Returns Ok(()) when shutdown flips, when the receiver behind tx is dropped, or when the protocol layer errors out.

Source

pub fn diff_envelopes( &mut self, _mailbox: &str, state: Option<&[u8]>, ) -> Result<EnvelopeDiff, JmapClientError>

Returns the Email/changes-driven envelope delta against the opaque per-backend state checkpoint.

Decodes state as the cached Email/state token, then walks Email/changes rounds until hasMoreChanges clears. Created ids are turned into new envelopes via Email/get; updated ids surface as FlagUpdate entries. The mailbox argument is part of the shared signature: JMAP Email/changes is global per account and ignores it. Falls back to EnvelopeDiff::FullListRequired when the cached state is unusable or the server returns cannotCalculateChanges.

Source

pub fn diff_mailboxes( &mut self, state: Option<&[u8]>, ) -> Result<MailboxDiff, JmapClientError>

Returns the Mailbox/changes-driven mailbox-set delta against the opaque per-backend state checkpoint. A single round trip: any non-empty bucket (or the server bumping the state) maps to MailboxDiff::Changed; an idle bucket maps to MailboxDiff::Unchanged. On cannotCalculateChanges the caller is told to re-list via Changed { new_state: None }.

Source§

impl JmapClientStd

Source

pub fn connect( url: &Url, tls: &Tls, http_auth: SecretString, ) -> Result<Self, JmapClientError>

Available on crate features native-tls or rustls-aws or rustls-ring only.

Opens a TCP / TLS connection to url, builds the inner client around it, then runs session_get to discover the JMAP session.

url is either a base URL for /.well-known/jmap discovery or a direct session endpoint.

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<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

impl<T, S> SpanWrap<S> for T
where S: WrappingSpan<T>,

Source§

fn with_span(self, span: S) -> <S as WrappingSpan<Self>>::Spanned

Invokes WrappingSpan::make_wrapped to wrap an AST node in a span.
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.