Let AI agents unsubscribe from mailing lists the way each message says #30

Merged
merge-queue merged 1 commit from agent-unsubscribe into main 2026-11-18 10:02:37 -08:00
Owner

Work package: https://openproject.home.romaine.life/wp/TUI-16

Lets an AI agent unsubscribe the user from mailing lists, when the user asks it to. Until now agents saw links only as their site and had no call that opens links or sends, so they couldn't.

Added

  • An unsubscribe MCP tool (agent::Call::Unsubscribe, ids from search_messages, at most 50 a call, deny_unknown_fields). For each message, tuimail reads its head (from the cache, else one download shared with reads, within the download limits) and does what its List-Unsubscribe says:
    • one-click: when List-Unsubscribe-Post is exactly List-Unsubscribe=One-Click (RFC 8058), it POSTs that body, application/x-www-form-urlencoded, to the https link over tuimail's own TLS (net::connect). Limits: a 30 s time limit, only the answer's head read (capped at 16 KB), no redirect followed, on a background task. The host must be a name on port 443 (not an IP address or this computer) and must match the site link_host shows. A 2xx answer means done.
    • email: otherwise, it sends "unsubscribe" to the mailto:'s one address only (the subject comes from the link, else "unsubscribe"). It goes out through the account's SMTP (worker::send), from the account the mail came to, with a copy kept in Sent. A link that names more than one address is refused.
    • needs the user: an https link without one-click is never opened. The user is asked as U asks (Confirm::OpenLink, now naming the agent that asked), but only when nothing else is open; otherwise the agent is just told.
    • none: no List-Unsubscribe.
  • The answer gives each message's way, its site or the address's domain (never the URL or the address), and the outcome.
  • Asked first like a change is when "ask before each change an agent makes" is on, and the question says it can't be undone. A new UNSUBSCRIBES_PER_HOUR limit (200) applies; unsubscribes don't count against the change limits. Refused while agents are off, like every call.
  • Failures are logged as op="unsubscribing" by class only (Class::Http(status), timeout, TLS…). SMTP failures are logged by worker::send, as before.
  • http.rs: oauth.rs's HTTP/1.1 form POST and answer parsing, moved out to be shared, plus post_for_status, which reads only the head.
  • unsubscribe.rs: which way to unsubscribe (way), the one-click target checks, the mailto draft, and the POST. mail::unsubscribe_of parses only the head.
  • Tests: RFC 8058 detection, the target checks, the request's exact bytes over a pipe, a mailto draft going only to its one address, the limits, and app-level wiring (the question and y, the sent message's recipients, a copy in Sent, each way's answer, the OpenLink question, the download path).

Changed

  • mcp::INSTRUCTIONS (1,367 of 2,048 characters): agents may unsubscribe only when the user asks, should use mark_spam for spam, and are told unsubscribe does only what a list's own header offers. The tool's description warns that unsubscribing from real spam confirms the address.
  • CLAUDE.md: the Security "AI agents" bullet no longer says there's no call that sends or opens links, and now describes the new call and its limits. The Architecture section on agents and the http.rs references are updated. The README's AI agents section is updated too.
  • SentCopy gains agent, and on_sent's Sent copy is now keep_sent_copy. The agent read's download is now agent_download.

Left alone

  • The user's own U key and its composer and confirmation behave as before.
  • Agents still can't write, reply, forward, delete for good, open links or attachments, or make filters.
  • DKIM isn't checked: RFC 8058 asks senders to sign these headers. With a forged header, the most that happens is one POST of the fixed body to a public https site on 443, with nothing of the user's in it.
