feat: refactor IMAP config to DB, add multi-account mail sources admin UI

Agent-Logs-Url: https://github.com/christianlouis/dmarq/sessions/f141cd3b-8d0a-4c7e-b479-ee973c209c11

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-29 16:18:15 +00:00
parent 7a0444a619
commit 6d9392e5e7
10 changed files with 1320 additions and 312 deletions
+53
View File
@@ -0,0 +1,53 @@
from datetime import datetime
from sqlalchemy import Boolean, Column, DateTime, Integer, String, Text
from app.core.database import Base
class MailSource(Base):
"""
Mail source configuration model.
Stores credentials and settings for a mail inbox used to retrieve DMARC
aggregate reports. The ``method`` field determines how the connection is
made and which additional fields are relevant:
- ``IMAP`` standard IMAP4 (over SSL/TLS or STARTTLS)
- ``POP3`` POP3 inbox (stub for future implementation)
- ``GMAIL_API`` Gmail API with OAuth 2.0 (stub for future implementation)
"""
__tablename__ = "mail_sources"
id = Column(Integer, primary_key=True, index=True)
# Human-readable label for the source
name = Column(String, nullable=False)
# Connection method determines which fields are used at runtime
method = Column(String, nullable=False, default="IMAP") # IMAP | POP3 | GMAIL_API
# Connection details (used by IMAP and POP3)
server = Column(String, nullable=True)
port = Column(Integer, nullable=True, default=993)
username = Column(String, nullable=True)
# NOTE: password is stored in plaintext. In a production environment this
# field should be encrypted at the application layer before persisting.
password = Column(Text, nullable=True)
use_ssl = Column(Boolean, default=True)
folder = Column(String, default="INBOX")
# Polling behaviour
polling_interval = Column(Integer, default=60) # minutes
# Source lifecycle
enabled = Column(Boolean, default=True, index=True)
last_checked = Column(DateTime, nullable=True)
# Timestamps
created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
def __repr__(self):
return f"<MailSource id={self.id} name={self.name!r} method={self.method!r}>"