search_by_date
Find emails within specific date ranges using ISO format dates to filter messages by when they were sent or received.
Instructions
Search emails by date range
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| since | No | Emails since date (ISO format) | |
| before | No | Emails before date (ISO format) | |
| mailbox | No | Mailbox name (default: current) | |
| limit | No | Max results (default: 50) |
Implementation Reference
- src/imap_mcp/imap_client.py:551-579 (handler)The search_by_date method implementation, which builds IMAP search criteria based on since/before parameters and fetches the corresponding emails.
def search_by_date( self, mailbox: Optional[str] = None, since: Optional[str] = None, before: Optional[str] = None, limit: int = 50, ) -> list[EmailHeader]: """Search emails by date range.""" self._ensure_connected() if mailbox: self.select_mailbox(mailbox) elif not self.current_mailbox: self.select_mailbox("INBOX") criteria = [] if since: criteria.extend(["SINCE", since]) if before: criteria.extend(["BEFORE", before]) if not criteria: criteria = ["ALL"] uids = self.client.search(criteria) 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:567-568 (registration)Registration and dispatch logic for the search_by_date tool in the MCP server.
elif name == "search_by_date": return imap_client.search_by_date(