search_by_subject
Find emails by subject text to locate specific messages in your IMAP mailbox. Specify subject, mailbox, and result limit for targeted email searches.
Instructions
Search emails by subject
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| subject | Yes | Subject text to search | |
| mailbox | No | Mailbox name (default: current) | |
| limit | No | Max results (default: 50) |
Implementation Reference
- src/imap_mcp/imap_client.py:533-549 (handler)Implementation of the `search_by_subject` tool which connects to IMAP, selects the mailbox, performs a search by subject, and returns a list of EmailHeader objects.
def search_by_subject( self, subject: str, mailbox: Optional[str] = None, limit: int = 50 ) -> list[EmailHeader]: """Search emails by subject.""" self._ensure_connected() if mailbox: self.select_mailbox(mailbox) elif not self.current_mailbox: self.select_mailbox("INBOX") uids = self.client.search(["SUBJECT", subject]) uids = sorted(uids, reverse=True)[:limit] if not uids: return [] messages = self.client.fetch(uids, ["ENVELOPE", "FLAGS", "RFC822.SIZE"]) return [self._parse_email_header(uid, data) for uid, data in messages.items()] - src/imap_mcp/server.py:561-562 (registration)Registration and invocation logic for `search_by_subject` in the MCP server handler.
elif name == "search_by_subject": return imap_client.search_by_subject(