Skip to main content

SessionClient

Struct SessionClient 

Source
#[non_exhaustive]
pub struct SessionClient { /* private fields */ }
Expand description

A JmapClient bound to a JMAP session.

Obtain via JmapMailExt::with_mail_session. All JMAP Mail methods are available on this type without needing to pass &Session on every call.

§Session lifecycle

SessionClient captures the Session at construction time. After re-fetching the session via JmapClient::fetch_session, construct a new SessionClient with the updated session. Reusing a stale SessionClient after session expiry will result in unknownAccount or similar errors from the server.

Clone is derived because JmapClient is itself cheap-to-clone (it already implements Clone and with_mail_session clones one internally), enabling parallel-task fan-out with one bound session.

Debug is implemented manually to redact the inner JmapClient (which holds an HTTP client and is intentionally not Debug in jmap-base-client); only the Session is shown. This lets callers embed a SessionClient in a #[derive(Debug)] struct without manual impls of their own.

Implementations§

Source§

impl SessionClient

Source

pub async fn email_get( &self, ids: Option<&[Id]>, properties: Option<&[&str]>, params: Option<EmailGetParams>, ) -> Result<GetResponse<Email>, ClientError>

Fetch Email objects by IDs (RFC 8621 §4.1.8 — Email/get).

If ids is None, the server returns all Emails for the account. Pass properties: None to return all fields. Pass params: None to use server defaults for body-fetch options.

Source

pub async fn email_changes( &self, since_state: &State, max_changes: Option<u64>, ) -> Result<ChangesResponse, ClientError>

Fetch changes to Email objects since since_state (RFC 8621 §4.2 — Email/changes).

If has_more_changes is true in the response, call again with new_state as since_state until the flag is false.

Source

pub async fn email_set( &self, create: Option<Value>, update: Option<HashMap<Id, PatchObject>>, destroy: Option<Vec<Id>>, if_in_state: Option<&State>, ) -> Result<SetResponse<Email>, ClientError>

Create, update, or destroy Email objects (RFC 8621 §4.3 — Email/set).

Pass create, update, and/or destroy as needed. All three are optional; pass None to omit any operation from the request. Pass if_in_state: Some(&state) to use an optimistic-concurrency guard.

update is Option<HashMap<Id, PatchObject>> (RFC 8620 §5.3). Wire format is unchanged from a plain JSON object because PatchObject is #[serde(transparent)]; the typed parameter binds the JSON Pointer key + null-leaf removal contract to the type system.

Source

pub async fn email_query( &self, filter: Option<Value>, sort: Option<Value>, position: Option<u64>, limit: Option<u64>, collapse_threads: Option<bool>, ) -> Result<QueryResponse, ClientError>

Query Email IDs with optional filter and sort (RFC 8621 §4.4 — Email/query).

Pass filter: None and sort: None to return all Emails with server-default ordering. Use position and limit for pagination. Pass collapse_threads: Some(true) to return at most one email per thread.

Source

pub async fn email_query_changes( &self, since_query_state: &State, max_changes: Option<u64>, collapse_threads: Option<bool>, ) -> Result<QueryChangesResponse, ClientError>

Fetch query-result changes for Email since since_query_state (RFC 8621 §4.5 — Email/queryChanges).

Source

pub async fn email_copy( &self, params: EmailCopyParams, create: Value, ) -> Result<SetResponse<Email>, ClientError>

Copy Emails from another account (RFC 8621 §4.7 — Email/copy).

params carries fromAccountId and optional destroy-after-copy flags. create is a map of creation keys to partial Email objects (with new mailboxIds etc.) as described in RFC 8621 §4.7.

Source

