---
name: himalaya
version: 2.0.0
author: community
license: MIT
description: "Himalaya CLI: IMAP/SMTP email from terminal (v2 schema, verified against v2.2.1)."
platforms: [linux, macos, windows]
metadata:
  hermes:
    tags: [Email, IMAP, SMTP, CLI, Communication]
    homepage: https://github.com/pimalaya/himalaya
prerequisites:
  commands: [himalaya]
---

# Himalaya Email CLI (v2)

CLI email client: read, search, flag, move and send mail over IMAP/SMTP from the terminal.
Separate from the Hermes email gateway adapter (which answers inbound mail) — this skill is
for acting on the mailbox from terminal tools.

Verified against **himalaya v2.2.1**. Authoritative upstream references (local v1 copies of
these were removed on purpose — wrong beats none):
- https://github.com/pimalaya/himalaya/blob/master/MIGRATION.md (v1 -> v2)
- https://github.com/pimalaya/himalaya/blob/master/config.sample.toml

## Prerequisites

1. `himalaya --version` works (binary in `~/.local/bin`, on PATH)
2. Config at `~/.config/himalaya/config.toml` (override: `-c PATH` / env `HIMALAYA_CONFIG`)
3. Credentials reachable through a password command

```bash
curl -sSL https://raw.githubusercontent.com/pimalaya/himalaya/master/install.sh | PREFIX=$HOME/.local sh
```

## Configuration (v2 schema)

**v1 is dead:** `backend.*` tables are ignored since v2, `folder.aliases.*` renamed, `template.*`
removed. Everything lives under one `[accounts.<name>]` table (`mailbox.alias.*` may also be global).

Run `himalaya configure` (alias `wizard`) interactively — needs PTY — or write it by hand:

```toml
[accounts.work]
default = true
email = "me@example.com"
display-name = "Me"

imap.server = "imaps://imap.example.com:993"   # bare host also works, imaps:// is implied
imap.sasl.plain.username = "me@example.com"
imap.sasl.plain.password.command = "pass show mail/imap"

smtp.server = "smtps://smtp.example.com:465"   # 587 => "smtp://host:587" + smtp.starttls = true
smtp.sasl.plain.username = "me@example.com"
smtp.sasl.plain.password.command = "pass show mail/smtp"

mailbox.alias.inbox = "INBOX"
mailbox.alias.sent = "Sent"
mailbox.alias.drafts = "Drafts"
mailbox.alias.trash = "Trash"
```

- Pick exactly one SASL mechanism per side; `plain` and `login` are the usual ones.
  Password sources: `...password.command = "cmd"` / `["cmd","arg"]` (stdout = password) or
  `...password.raw` (avoid: the file then carries the secret).
- A password command that pipes (`grep … | cut …`) goes in the explicit shell form
  `["sh", "-c", "grep … | cut … | tr -d '\n\r'"]` so the shell is guaranteed regardless of how
  string commands are dispatched, and trim the trailing newline yourself. Then measure the
  command's output (`… | wc -c`) before suspecting the credential.
- Aliases are required whenever the server's names differ from the canonical roles (Gmail:
  `[Gmail]/Sent Mail`). **A missed sent-alias makes save-to-Sent fail *after* SMTP delivery
  succeeded** — a naive retry re-sends and duplicates the mail. Verify names first with
  `himalaya mailbox list`.
- Validate without sending: `himalaya account check` (per-backend PASS/FAIL).

## Common operations (v2)

### Mailboxes
```bash
himalaya mailbox list
himalaya mailbox list --counts
```

### List / search envelopes (default mailbox = inbox)
```bash
himalaya envelope list                        # newest first
himalaya envelope list -m Sent -p 1 -s 20     # --mailbox, --page, --page-size
himalaya envelope search from john@example.com subject meeting
# query grammar: and/or/not + parens + `order by date|from|to|subject [asc|desc]`
# (no `before <date>` in v2; unsupported clauses fail at parse time)
```

### Read
```bash
himalaya message read 42          # message-level info only — v2 renders NO body text
himalaya message read 42 --raw    # raw MIME: pipe into your own renderer (e.g. Python email)
```

