Skip to content

Add a Mail service - #239

Merged
mattt merged 18 commits into
mainfrom
mattt/mail-app-service
Oct 22, 2026
Merged

mattt merged 18 commits into
mainfrom
mattt/mail-app-service

Conversation

@mattt

@mattt mattt commented Sep 21, 2026 •

Copy link
Copy Markdown
Owner

Mail has no public API for reading messages, so assistants connected to iMCP can't search or read mail stored on the Mac. This PR adds a Mail service that reads Mail's local index and message files with the Envelope package and never writes to them.

The service adds four tools. mail_mailboxes_list lists mailboxes with their accounts. mail_messages_search searches by sender, subject, mailbox, date range, and read status, newest first, with a cursor for the next page. mail_messages_read reads one message's body, headers, and attachment names. mail_compose opens a new draft in the default email app; it doesn't save or send anything.

Reading mail needs access to ~/Library/Mail. When Mail is turned on, iMCP asks for that folder and keeps a security-scoped bookmark so that later launches can read it without asking again. Without folder access, mail_compose still works. Reads use a read-only SQLite connection in WAL mode, one connection at a time, with time limits on each statement and each read, so iMCP doesn't change the index or run checkpoints. Errors reach clients as readable messages, and compose URLs reject header injection.

The README adds Mail to the service table with its icon, adds it to the hero images, and describes folder access, search, and pagination in a new section. Tests in imcp-serverTests run the tools against a synthetic Mail store in WAL mode, covering mailbox listing, search filters, date ranges, pagination, and message reads.

I tested a sandboxed, ad hoc signed Debug build of this branch against a real Mail store on macOS 27. Turning Mail on opened the folder picker in ~/Library, with only Mail selectable; before e8dbd70 it opened in the app's sandbox container. After I chose ~/Library/Mail, a stdio client listed mailboxes, searched all mail newest first, paged with nextCursor without repeats, searched a 7-day range with a UTC offset and a date-only range, filtered by mailbox and by unread state, and read recent messages, with each search returning in under 0.1 s. One message that Mail had only partly downloaded returned "Mail has downloaded only part of the message. Open the message in Mail to download it." After quitting and reopening the app, the same checks passed without the picker, using the stored bookmark, and the search saw new mail that had arrived in the meantime. With Envelope 0.3.0, no mailbox reported an account email, because current Mail stores write an IMAP account's address as the host of its account URL in MailData/Signatures/AccountsMap.plist. This PR requires Envelope 0.3.1, which reads that form (mattt/Envelope#5). With it, 9 of the store's 10 accounts reported an address; the tenth, a recently reconnected and disabled account, has no entry in Mail's account map.

The service reads the local Mail Envelope Index and .emlx files through a read-only, security-scoped bookmark on ~/Library/Mail. Composition opens a mailto URL in the default email app and needs no folder access.

This comment was marked as resolved.

Use the remote package instead of a local checkout, and adopt Mail.Store.
Search pagination now uses cursors, so mail_messages_search replaces
offset with cursor and returns nextCursor.
@mattt
mattt requested a balanced review from Copilot October 16, 2026 12:56
@mattt
mattt marked this pull request as ready for review October 16, 2026 12:57
mattt added 2 commits October 16, 2026 06:00
Point AppTests at the model and logging files that main moved to Shared.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Live Mail database access and persistent sandbox permissions need macOS runtime validation and final human review.

2 open findings
2 resolved since last review

🧠 Review effort: Balanced

Comment thread App/Services/Mail.swift Resolved
Comment thread App/Services/Mail.swift Resolved
mattt added 3 commits October 16, 2026 06:03
Depend on the single Envelope product, create the store from the resolved
Mail folder URL, and use Mailbox.ID for mailbox identifiers, so mailbox
@id values now include the store, such as "V10:12".
@mattt mattt changed the title Add a Mail service to search, read, and compose email Add a Mail service Oct 17, 2026
@mattt
mattt force-pushed the mattt/mail-app-service branch from 51279df to f8325a2 Compare October 21, 2026 14:11
@mattt
mattt merged commit 8c2ea8e into main Oct 22, 2026
2 checks passed
@mattt
mattt deleted the mattt/mail-app-service branch October 22, 2026 15:04
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