> ## Documentation Index
> Fetch the complete documentation index at: https://docs.automate.ax/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Automate.ax automations are TypeScript programs.
> Use Bun for installation and command examples.
> Use Automate.ax for the product name and automate.ax for the package, CLI, and domain.
> Treat documented public APIs as current; do not invent transitional or deprecated names.

# Untrash

> Restore one or many Gmail messages from Trash.

`untrash` restores one or many messages using Gmail's dedicated untrash operation. Use it to recover messages that are still present in Trash.

## Example

Restore up to 100 trashed messages from a trusted sender:

```ts theme={null}
import { automation, branch } from "automate.ax"
import { searchMessages, untrash } from "automate.ax/gmail"

export default automation("Restore trusted trashed Gmail messages", () => {
  const messages = searchMessages({
    includeSpamTrash: true,
    limit: 100,
    query: "in:trash from:billing@example.com",
  })

  branch(
    messages.length.transform((length) => length > 0),
    () => {
      untrash({
        messageIds: messages.transform((results) =>
          results.map((message) => message.messageId),
        ),
      })
    },
  )
})
```

## Inputs

| Name         | Type                                 | Required | Description                                                                      |
| ------------ | ------------------------------------ | -------- | -------------------------------------------------------------------------------- |
| `messageIds` | `string \| string[]`                 | Yes      | One or up to 1,000 immutable Gmail message IDs.                                  |
| `account`    | `string \| Google account reference` | No       | Google account binding to use. Defaults to the project's default Google account. |

Every input field also accepts a compatible `Signal`; the example derives message IDs from `searchMessages`.

## Output

The action returns a `Signal<Array<{ messageId: string; threadId: string; historyId?: string; labelIds: string[] }>>` with Gmail's updated metadata for every message, in input order.

| Field       | Type                  | Description                                                                  |
| ----------- | --------------------- | ---------------------------------------------------------------------------- |
| `messageId` | `string`              | Immutable Gmail message ID.                                                  |
| `threadId`  | `string`              | Immutable ID of the thread containing the message.                           |
| `historyId` | `string \| undefined` | Latest mailbox history record affecting the message, when Gmail supplies it. |
| `labelIds`  | `string[]`            | Gmail system and user label IDs currently applied after the operation.       |

The returned `labelIds` are the source of truth for the message's placement after Gmail restores it. The action cannot recover a message that Gmail has already deleted permanently.
