messages.learn
Train spam filter from a message.
Submits spam or ham training feedback for a specific email message to tune the spam filter. Idempotent per message and class: if this message was already taught this class — by an earlier call, or by the user moving it into or out of Junk (which trains on its own after a short undo window) — the call answers 202 without sending it again, and it supersedes a move-triggered sample still waiting out that window. The opposite class is always sent.
openemail.messages.learn(
mailboxId: string,
messageId: string,
body: MessagesLearnBody,
options?: CallOptions,
): ApiPromise<MessagesLearnResult>It calls POST /mailboxes/{mailboxId}/messages/{messageId}/learn: Train spam filter from a message in the API reference.
Example
const result = await openemail.messages.learn(mailboxId, messageId, { class: 'spam' })Arguments
| Argument | Type | Description |
|---|---|---|
mailboxId | string | Mailbox ULID identifier. The path's {mailboxId}. |
messageId | string | Message ULID identifier. The path's {messageId}. |
body | MessagesLearnBody | The request's body. |
Options
It takes no options of its own. Every call also takes signal, timeout, retry and headers, which say how that one call is sent (call options).
Answer
Awaited, it is the API's JSON, MessagesLearnResult. It is an ApiPromise: .withResponse() gives the same with the Response it came in, for its headers.
Errors
| Status | What it means |
|---|---|
401 | unauthorized: the bearer credential is missing, malformed, expired, or revoked. Carries a WWW-Authenticate: Bearer challenge |
404 | Mailbox or message not found |
413 | too_large: JSON request body exceeds 1 MiB or 500,000 values (object keys included), checked before parsing |
503 | learning_unavailable — spam filter service is not configured. Or temporary_failure: the platform's storage could not answer just now; retry after the Retry-After window. Any operation can answer this. A write that got it may have been applied, so retry it with the same idempotency key where it takes one, or read the state back first (see Transient failures in the API description) |
A failed call rejects with a RequestError: its status, and its code, the API's error. Decide on the code: one status covers several.
Types
MessagesLearnBody
/** The body of `messages.learn`. */
type MessagesLearnBody = {
/** Feedback classification ('spam' for junk, 'ham' for legitimate) */
class: ('spam' | 'ham')
}MessagesLearnResult
/** What `messages.learn` answers. */
type MessagesLearnResult = {
status: string
}