pub async fn email_import( &self, emails: &HashMap<String, EmailImportInput<'_>>, if_in_state: Option<&State>, ) -> Result<EmailImportResponse, ClientError>

Import raw RFC 5322 messages into the account (RFC 8621 §4.8 — Email/import).

Each entry in emails maps a caller-chosen creation id to an EmailImportInput referencing a previously uploaded blob and the target mailbox(es). The blob must have been uploaded via the standard blob-upload mechanism on jmap-base-client before calling this method.

At least one mailbox id is required per RFC 8621 §4.8; the empty-set case is rejected client-side as InvalidArgument. An empty emails map is also rejected — a no-op import is never useful and would generate a round-trip with no successful creations.

Pass if_in_state: Some(&state) for an optimistic-concurrency guard against the Email object state (RFC 8621 §4.8 returns stateMismatch if the supplied state does not match).

Per-creation failures appear in EmailImportResponse::not_created as super::SetError values; possible error codes include alreadyExists (with an existingId extra field), invalidProperties, overQuota, and invalidEmail.

Source

pub async fn email_parse( &self, blob_ids: &[Id], params: Option<EmailParseParams>, ) -> Result<EmailParseResponse, ClientError>

Parse uploaded blobs as RFC 5322 messages without importing them (RFC 8621 §4.9 — Email/parse).

Returns Email objects derived from each blob. Per RFC 8621 §4.9 the returned Emails have id, mailboxIds, keywords, and receivedAt set to null (the messages are not in the mail store); threadId MAY be present if the server can predict the assignment.

Pass params: None to use server defaults for properties and body fetching. The set of properties returned defaults to the spec-listed header/body fields documented in RFC 8621 §4.9.

Empty blob_ids is rejected as InvalidArgument — a no-op parse round-trip is never useful.

Source§

impl SessionClient

Source

pub async fn identity_get( &self, ids: Option<&[Id]>, properties: Option<&[&str]>, ) -> Result<GetResponse<Identity>, ClientError>

Fetch Identity objects by IDs (RFC 8621 §6.1 — Identity/get).

If ids is None, the server returns all Identities for the account. Pass properties: None to return all fields.

Source

pub async fn identity_changes( &self, since_state: &State, max_changes: Option<u64>, ) -> Result<ChangesResponse, ClientError>

Fetch changes to Identity objects since since_state (RFC 8621 §6.2 — Identity/changes).

Source

pub async fn identity_set( &self, create: Option<Value>, update: Option<HashMap<Id, PatchObject>>, destroy: Option<Vec<Id>>, ) -> Result<SetResponse<Identity>, ClientError>

Create, update, or destroy Identity objects (RFC 8621 §6.3 — Identity/set).

Pass create, update, and/or destroy as needed. Pass None to omit.

update is Option<HashMap<Id, PatchObject>> (RFC 8620 §5.3). Wire format is unchanged from a plain JSON object because PatchObject is #[serde(transparent)]; the typed parameter binds the JSON Pointer key + null-leaf removal contract to the type system.

Source§

impl SessionClient

Source

pub async fn mailbox_get( &self, ids: Option<&[Id]>, properties: Option<&[&str]>, ) -> Result<GetResponse<Mailbox>, ClientError>

Fetch Mailbox objects by IDs (RFC 8621 §2.1 — Mailbox/get).

If ids is None, the server returns all Mailboxes for the account. Pass properties: None to return all fields.

Source

pub async fn mailbox_changes( &self, since_state: &State, max_changes: Option<u64>, ) -> Result<ChangesResponse, ClientError>

Fetch changes to Mailbox objects since since_state (RFC 8621 §2.2 — Mailbox/changes).

Source

pub async fn mailbox_set( &self, create: Option<Value>, update: Option<HashMap<Id, PatchObject>>, destroy: Option<Vec<Id>>, params: Option<MailboxSetParams>, ) -> Result<SetResponse<Mailbox>, ClientError>

Create, update, or destroy Mailbox objects (RFC 8621 §2.5 — Mailbox/set).

Pass create, update, and/or destroy as needed. Pass None to omit. Pass params: Some(MailboxSetParams { on_destroy_remove_emails: Some(true) }) to allow destroying a non-empty mailbox.

update is Option<HashMap<Id, PatchObject>> (RFC 8620 §5.3). Wire format is unchanged from a plain JSON object because PatchObject is #[serde(transparent)]; the typed parameter binds the JSON Pointer key + null-leaf removal contract to the type system.

Source

pub async fn mailbox_query( &self, filter: Option<Value>, sort: Option<Value>, position: Option<u64>, limit: Option<u64>, ) -> Result<QueryResponse, ClientError>

Query Mailbox IDs with optional filter and sort (RFC 8621 §2.3 — Mailbox/query).

Pass filter: None and sort: None to return all Mailboxes with server-default ordering. Use position and limit for pagination.

Source

pub async fn mailbox_query_changes( &self, since_query_state: &State, max_changes: Option<u64>, ) -> Result<QueryChangesResponse, ClientError>

Fetch query-result changes for Mailbox since since_query_state (RFC 8621 §2.4 — Mailbox/queryChanges).

Source§

impl SessionClient

Source

pub async fn search_snippet_get( &self, account_id: Option<&Id>, filter: Value, thread_ids: Option<&[Id]>, email_ids: Option<&[Id]>, ) -> Result<Value, ClientError>

Fetch SearchSnippet objects (RFC 8621 §5 — SearchSnippet/get).

filter is the same filter object used in Email/query. Either thread_ids or email_ids (or both) may be provided to scope the snippets; the server returns one SearchSnippet per email in the result set.

Returns the raw response value because the SearchSnippet/get response shape differs from the standard /get shape (no state, no notFound). Callers should deserialize into Vec<jmap_mail_types::SearchSnippet> via response["list"].as_array().

Source§

impl SessionClient

Source

pub async fn email_submission_get( &self, ids: Option<&[Id]>, properties: Option<&[&str]>, ) -> Result<GetResponse<EmailSubmission>, ClientError>

Fetch EmailSubmission objects by IDs (RFC 8621 §7.1 — EmailSubmission/get).

If ids is None, the server returns all submissions for the account. Pass properties: None to return all fields.

Source

pub async fn email_submission_changes( &self, since_state: &State, max_changes: Option<u64>, ) -> Result<ChangesResponse, ClientError>

Fetch changes to EmailSubmission objects since since_state (RFC 8621 §7.2 — EmailSubmission/changes).

Source

pub async fn email_submission_query( &self, filter: Option<Value>, sort: Option<Value>, position: Option<u64>, limit: Option<u64>, ) -> Result<QueryResponse, ClientError>

Query EmailSubmission IDs with optional filter and sort (RFC 8621 §7.3 — EmailSubmission/query).

The sort property for this object type is "sentAt" (RFC 8621 §7.3, line 4513), not "sendAt" (which is an object field). Callers constructing the sort argument should use "sentAt" as the property name.

Source

pub async fn email_submission_query_changes( &self, since_query_state: &State, max_changes: Option<u64>, filter: Option<Value>, sort: Option<Value>, ) -> Result<QueryChangesResponse, ClientError>

Fetch query-result changes for EmailSubmission since since_query_state (RFC 8621 §7.4 — EmailSubmission/queryChanges).

Source

pub async fn email_submission_set( &self, create: Option<Value>, update: Option<HashMap<Id, PatchObject>>, destroy: Option<Vec<Id>>, if_in_state: Option<&State>, params: Option<EmailSubmissionSetParams>, ) -> Result<SetResponse<EmailSubmission>, ClientError>

Create, update, or destroy EmailSubmission objects (RFC 8621 §7.5 — EmailSubmission/set).

The optional params argument carries the two success-hook fields:

  • on_success_update_email — a PatchObject map (keyed by submission creation key) of patches to apply to the associated Email when the submission is created successfully (RFC 8621 §7.5).
  • on_success_destroy_email — IDs (or #-reference creation keys) of Email objects to destroy when the submission is created successfully (RFC 8621 §7.5).
Source§

impl SessionClient

Source

pub async fn thread_get( &self, ids: Option<&[Id]>, properties: Option<&[&str]>, ) -> Result<GetResponse<Thread>, ClientError>

Fetch Thread objects by IDs (RFC 8621 §3.1 — Thread/get).

If ids is None, the server returns all Threads for the account. Pass properties: None to return all fields.

Source

pub async fn thread_changes( &self, since_state: &State, max_changes: Option<u64>, ) -> Result<ChangesResponse, ClientError>

Fetch changes to Thread objects since since_state (RFC 8621 §3.2 — Thread/changes).

If has_more_changes is true in the response, call again with new_state as since_state until the flag is false.

Source§

impl SessionClient

Source

pub async fn vacation_response_get( &self, ) -> Result<GetResponse<VacationResponse>, ClientError>

Fetch the VacationResponse singleton for the account (RFC 8621 §8).

The server always returns a single VacationResponse object whose id is "singleton". There is no need to pass ids.

Source

pub async fn vacation_response_set( &self, update: Option<HashMap<Id, PatchObject>>, ) -> Result<SetResponse<VacationResponse>, ClientError>

Update the VacationResponse singleton (RFC 8621 §8).

update should be a JSON object of the form:

{ "singleton": { "isEnabled": true, "subject": "Out of office" } }

create and destroy are not supported by VacationResponse/set.

update is Option<HashMap<Id, PatchObject>> (RFC 8620 §5.3). The usual shape is {"singleton": <patch>}. Wire format is unchanged from a plain JSON object because PatchObject is #[serde(transparent)].

Trait Implementations§

Source§

impl Clone for SessionClient

Source§

fn clone(&self) -> SessionClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SessionClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more