Count matching mail
count_mailCount messages in a folder that match search filters and return only the total, without listing messages or marking them read.
Instructions
Count the messages in one folder that match search_mail's filters; returns a number, not messages, and marks nothing read.
Use it for "how many" questions and to size a change before preview_action; use search_mail to list or read the messages. It takes search_mail's filters, unread_only, exclusions and query, with no paging.
Cheap: IMAP UID SEARCH only (one command, plus one per extra non-ASCII value); it never fetches headers or bodies. Bridge matches every condition itself: from, to and subject compare raw header text, so encoded non-ASCII headers can count lower than search_mail finds. Header and text conditions make Bridge read each message in the folder; dates and unread_only do not. All Mail gets no default date window here. Counts come from live IMAP, not the header cache, so index_note and index_status never appear, even during a rebuild. It uses at most 20 seconds overall and 10 seconds per IMAP command (shorter configured limits win).
Returns folder and count. A timeout returns count=0 with partial=true, timed_out=true, partial_reason and error: the count is incomplete and must not be read as an empty folder. Narrower dates do not help a timeout with these conditions: use search_mail.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| to | No | To header contains this text, ignoring case. | |
| text | No | Raw message contains this, ignoring case. Bridge reads the whole folder to answer, whatever the dates, which a large folder may not finish in time. | |
| from_ | No | Sender contains this text, ignoring case. | |
| query | No | Conditions joined with and, or and not; the entries of one object all apply. from, to, subject and text match substrings; and and or take a list of 1 to 20 queries, not takes one query. At most 20 conditions in 5 nested levels. For example {"or": [{"from": "a@example.test"}, {"subject": "invoice", "not": {"text": "unsubscribe"}}]}. | |
| since | No | Earliest date, inclusive, as YYYY-MM-DD. | |
| before | No | Latest date, exclusive, as YYYY-MM-DD. | |
| folder | No | The mailbox to search, by its exact LIST name, such as INBOX, Archive, Sent, All Mail, Folders/Receipts or Labels/Work. | INBOX |
| subject | No | Subject contains this text, ignoring case. | |
| unread_only | No | Only unread messages. Takes only a JSON boolean. | |
| exclude_text | No | Leave out messages whose text contains this, as Bridge matches it. | |
| exclude_subject | No | Leave out messages whose subject contains this text. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||