A Ruby-based system for synchronizing Gmail/IMAP accounts to local SQLite databases and providing email analysis tools through a Model Context Protocol (MCP) server.
- Email Synchronization: Download emails from Gmail/IMAP to local SQLite database
- Raw Email Archiving: Save emails as .eml files with Gmail metadata preservation
- MCP Server: AI agent access to email database with 23+ analysis tools
- Docker Workflow: No local Ruby installation required
- Gmail Extensions: Support for X-GM-LABELS, X-GM-MSGID, X-GM-THRID
- Parallel Archive Script: Bash script for parallel email archiving
- Async Job Queue Archive: Advanced async job queue with resumability and progress tracking
- Parallel Download Script: Bash script for parallel email downloading to SQLite
- Async Job Queue Download: Advanced async job queue for downloading with resumability
# Clone the repository
git clone <repository-url>
cd nittymail
# Setup environment
cd cli
cp .env.sample .env
# Edit .env with your IMAP credentials
# List available mailboxes
docker compose run --rm cli mailbox list
# Download emails to SQLite
docker compose run --rm cli mailbox download --mailbox INBOX
# Archive emails to .eml files
docker compose run --rm cli mailbox archive --mailbox INBOX
# Download emails to SQLite database
docker compose run --rm cli mailbox download --mailbox INBOX
# Async job queue archive (recommended for large mailboxes)
./cli/bin/archive_async.sh -- --mailbox INBOX
# Async job queue download (recommended for large mailboxes)
./cli/bin/download_async.sh -- --mailbox INBOX
# Start MCP server for AI agent access
docker compose run --rm cli db mcpnittymail/
├── cli/ # Main CLI application
│ ├── commands/ # Thor-based CLI commands
│ ├── models/ # ActiveRecord models
│ ├── docs/ # CLI documentation
│ │ ├── CLI_REFERENCE.md # Complete command reference
│ │ └── MCP_TOOLS.md # MCP tools documentation
│ ├── bin/
│ │ ├── archive.sh # Parallel archive script
│ │ ├── archive_async.sh # Async job queue archive script
│ │ ├── download.sh # Parallel download script
│ │ └── download_async.sh # Async job queue download script
├── gem/ # NittyMail Ruby gem
│ └── lib/nitty_mail/ # Core IMAP/email processing
├── docs/ # Project documentation
└── AGENTS.md # AI agent development guide
- CLI Reference - Complete command reference with all options
- CLI Setup Guide - Docker setup and basic CLI usage
- MCP Tools - Documentation for all 23 MCP database tools
- Agent Guide - Development guidelines for AI agents
- Gem README - Ruby gem documentation
# List IMAP mailboxes
docker compose run --rm cli mailbox list
# Download emails to SQLite database
docker compose run --rm cli mailbox download --mailbox INBOX
# Archive emails to .eml files
docker compose run --rm cli mailbox archive --mailbox INBOX# Start MCP server for AI agents
docker compose run --rm cli db mcp --database ./emails.sqlite3# Use parallel archive script for faster email archiving
# This script spawns multiple processes to archive emails concurrently
./cli/bin/archive.sh -- --mailbox INBOX| Variable | Description | Default |
|---|---|---|
NITTYMAIL_IMAP_ADDRESS |
IMAP account email | Required |
NITTYMAIL_IMAP_PASSWORD |
IMAP password/app password | Required |
NITTYMAIL_SQLITE_DB |
SQLite database path | cli/data/[ADDRESS].sqlite3 |
NITTYMAIL_MAX_FETCH_SIZE |
IMAP batch size | 200 |
NITTYMAIL_MCP_MAX_LIMIT |
MCP query limit | 1000 |
The MCP server provides 23+ tools for email analysis:
db.list_earliest_emails,db.get_email_full,db.filter_emailsdb.search_emails(vector search stub)
db.get_email_stats,db.get_top_senders,db.get_top_domainsdb.get_largest_emails,db.get_mailbox_stats
db.get_emails_by_date_range,db.get_email_activity_heatmapdb.get_response_time_stats,db.get_seasonal_trends
db.search_email_headers,db.get_emails_by_keywordsdb.get_emails_with_attachments
db.get_emails_by_size_range,db.get_duplicate_emailsdb.execute_sql_query(read-only SQL)
- Docker and Docker Compose
- Gmail/IMAP account with IMAP enabled
- App password (for Gmail 2FA accounts)
# Run CLI tests
docker compose run --rm cli bundle exec rspec -fd -b spec/
# Run gem tests
cd gem && bundle exec rspec -fd -b
# Lint code
docker compose run --rm cli bundle exec standardrb --fixSee COPYING file for license information.
- Fork the repository
- Create a feature branch
- Make changes with tests
- Run the full test suite
- Submit a pull request
See AGENTS.md for detailed development guidelines.