Skip to main content

DraftsApi

Struct DraftsApi 

Source
pub struct DraftsApi<'a> { /* private fields */ }
Expand description

Drafts API façade.

Implementations§

Source§

impl<'a> DraftsApi<'a>

Source

pub fn new(client: &'a GmailClient) -> Self

Wraps an existing GmailClient for draft operations.

Source

pub async fn list( &self, query: Option<&str>, limit: usize, page_token: Option<&str>, ) -> Result<DraftListResponse>

Lists drafts matching query, returning a single page.

query uses the Gmail search-box syntax. limit is rejected client-side when it exceeds MAX_PAGE_LIMIT; use Self::list_all to auto-paginate across pages. Needs only the gmail.readonly scope.

Source

pub async fn list_all( &self, query: Option<&str>, limit: usize, ) -> Result<DraftListResponse>

Lists drafts, auto-paginating via cursor as needed.

limit == 0 means “fetch every draft up to HARD_CAP”, exactly as MessagesApi::search_all does.

Source

pub async fn list_summaries( &self, query: Option<&str>, limit: usize, concurrency: usize, ) -> Result<Vec<DraftSummary>>

Lists drafts and enriches each with its recipients, subject, date and snippet via one messages.get(format=metadata) call per draft.

The hydration fan-out is MessagesApi::search_summaries’ own (hydrate_in_order): at most concurrency calls in flight (clamped to 1 through MAX_CONCURRENCY), results in listing order, and any one failure aborts the whole call. The one exception is a 404 on a draft’s message: the draft was saved again after the listing, which replaced that message. It keeps its row, with the listing’s ids and blank headers. Both endpoints accept gmail.readonly.

Source

pub async fn get( &self, draft_id: &str, format: MessageFormat, ) -> Result<DraftDetail>

Fetches one draft by its draft id, with its message at format.

A 404 becomes a “no draft with id” error that points at gmail draft list, since the likely cause is passing a message id, which gmail search and gmail read show but no drafts endpoint accepts. The HTTP error stays in the chain. Needs only the gmail.readonly scope.

Source

pub async fn create(&self, raw: &[u8], thread_id: Option<&str>) -> Result<Draft>

Creates a draft from a complete RFC 5322 message (drafts.create?uploadType=multipart).

Uses MessagesApi::insert’s /upload/ multipart transport ([upload_rfc822]), so large attachments work: the draft resource as the JSON part, then raw verbatim as message/rfc822. Content over MAX_INSERT_BYTES is refused before the request body is even built.

thread_id files the draft into an existing thread. Gmail only honours it when the message’s In-Reply-To/References and Subject also match that thread (see crate::gmail::compose).

Requires gmail.modify (or gmail.compose); a gmail.readonly token gets a 403 back from Google. drafts.create costs 10 quota units, per https://developers.google.com/workspace/gmail/api/reference/quota.

Source

pub async fn update( &self, draft_id: &str, raw: &[u8], thread_id: Option<&str>, ) -> Result<Draft>

Replaces a draft’s message with raw (PUT drafts/{id}?uploadType=multipart).

Gmail has no partial form: the whole message is replaced, and the draft keeps its id but gets a new message id. Same /upload/ transport and MAX_INSERT_BYTES pre-check as Self::create.

thread_id must be re-sent to keep a reply draft in its thread. An update that omits it silently moves the draft out of the thread, so callers pass the threadId of the draft they fetched. Drafts have no ETag or precondition, so this always overwrites whatever is stored; callers that care check the message id first.

Requires gmail.modify (or gmail.compose).

Trait Implementations§

Source§

impl<'a> Debug for DraftsApi<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for DraftsApi<'a>

§

impl<'a> !UnwindSafe for DraftsApi<'a>

§

impl<'a> Freeze for DraftsApi<'a>

§

impl<'a> Send for DraftsApi<'a>

§

impl<'a> Sync for DraftsApi<'a>

§

impl<'a> Unpin for DraftsApi<'a>

§

impl<'a> UnsafeUnpin for DraftsApi<'a>

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<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