Skip to content

fix: produce working Apple Mail deep links from search results#34

Open
loukandr wants to merge 2 commits intopatrickfreyer:mainfrom
loukandr:fix-mail-link-format
Open

fix: produce working Apple Mail deep links from search results#34
loukandr wants to merge 2 commits intopatrickfreyer:mainfrom
loukandr:fix-mail-link-format

Conversation

@loukandr
Copy link
Copy Markdown

Problem

The mail_link field in search_emails results produces URLs that Apple Mail rejects with MCMailErrorDomain error 1030 when clicked. Example current output:

message:6333E88C-AEFA-4039-8CC9-B6FBBC987DDF%40andreadelis.com

Two issues:

  • Scheme is message: instead of message://.
  • The @ is percent-encoded as %40, which Apple Mail does not accept.

AppleScript's message id property 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):

  • Strip any existing angle brackets from the Message-ID.
  • Rebuild the link with message:// scheme, percent-encoded angle brackets, and raw @.

Resulting format:

message://%3C6333E88C-AEFA-4039-8CC9-B6FBBC987DDF@andreadelis.com%3E

This opens correctly in Apple Mail regardless of whether the source ID included angle brackets.

Test plan

  • python3 -m unittest discover tests passes (11/11).
  • Updated two assertions in tests/test_mail_search_tools.py to reflect the new format.
  • Verified end-to-end by pasting the generated link into an Obsidian note and clicking it: Apple Mail opens the correct message. Verified against real emails whose Message-IDs are returned without angle brackets.

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.
Copilot AI review requested due to automatic review settings April 11, 2026 18:02
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_id by stripping any existing angle brackets before building a deep link.
  • Generate Apple Mail links using message://%3C{...}%3E with @ 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.

Comment on lines 74 to 81
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",
)
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, added in 0b9db3f as test_search_emails_mail_link_normalizes_missing_angle_brackets.

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