Add IMAP to Nextcloud Calendar importer

- IMAP mailbox monitoring with SSL/TLS, STARTTLS and plain connection support
- ICS attachment extraction from emails and import to Nextcloud via CalDAV
- Create or update calendar events by UID to avoid duplicates
- Event filtering by summary (contains, regex or exact match, with inversion)
- Deduplication by regex pattern extracted from event summaries
- Move or mark processed emails as seen after import
- Continuous polling mode and one-time run mode
- Fully configurable via environment variables
- Docker and Docker Compose support
- Test suite with pytest
This commit is contained in:
2026-01-06 21:50:45 +00:00
commit c87a99f570
10 changed files with 1695 additions and 0 deletions

52
.env.sample Normal file
View File

@@ -0,0 +1,52 @@
# IMAP Configuration
IMAP_SERVER=imap.example.com
IMAP_PORT=993
IMAP_EMAIL=your-email@example.com
IMAP_PASSWORD=your-password
IMAP_MAILBOX=INBOX
IMAP_PROCESSED_FOLDER=Processed
# IMAP Security Options
# For SSL/TLS (port 993): IMAP_USE_SSL=true, IMAP_USE_STARTTLS=false
# For STARTTLS (port 143): IMAP_USE_SSL=false, IMAP_USE_STARTTLS=true
# For plain (NOT RECOMMENDED): IMAP_USE_SSL=false, IMAP_USE_STARTTLS=false
IMAP_USE_SSL=true
IMAP_USE_STARTTLS=false
# Set to false to accept self-signed certificates
IMAP_VERIFY_SSL=true
# Nextcloud CalDAV Configuration
CALDAV_URL=https://your-nextcloud.com/remote.php/dav
CALDAV_USERNAME=your-nextcloud-username
CALDAV_PASSWORD=your-nextcloud-password
CALENDAR_NAME=personal
# Set to false to accept self-signed certificates
CALDAV_VERIFY_SSL=true
# Processing Options
MARK_AS_SEEN=true
MOVE_PROCESSED=false
CHECK_INTERVAL=300
RUN_ONCE=false
# Summary Filter Options
# Leave SUMMARY_FILTER empty to import all events
# Examples:
# SUMMARY_FILTER=Meeting (imports only events with "Meeting" in title)
# SUMMARY_FILTER=^Team.* (regex: imports events starting with "Team")
# SUMMARY_FILTER=Dentist (exact match with SUMMARY_FILTER_MODE=exact)
SUMMARY_FILTER=
SUMMARY_FILTER_MODE=contains
INVERT_FILTER=false
# Deduplication Options
# Use these to replace existing events based on a pattern in the SUMMARY field
# This is useful when the same event (e.g., delivery updates) gets different UIDs
# Examples:
# DEDUPE_BY_SUMMARY_PATTERN=Order (\d+) (extracts order number from "Ocado Delivery (Order 123456)")
# DEDUPE_BY_SUMMARY_PATTERN=Booking #(\w+) (extracts booking reference)
DEDUPE_ENABLED=false
DEDUPE_BY_SUMMARY_PATTERN=
# Logging
LOG_LEVEL=INFO