Skip to content

fix: stop invalid inputs from turning move_email and manage_trash destructive - #124

Merged
patrickfreyer merged 1 commit into
patrickfreyer:mainfrom
proscar87:fix/reject-unfiltered-move-trash
Oct 16, 2026
Merged

patrickfreyer merged 1 commit into
patrickfreyer:mainfrom
proscar87:fix/reject-unfiltered-move-trash

Conversation

@proscar87

Copy link
Copy Markdown
Contributor

Two inputs made a filtered management call act on far more than it was asked to. Found while reading manage.py against the generated AppleScript.

move_email with a negative older_than_days

  • The "at least one filter is required" guard tested not older_than_days, so -1 passed it.
  • The date condition is only added for older_than_days > 0, so the generated script has no cutoff at all (if true then … move aMessage to destMailbox).
  • Result: move_email(account="Work", to_mailbox="Archive", older_than_days=-1) moved the newest max_moves (50) messages, whatever their age.
  • Fix: only a positive age counts as a filter. That's the rule update_email_status and manage_trash already use.

manage_trash with an unknown action

  • Anything other than empty_trash or delete_permanent fell through to else: # move_to_trash.
  • So manage_trash(action="list", subject_keyword="Invoice", dry_run=False) moved the matching invoices to Trash.
  • Fix: the action is validated before any script is built, with the same wording update_email_status uses for an invalid action.

Tests

  • tests/test_move_email.py (new) and InvalidActionTests in tests/test_manage_trash.py. Both fail on main and pass with the change. The 0 case already worked; the new test pins it.
  • Full suite: 261 passed. The 2 failures are the same ones on unmodified main and come from this machine: /var vs /private/var in test_create_rich_email_draft_writes_multipart_eml, and the Homebrew python3 symlink in the path-guard test. That second one looks like a real gap in the guard, and I'll send it separately.

🤖 Generated with Claude Code

…tructive

- move_email: a negative older_than_days passed the 'at least one filter'
  guard but added no date condition, so it moved the newest max_moves
  messages regardless of age. Only a positive age counts as a filter now,
  the rule update_email_status and manage_trash already use.
- manage_trash: an unrecognised action fell through to the move_to_trash
  branch, so action='list' with dry_run=False moved matches to Trash. It
  is now rejected before any script runs.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
patrickfreyer added a commit that referenced this pull request Oct 16, 2026
…t-guards

Carry #124: stop invalid inputs from turning move_email and manage_trash destructive
@patrickfreyer
patrickfreyer merged commit f8e21f5 into patrickfreyer:main Oct 16, 2026
5 checks passed

Copy link
Copy Markdown
Owner

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

Thanks @proscar87. Carried with your commits and a CHANGELOG entry, merged in #129. Closing the original.


Generated by Claude Code

proscar87 pushed a commit to proscar87/apple-mail-mcp that referenced this pull request Oct 16, 2026
@patrickfreyer patrickfreyer mentioned this pull request Oct 28, 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