Repository navigation
Add a Mail service - #239
Merged
Merged
Conversation
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.
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.
Point AppTests at the model and logging files that main moved to Shared.
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
force-pushed
the
mattt/mail-app-service
branch
from
October 21, 2026 14:11
51279df to
f8325a2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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_listlists mailboxes with their accounts.mail_messages_searchsearches by sender, subject, mailbox, date range, and read status, newest first, with a cursor for the next page.mail_messages_readreads one message's body, headers, and attachment names.mail_composeopens 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_composestill 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-serverTestsrun 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 onlyMailselectable; 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 withnextCursorwithout 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 inMailData/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.