---
title: "search · RUAL Documentation"
description: "Finds messages in a mailbox and returns their UIDs, newest first. Wire the UIDs into imap fetch to read them. Every criterion that is filled must match."
canonical: https://docs.rual.nl/block-types/imap/imapconnection_search
language: en
---

[Cluster](https://docs.rual.nl/cluster)

[Blocks](https://docs.rual.nl/block-types)

[Interfaces](https://docs.rual.nl/interfaces)

[Blueprints](https://docs.rual.nl/blueprints)

[Blueprint Language](https://docs.rual.nl/engine)

[Tutorials](https://docs.rual.nl/tutorials)

[Home automation](https://docs.rual.nl/home-automation)

[Examples](https://docs.rual.nl/examples)

[Reference](https://docs.rual.nl/reference)

[Architecture](https://docs.rual.nl/architecture)

[Troubleshooting](https://docs.rual.nl/troubleshooting)

Other

# search

This block is part of the [`imap`](https://docs.rual.nl/block-types/imap) group and was last modified in core [`v15.0.1`](https://docs.rual.nl/core-versions/150001).

Finds messages in a mailbox and returns their UIDs, newest first. Wire the UIDs into `imap fetch` to read them. Every criterion that is filled must match.

- flow `flow`

- connection required `imapconnection`

- mailbox `value` Mailbox to search. Defaults to `INBOX`.

Default `INBOX`

- unseen only `condition` Only messages not yet marked read.

Default `false`

- flagged only `condition` Only starred / flagged messages.

Default `false`

- answered only `condition` Only messages marked answered.

Default `false`

- from `value` Substring of the From header.

- to `value` Substring of the To header.

- subject `value` Substring of the Subject header.

- text `value` Substring anywhere in the message, headers included.

- body `value` Substring of the body only.

- since `value` Arrived on or after this date. ISO date, RFC 3339, `dd-mm-yyyy` or epoch.

- before `value` Arrived before this date (exclusive).

- larger than bytes `number` Only messages larger than this many bytes.

- smaller than bytes `number` Only messages smaller than this many bytes.

- header name `value` Match one header, e.g. `List-Id`. Needs `header value`.

- header value `value` Substring the named header must contain.

- uid after `number` Only uids greater than this : pass the highest uid handled last run to poll incrementally.

- limit `number` Keep at most this many uids after ordering. 0 keeps all.

Default `0`

- newest first `condition` Order uids newest first (default). Off orders oldest first.

Default `true`

- flow `flow`

- connection `imapconnection`

- success `condition`

- error `value`

- uids `array`

- count `number`

- uid validity `number`

- uid next `number`

- messages in mailbox `number`

Runs UID SEARCH in mailbox (default INBOX) and outputs uids[] (numbers, newest first unless newest_first=false), count, uid_validity, uid_next and messages (the mailbox total). Criteria are ANDed: unseen/flagged/answered (conditions), from/to/subject/text/body (substring, case-insensitive, as the server matches), since/before (arrival date; before is exclusive; ISO date, RFC 3339, dd-mm-yyyy or epoch), larger/smaller (bytes), header_name+header_value, and uid_after : uids strictly greater than a remembered cursor, the incremental-poll criterion. limit cuts the list AFTER ordering, so limit 10 is the ten newest. Polling pattern: remember the highest uid you handled together with uid_validity; next run pass uid_after=that uid, and if uid_validity changed, the server reset the mailbox and your cursor means nothing : start over. A search that matches nothing is success=true with count 0. Suppressed in a simulation.

| `find emails` |
| --- |
| `unread` |
| `imap search` |
| `poll inbox` |

A typical wiring for [search](https://docs.rual.nl/block-types/imap/imapconnection_search): a [function trigger](https://docs.rual.nl/block-types/globals/trigger_custom_function) starts the flow; [move messages](https://docs.rual.nl/block-types/imap/imapconnection_move) feeds the `connection` pin; the `flow` out pin feeds [debug](https://docs.rual.nl/block-types/state%2520ui/state_debug).

[![Studio canvas example for the search block: typical wiring for search.](https://docs.rual.nl/canvas-examples/imapconnection_search.png)](https://docs.rual.nl/canvas-examples/imapconnection_search.png?v=3)

## Version history

Introduced in [`v15.0.1`](https://docs.rual.nl/core-versions/150001).

- [Back to `imap`](https://docs.rual.nl/block-types/imap): Return to the main group to view all sub-groups

- [Back to `imap`](https://docs.rual.nl/block-types/imap?group=imap): Return to the group to view all blocks within this group

Was this page helpful? [Tell us what to improve](https://docs.rual.nl/support) · RUAL Docs is an integral component of the [RUAL ecosystem](https://rual.nl)
