- Add configuration system with automatic file discovery (current dir, config subdir, user home, XDG config) - Implement IMAP client with TLS connection, authentication, and mailbox listing - Add CouchDB integration with database creation and document storage - Support folder filtering (include/exclude) and date filtering (since parameter) - Include duplicate detection to prevent re-storing existing messages - Add comprehensive error handling and logging throughout - Structure code in clean packages: config, mail, couch - Application currently uses placeholder messages to test the storage pipeline - Ready for real IMAP message parsing implementation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
4.5 KiB
4.5 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
mail2couch is a utility for backing up mail from various sources (primarily IMAP) to CouchDB. The project supports two implementations:
- Go implementation: Located in
/go/directory (currently the active implementation) - Rust implementation: Planned but not yet implemented
Development Commands
Go Implementation (Primary)
# Build the application
cd go && go build -o mail2couch .
# Run the application with automatic config discovery
cd go && ./mail2couch
# Run with specific config file
cd go && ./mail2couch -config /path/to/config.json
# Run linting/static analysis
cd go && go vet ./...
# Run tests (currently no tests exist)
cd go && go test ./...
# Check dependencies
cd go && go mod tidy
Architecture
Core Components
-
Configuration (
config/): JSON-based configuration system- Supports multiple mail sources with filtering options
- CouchDB connection settings
- Each source can have folder and message filters
-
Mail Handling (
mail/): IMAP client implementation- Uses
github.com/emersion/go-imap/v2for IMAP operations - Supports TLS connections
- Currently only lists mailboxes (backup functionality not yet implemented)
- Uses
-
CouchDB Integration (
couch/): Database operations- Uses
github.com/go-kivik/kivik/v4as CouchDB driver - Handles database creation and document management
- Defines
MailDocumentstructure for email storage
- Uses
Configuration Structure
The application uses config.json for configuration with the following structure:
couchDb: Database connection settings (URL, credentials, database name)mailSources: Array of mail sources with individual settings:- Protocol support (currently only IMAP)
- Connection details (host, port, credentials)
- Filtering options for folders and messages
- Enable/disable per source
Configuration File Discovery
The application automatically searches for configuration files in the following order:
- Path specified by
-configcommand line flag ./config.json(current working directory)./config/config.json(config subdirectory)~/.config/mail2couch/config.json(user XDG config directory)~/.mail2couch.json(user home directory)
This design ensures the same config.json format will work for both Go and Rust implementations.
Current Implementation Status
- ✅ Configuration loading with automatic file discovery
- ✅ Command line flag support for config file path
- ✅ CouchDB client initialization and database creation
- ✅ IMAP connection and mailbox listing
- ✅ Build error fixes
- ✅ Email message retrieval framework (with placeholder data)
- ✅ Email storage to CouchDB framework
- ✅ Folder filtering logic
- ✅ Date filtering support
- ✅ Duplicate detection and prevention
- ❌ Real IMAP message parsing (currently uses placeholder data)
- ❌ Full message body and attachment handling
- ❌ Incremental sync functionality
- ❌ Rust implementation
Key Dependencies
github.com/emersion/go-imap/v2: IMAP client librarygithub.com/go-kivik/kivik/v4: CouchDB client library
Development Notes
- The main entry point is
main.gowhich orchestrates the configuration loading, CouchDB setup, and mail source processing - Each mail source is processed sequentially with proper error handling
- The application currently uses placeholder message data for testing the storage pipeline
- Message filtering by folder (include/exclude) and date (since) is implemented
- Duplicate detection prevents re-storing existing messages
- No tests are currently implemented
- The application uses automatic config file discovery as documented above
Next Steps
To complete the implementation, the following items need to be addressed:
- Real IMAP Message Parsing: Replace placeholder message generation with actual IMAP message fetching and parsing using the correct go-imap/v2 API
- Message Body Extraction: Implement proper text/plain and text/html body extraction from multipart messages
- Attachment Handling: Add support for email attachments (optional)
- Error Recovery: Add retry logic for network failures and partial sync recovery
- Performance: Add batch operations for better CouchDB insertion performance
- Testing: Add unit tests for all major components
Development Guidelines
Code Quality and Standards
- All code requires perfect linting and tool-formatting, exceptions are allowed only if documented properly