
# Recipes

These use [jq](https://jqlang.org/) to read fob-email's JSON. Each recipe works on one account; add `--account <name>` to the commands to choose another.

## Download every invoice from a sender

```bash
mkdir -p invoices
fob-email emails search --from billing@vendor.example --since 2026-09-01 --json \
  | jq -r '.[] | select(.hasAttachment) | .id' \
  | while read -r id; do
      fob-email emails download "$id" -o invoices
    done
```

Attachments with the same file name overwrite each other. To keep them apart, download each message into its own folder: `-o "invoices/$id"`.

## File messages into a folder

```bash
fob-email folders create Statements          # once
fob-email emails search --subject "statement" --json \
  | jq -r '.[].id' \
  | while read -r id; do
      fob-email emails move "$id" --to Statements
    done
```

Every move happens straight away. Run the search on its own first and check the list.

## Unread messages with attachments

```bash
fob-email emails list --limit 200 --json \
  | fob-email emails filter --unseen --has-attachment \
  | jq -r '.[] | "\(.id)\t\(.from.addr)\t\(.subject)"'
```

## Export the inbox to CSV

```bash
fob-email emails list --limit 500 --json \
  | jq -r '["id","date","from","subject"], (.[] | [.id, .date, .from.addr, .subject]) | @csv' \
  > inbox.csv
```

## Who emails you most

```bash
fob-email emails list --limit 500 --json \
  | jq -r 'group_by(.from.addr) | map({from: .[0].from.addr, count: length}) | sort_by(-.count) | .[:10][] | "\(.count)\t\(.from)"'
```

## Send a report with attachments

```bash
fob-email emails send --to finance@example.com \
  --subject "Invoices received, week $(date +%V)" \
  --body-file summary.txt \
  --attach invoices/INV-2291.pdf --attach invoices/INV-2304.pdf
```

## Fast repeated searches from the local copy

```bash
fob-email sync run --all-folders --limit 5000     # once, then again whenever you want fresh data
fob-email emails search --cached --from aws --since 2026-01-01
fob-email emails search --cached --subject receipt --folder Archive
```

See [Local sync](/docs/email/cli/local-sync).