### Send — canonical path: raw RFC 5322 on stdin
`template` is gone in v2; build the message yourself and pipe it in:
```bash
cat << 'EOF' | himalaya message send
From: Me <me@example.com>
To: them@example.com
Subject: Topic
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"

Body text with ümlauts / emoji.
EOF
```
- **PITFALL — always include `MIME-Version` + `Content-Type: text/plain; charset="utf-8"`
  (headers, then ONE empty line, then body).** Without them the default is us-ascii: the
  receiving client replaces every non-ASCII byte with U+FFFD (umlauts → two `&#65533;`,
  emoji → 4×), while the Sent copy still looks perfect — damage is only visible on the
  receiving side. Subject with non-ASCII needs RFC 2047 encoding (`=?utf-8?b?...?=`).
- Verify after sending with ONE compact jq line (Sent copy = SMTP acceptance + server-side
  copy; it does NOT prove delivery into the recipient's mailbox — that would need IMAP access
  to their account, which we don't have):
  `himalaya envelope list -m Sent -p 1 -s 1 --json | jq -r '.envelopes[0] | "id=\(.id) to=\(.to[].email) subj=\(.subject)"'`
  Subject + recipient in one row — no `message read --raw` MIME dump needed for the check.
  Do send + verify inside ONE `terminal` call (heredoc send `&&` the jq line): 1 roundtrip,
  not 3–4.
- Attachments: build the MIME yourself (Python `email` module), then feed path/inline/stdin to
  `message send`.
- Flag-based helpers exist for the simple cases: `himalaya message compose|reply|forward`
  (read `--help` for their flags).
- Sent copy: `message send --save Sent` / `--no-save`; default comes from
  `message.send.save-copy`. Enable only after `mailbox.alias.sent` is verified.

### Reply with threading headers
```bash
cat << EOF | himalaya message send
From: Me <me@example.com>
To: sender@example.com
Subject: Re: Original Subject
In-Reply-To: <original-message-id>
References: <original-message-id>

Your reply.
EOF
```

### Move / copy / delete
```bash
himalaya message move --to Archive 42      # -f/--from defaults to the inbox alias
himalaya message copy --to Archive 42
himalaya message delete 42                 # trashes first
```

### Flags
```bash
himalaya flag add --flag seen 42
himalaya flag remove --flag seen 42
```

### Attachments
```bash
himalaya attachment list 42
himalaya attachment download 42            # all attachments; or pass an attachment id
himalaya attachment download 42 --dir ~/Downloads
```

### Output & debugging
```bash
himalaya envelope list --json           # v2 global flag; `--output json|plain` is gone
# PITFALL: `--output json` hard-fails in v2 (Usage error = wasted roundtrip). Shape is
# {"queued":N,"envelopes":[…]}, NOT a flat array → `jq '.[0]'` returns nothing; use `.envelopes[0]`.
himalaya envelope list --log-level debug   # was RUST_LOG=...
himalaya envelope list --log-level trace
```
- **Mojibake-Beschwerden („komische Zeichen“) lokalisierten:** erst die Send-Kopie als
  Roh-MIME holen — `himalaya message read <id> -m Sent --raw`. Body-Bytes korrekt, aber
  `Content-Type`/`charset` fehlt → Charset-Header beim Senden ergänzen (siehe Send-Pitfall).
  Body-Bytes selbst kaputt → der Fehler lag schon in der Texterzeugung, nicht im Mail-Stack
  (Erzeugung prüfen, nicht den Versandweg).

## Hermes integration notes
- Read/list/search/move/flag: plain `terminal` calls, no PTY.
- `himalaya configure` is interactive -> PTY mode only.
- Message ids are per-mailbox in v2 -> re-list after changing mailboxes.
- Multiple accounts: `-a <name>`; list with `himalaya account list`.
- Never put passwords in commands or chat: always `...password.command` reading a 600 file
  (here: `grep '^EMAIL_PASSWORD=' /opt/data/.env | cut -d= -f2-`, one secret, one source).

## Tips
- `himalaya <command> --help` is the authoritative v2 flag list — bundled/old docs are v1.
- The real send test is the round trip: after sending, check `envelope list -m Sent`.
- Ids are relative to the current mailbox. On "AUTHENTICATE PLAIN failed" go in this order:
  measure the password command's output (`… | wc -c`), then try the same value straight at the
  server with Python `imaplib`/`smtplib` with every output masked — that separates a wrong value
  (rotate it at the provider) from himalaya plumbing, which `account check` alone cannot.