Work package: https://openproject.home.romaine.life/wp/TUI-16 Lets an AI agent unsubscribe the user from mailing lists, when the user asks it to. Until now agents saw links only as their site and had no call that opens links or sends, so they couldn't. ## Added - An `unsubscribe` MCP tool (`agent::Call::Unsubscribe`, ids from search_messages, at most 50 a call, `deny_unknown_fields`). For each message, tuimail reads its head (from the cache, else one download shared with reads, within the download limits) and does what its List-Unsubscribe says: - **one-click:** when List-Unsubscribe-Post is exactly `List-Unsubscribe=One-Click` (RFC 8058), it POSTs that body, `application/x-www-form-urlencoded`, to the https link over tuimail's own TLS (`net::connect`). Limits: a 30 s time limit, only the answer's head read (capped at 16 KB), no redirect followed, on a background task. The host must be a name on port 443 (not an IP address or this computer) and must match the site `link_host` shows. A 2xx answer means done. - **email:** otherwise, it sends "unsubscribe" to the `mailto:`'s one address only (the subject comes from the link, else "unsubscribe"). It goes out through the account's SMTP (`worker::send`), from the account the mail came to, with a copy kept in Sent. A link that names more than one address is refused. - **needs the user:** an https link without one-click is never opened. The user is asked as `U` asks (`Confirm::OpenLink`, now naming the agent that asked), but only when nothing else is open; otherwise the agent is just told. - **none:** no List-Unsubscribe. - The answer gives each message's way, its site or the address's domain (never the URL or the address), and the outcome. - Asked first like a change is when "ask before each change an agent makes" is on, and the question says it can't be undone. A new `UNSUBSCRIBES_PER_HOUR` limit (200) applies; unsubscribes don't count against the change limits. Refused while agents are off, like every call. - Failures are logged as `op="unsubscribing"` by class only (`Class::Http(status)`, timeout, TLS…). SMTP failures are logged by `worker::send`, as before. - `http.rs`: oauth.rs's HTTP/1.1 form POST and answer parsing, moved out to be shared, plus `post_for_status`, which reads only the head. - `unsubscribe.rs`: which way to unsubscribe (`way`), the one-click target checks, the mailto draft, and the POST. `mail::unsubscribe_of` parses only the head. - Tests: RFC 8058 detection, the target checks, the request's exact bytes over a pipe, a mailto draft going only to its one address, the limits, and app-level wiring (the question and `y`, the sent message's recipients, a copy in Sent, each way's answer, the OpenLink question, the download path). ## Changed - `mcp::INSTRUCTIONS` (1,367 of 2,048 characters): agents may unsubscribe only when the user asks, should use mark_spam for spam, and are told unsubscribe does only what a list's own header offers. The tool's description warns that unsubscribing from real spam confirms the address. - CLAUDE.md: the Security "AI agents" bullet no longer says there's no call that sends or opens links, and now describes the new call and its limits. The Architecture section on agents and the http.rs references are updated. The README's AI agents section is updated too. - `SentCopy` gains `agent`, and `on_sent`'s Sent copy is now `keep_sent_copy`. The agent read's download is now `agent_download`. ## Left alone - The user's own `U` key and its composer and confirmation behave as before. - Agents still can't write, reply, forward, delete for good, open links or attachments, or make filters. - DKIM isn't checked: RFC 8058 asks senders to sign these headers. With a forged header, the most that happens is one POST of the fixed body to a public https site on 443, with nothing of the user's in it.
Let AI agents unsubscribe from mailing lists the way each message says
All checks were successful
merge-queue landed on main
Suite release / scope (pull_request) Successful in 6s
Suite rust / check-test-linux (pull_request) Has been skipped
Suite rust / check-typos (pull_request) Has been skipped
Suite rust / check-machete (pull_request) Has been skipped
Suite rust / check-audit (pull_request) Has been skipped
Suite default / check-fetches (pull_request) Has been skipped
Suite default / check-rules (pull_request) Has been skipped
Suite release / module (pull_request) Has been skipped
Suite release / reserve (pull_request) Has been skipped
Suite release / build (rust, aarch64-pc-windows-msvc) (, rust-aarch64-pc-windows-msvc, false, windows-latest, aarch64-pc-windows-msvc, rust) (pull_request) Has been skipped
Suite release / build (rust, aarch64-unknown-linux-gnu) (, rust-aarch64-unknown-linux-gnu, false, ubuntu-latest, aarch64-unknown-linux-gnu, rust) (pull_request) Has been skipped
Suite release / build (rust, x86_64-pc-windows-msvc) (, rust-x86_64-pc-windows-msvc, false, windows-latest, x86_64-pc-windows-msvc, rust) (pull_request) Has been skipped
Suite release / build (rust, x86_64-unknown-linux-gnu) (, rust-x86_64-unknown-linux-gnu, false, ubuntu-latest, x86_64-unknown-linux-gnu, rust) (pull_request) Has been skipped
Suite release / finalize (pull_request) Has been skipped
Suite release / home-sync (pull_request) Has been skipped
Suite release / publish (pull_request) Has been skipped
Suite release / dispatch (pull_request) Has been skipped
Suite release / deploy-image (pull_request) Has been skipped
Suite default / reused-checks (pull_request) Successful in 6s
Suite rust / check-format (pull_request) Successful in 8s
Suite release / check-build (rust, aarch64-unknown-linux-gnu) (, rust-aarch64-unknown-linux-gnu, false, ubuntu-latest, aarch64-unknown-linux-gnu, rust) (pull_request) Successful in 1m40s
Suite rust / check-services (pull_request) Successful in 2m9s
Suite rust / check-test-windows (pull_request) Successful in 2m18s
Suite rust / reused-checks (pull_request) Successful in 6s
Suite release / check-build (rust, x86_64-pc-windows-msvc) (, rust-x86_64-pc-windows-msvc, false, windows-latest, x86_64-pc-windows-msvc, rust) (pull_request) Successful in 2m36s
Suite release / check-build (rust, x86_64-unknown-linux-gnu) (, rust-x86_64-unknown-linux-gnu, false, ubuntu-latest, x86_64-unknown-linux-gnu, rust) (pull_request) Successful in 2m38s
Suite release / check-build (rust, aarch64-pc-windows-msvc) (, rust-aarch64-pc-windows-msvc, false, windows-latest, aarch64-pc-windows-msvc, rust) (pull_request) Successful in 3m23s
Suite release / check-package (pull_request) Successful in 8s
Suite release / reused-checks (pull_request) Successful in 4s
e32a78aacc
An unsubscribe tool for agents: one click where List-Unsubscribe-Post offers
it (RFC 8058), else mail to the list's one address, else the page is left to
the user. Asked first as changes are, at most 200 messages an hour. The
HTTP/1.1 POST moves from oauth.rs to http.rs, shared by both.
merge-queue deleted branch agent-unsubscribe 2026-11-18 10:02:37 -08:00
Sign in to join this conversation.
No description provided.