Mail Invoice Archiver
by @amortalsodyssey
Read supported mailbox providers such as 126, 163, and Gmail, identify invoice attachments or invoice download links, archive invoices by month, deduplicate...
clawhub install mail-invoice-archiver-skillš About This Skill
name: mail_invoice_archiver description: Read supported mailbox providers such as 126, 163, and Gmail, identify invoice attachments or invoice download links, archive invoices by month, deduplicate by invoice number and amount, and prepare monthly reports plus delivery bundles. Use when OpenClaw needs to sync invoice mail, investigate failed downloads, package a month's archive, or summarize totals and high-value invoices. metadata: {"openclaw":{"name":"mail_invoice_archiver","displayName":"Mail Invoice Archiver","requires":["python3"],"requiresNetwork":true}}
Mail Invoice Archiver
Quick Start
python3 {baseDir}/scripts/cli.py providers --json when you need to show the currently supported mailbox providers and their setup notes.python3 {baseDir}/scripts/cli.py doctor --json first. If it returns setup_required: true, guide the user through setup and wait for confirmation.python3 {baseDir}/scripts/cli.py setup for an interactive setup wizard, or pass --mail-provider 126|163|gmail|custom plus --provider system|env|config|prompt for scripted setup.python3 {baseDir}/scripts/cli.py sync --month YYYY-MM --json to pull a month into the local archive.python3 {baseDir}/scripts/cli.py report --month YYYY-MM --json to inspect totals, duplicates, conflicts, and failures.python3 {baseDir}/scripts/cli.py deliver --month YYYY-MM --json to prepare a zip plus summary for the current chat.Workflow
1. Run doctor.
2. If doctor reports setup_required, ask the user which mailbox provider they want first:
126, 163, gmail, or custom.
3. Ask the user which auth mode they want:
system credential store, environment variables, config file, or prompt-each-session.
4. Run setup with the chosen mailbox provider and auth mode, then wait for the user to confirm they completed any external steps, such as exporting environment variables.
4. Run doctor again to confirm the setup works.
5. Run list --month YYYY-MM --limit 20 --json when you need a quick mailbox preview without downloading files.
6. Run sync --month YYYY-MM --json to archive candidate invoices into ~/Documents/invoice-archive/YYYY-MM/.
7. Run report --month YYYY-MM --json after sync and summarize:
total amount, canonical invoice count, high-value invoices, duplicates, conflicts, and failures.
8. Run deliver --month YYYY-MM --json, then attach the returned zip file in the current chat and paste the summary.
Windows Env Setup
env on Windows, offer one of these exact snippets and wait for confirmation before rerunning doctor.$env:MAIL_INVOICE_ARCHIVER_EMAIL = "your-mail@example.com"
$env:MAIL_INVOICE_ARCHIVER_AUTH_CODE = "your-provider-secret"
python "{baseDir}/scripts/cli.py" doctor --json
set MAIL_INVOICE_ARCHIVER_EMAIL=your-mail@example.com
set MAIL_INVOICE_ARCHIVER_AUTH_CODE=your-provider-secret
python "{baseDir}\scripts\cli.py" doctor --json
MAIL_INVOICE_ARCHIVER_AUTH_CODE must be a Gmail app password, not the normal Google account password.Rules
system auth on macOS and Windows, env on Linux, CI, or headless sessions, and prompt only when the user does not want to persist the secret anywhere.system currently means macOS Keychain on macOS and Windows Credential Manager on Windows.126, 163, and gmail.appleimap.126.com as the preferred 126 IMAP host.ID only when that provider needs it. Today that means 126 and 163; Gmail does not need it.invoice number + amount.
Ā„ amount. PDF text extraction may reorder the invoice area and expose tax base amount, tax amount, and total amount in the wrong sequence.åē§°ļ¼ åē§°ļ¼ layouts after text extraction. Prefer layout-aware extraction over a single regex when distinguishing buyer and seller.duplicate against an older canonical row outside the month window. Summaries should aggregate by current-month business keys, not only by status='saved' rows inside the month.ä»·ēØåč®” for totals, record and honor that rule consistently in later extraction and reporting.Resources
Local Secret Config Convention
When this skill needs Feishu app credentials for local delivery helpers or follow-up integrations, do not store real secrets inside the published skill directory.
Use this split instead:
config/feishu/config.example.yaml~/.config/openclaw/mail_invoice_archiver/feishu.config.yamlWhy this rule exists:
.gitignore reduces Git commit risk, but should not be treated as the security boundary for skill publishing.Recommended loading order for Feishu credentials:
1. explicit environment variables
2. local private config at ~/.config/openclaw/mail_invoice_archiver/feishu.config.yaml
3. prompt the user
Environment variable names:
MAIL_INVOICE_ARCHIVER_FEISHU_APP_IDMAIL_INVOICE_ARCHIVER_FEISHU_APP_SECRETMAIL_INVOICE_ARCHIVER_FEISHU_RECEIVE_ID_TYPEMAIL_INVOICE_ARCHIVER_FEISHU_CONFIGNever publish or share the real local config file.
If config/feishu/config.yaml appears inside the skill directory, treat it as an unsafe misconfiguration. The runtime should fail fast and require moving that file out of the skill.
š” Examples
python3 {baseDir}/scripts/cli.py providers --json when you need to show the currently supported mailbox providers and their setup notes.python3 {baseDir}/scripts/cli.py doctor --json first. If it returns setup_required: true, guide the user through setup and wait for confirmation.python3 {baseDir}/scripts/cli.py setup for an interactive setup wizard, or pass --mail-provider 126|163|gmail|custom plus --provider system|env|config|prompt for scripted setup.python3 {baseDir}/scripts/cli.py sync --month YYYY-MM --json to pull a month into the local archive.python3 {baseDir}/scripts/cli.py report --month YYYY-MM --json to inspect totals, duplicates, conflicts, and failures.python3 {baseDir}/scripts/cli.py deliver --month YYYY-MM --json to prepare a zip plus summary for the current chat.š Constraints
system auth on macOS and Windows, env on Linux, CI, or headless sessions, and prompt only when the user does not want to persist the secret anywhere.system currently means macOS Keychain on macOS and Windows Credential Manager on Windows.126, 163, and gmail.appleimap.126.com as the preferred 126 IMAP host.ID only when that provider needs it. Today that means 126 and 163; Gmail does not need it.invoice number + amount.
Ā„ amount. PDF text extraction may reorder the invoice area and expose tax base amount, tax amount, and total amount in the wrong sequence.åē§°ļ¼ åē§°ļ¼ layouts after text extraction. Prefer layout-aware extraction over a single regex when distinguishing buyer and seller.duplicate against an older canonical row outside the month window. Summaries should aggregate by current-month business keys, not only by status='saved' rows inside the month.ä»·ēØåč®” for totals, record and honor that rule consistently in later extraction and reporting.