Skip to content

feat: message_ids on manage_trash for exact-id move to trash - #150

Merged
patrickfreyer merged 1 commit into
patrickfreyer:mainfrom
PodioSpaz:feat/manage-trash-message-ids
Nov 18, 2026
Merged

patrickfreyer merged 1 commit into
patrickfreyer:mainfrom
PodioSpaz:feat/manage-trash-message-ids

Conversation

@PodioSpaz

Copy link
Copy Markdown
Contributor

Adds an optional message_ids argument to manage_trash(action="move_to_trash"), matching the one move_email got in #50.

Why

Today the only way to trash specific messages is to filter by sender / subject_keywords and hope the preview catches only the ones you mean. With recurring subjects (statements, digests, "Your order has shipped") the filter also catches older mail. A triage workflow then has to narrow the filters until the dry-run count matches, or give up on that group. In one real inbox triage run, 99 of 364 queued messages couldn't be trashed or archived safely for this reason. The caller already had the exact ids from search_emails.

What changed

  • manage_trash(..., message_ids=[...]), for action="move_to_trash" only. When set, subject, sender, age filters and apply_to_all are ignored, as in move_email.
  • Direct lookup, no whose. Each id is looked up with «class mssg» id N of mailbox inside the loop, following the guidance in enhancement: id-based read_email and attachment tools, and a size guard for search output #128 and search_emails on large INBOX causes Mac Mail UI to hang and returns empty results #41. The lookup is never a whose scan over the mailbox or a reference list captured up front.
  • Id re-read before each move. The resolved message's id is read again right before the move and must equal the requested id. I added this because I have seen a loop that looked messages up by id while removing them from the same mailbox trash the wrong messages. That loop used first message whose id is N plus delete, not this tool. The re-read check makes that kind of mistake fail safely.
  • Re-check after a real run. Every id is looked up again afterward and reported as STILL PRESENT: N, plus a Still in mailbox: <id> line for each one, so callers can confirm the result.
  • Safety limits.
    • The number of ids can't exceed max_deletes.
    • Non-numeric ids are dropped and duplicates are removed, using the existing normalize_message_ids helper.
    • Ids that aren't in the mailbox are listed as Not found: <id>.
    • The output ends with REQUESTED: n id(s), MATCHED: k, like move_email.
  • dry_run=True stays the default and previews without moving anything.
  • A CHANGELOG entry under Unreleased → Added.

The change only adds an argument with a default. No existing tool names or required arguments change.

Testing

  • PYTHONPATH=plugin python -m pytest tests/ -q: 315 passed, 1 failed. The failure is test_compose_tools.py::test_create_rich_email_draft_writes_multipart_eml, which also fails on main on macOS: the temp directory resolves to /private/var/... while the test expects /var/.... It's unrelated to this change.
  • 9 new tests in tests/test_manage_trash.py cover:
    • dry run vs. real run
    • each lookup happening inside the loop, with the id re-checked before the move
    • no whose in the generated script
    • other filters ignored
    • id normalization
    • the empty-id, non-numeric-id, over-max_deletes and wrong-action errors
  • scripts/check_versions.py passes. The generated AppleScript compiles with osacompile for both dry and real runs.
  • Live run on macOS (iCloud IMAP account): I moved 8 messages into a scratch mailbox and trashed 5 of them by id in one call (positions 1, 3, 5, 7 and 8), plus one id that doesn't exist.
    • Exactly those 5 went to Trash, and the other 3 stayed.
    • The 3 kept messages included a near-duplicate subject ("…forecast for 11/13…" stayed while "…forecast for 11/14…" was trashed).
    • The fake id was reported as Not found, and STILL PRESENT: 0.
    • I also checked that the presence lookup finds a message that is still there.

Related

🤖 Generated with Claude Code

Callers that already know which messages to trash can pass their ids
instead of narrowing subject/sender filters. Each id is resolved with
a direct lookup (no whose scan) and re-read right before the move; a
real run then re-checks every id and reports any still in the source
mailbox. The id count must not exceed max_deletes. Mirrors the
message_ids path on move_email.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
patrickfreyer added a commit that referenced this pull request Nov 18, 2026
carry #150: message_ids on manage_trash for exact-id move to trash
@patrickfreyer
patrickfreyer merged commit b24efc8 into patrickfreyer:main Nov 18, 2026

Copy link
Copy Markdown
Owner

Posted by Claude (AI maintainer agent) on Patrick's behalf.

Thank you @PodioSpaz! This is merged via #151, which carries your commit unchanged plus a merge of current main. 3.4.0 had moved the old [Unreleased] section, so your CHANGELOG entry now sits in the new [Unreleased] with credit. The re-read before each move and the STILL PRESENT check afterwards are a good addition for a destructive path, and the live iCloud run was helpful. Closing this in favour of #151.


Generated by Claude Code

@patrickfreyer patrickfreyer mentioned this pull request Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants