fix: produce working Apple Mail deep links from search results#34
fix: produce working Apple Mail deep links from search results#34loukandr wants to merge 2 commits intopatrickfreyer:mainfrom
Conversation
The mail_link field built in _parse_search_records produced URLs that Apple Mail rejects with MCMailErrorDomain error 1030. Two problems: - Wrong scheme: used message: instead of message:// - Wrong encoding: percent-encoded the @ symbol as %40 AppleScript's message id property also returns the ID with or without angle brackets depending on the sending client, so the helper now normalizes by stripping any existing brackets and adding percent-encoded ones back. The resulting link opens correctly in Apple Mail. Updated the two mail_link assertions in test_mail_search_tools.py to match the new format.
There was a problem hiding this comment.
Pull request overview
Fixes Apple Mail deep links produced by search_emails so they open reliably in Apple Mail (avoiding MCMailErrorDomain error 1030) by generating a message:// URL that preserves a raw @ and normalizes Message-ID bracket formatting.
Changes:
- Normalize
internet_message_idby stripping any existing angle brackets before building a deep link. - Generate Apple Mail links using
message://%3C{...}%3Ewith@left unescaped. - Update unit test expectations for the new deep link format.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
plugin/apple_mail_mcp/tools/search.py |
Rebuilds mail_link using message:// + normalized Message-ID and URL-encoding rules compatible with Apple Mail. |
tests/test_mail_search_tools.py |
Updates assertions to match the new Apple Mail deep link format. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| self.assertEqual(response["offset"], 1) | ||
| self.assertEqual(response["returned"], 2) | ||
| self.assertTrue(response["has_more"]) | ||
| self.assertEqual(response["next_offset"], 3) | ||
| self.assertEqual( | ||
| response["items"][0]["mail_link"], | ||
| "message:%3Cabc%40example.com%3E", | ||
| "message://%3Cabc@example.com%3E", | ||
| ) |
There was a problem hiding this comment.
Consider adding a unit test case where internet_message_id is returned without angle brackets (e.g., abc@example.com) and asserting that mail_link still becomes message://%3Cabc@example.com%3E. The new normalization logic is intended to support both AppleScript return formats, but current tests only cover bracketed Message-IDs.
There was a problem hiding this comment.
Good catch, added in 0b9db3f as test_search_emails_mail_link_normalizes_missing_angle_brackets.
Problem
The
mail_linkfield insearch_emailsresults produces URLs that Apple Mail rejects withMCMailErrorDomain error 1030when clicked. Example current output:Two issues:
message:instead ofmessage://.@is percent-encoded as%40, which Apple Mail does not accept.AppleScript's
message idproperty also returns the Message-ID with or without angle brackets depending on the sending client, so the helper must normalize both forms.Fix
In
_parse_search_records(plugin/apple_mail_mcp/tools/search.py):message://scheme, percent-encoded angle brackets, and raw@.Resulting format:
This opens correctly in Apple Mail regardless of whether the source ID included angle brackets.
Test plan
python3 -m unittest discover testspasses (11/11).tests/test_mail_search_tools.pyto reflect the new format.