feat: add mail import detail events

This commit is contained in:
Christian Krakau-Louis
2026-05-22 20:06:51 +02:00
parent 5f416d042f
commit c1b81d3e06
13 changed files with 520 additions and 67 deletions
@@ -121,6 +121,7 @@ class MailSourceImportResponse(BaseModel):
error_count: int
new_domains: List[str]
errors: List[str]
details: List[Dict[str, str]]
started_at: datetime
finished_at: datetime
created_at: datetime
@@ -183,6 +184,24 @@ def _decode_json_list(value: Optional[str]) -> List[str]:
return [str(item) for item in decoded]
def _decode_json_details(value: Optional[str]) -> List[Dict[str, str]]:
"""Decode a sanitized JSON detail list stored on import history rows."""
if not value:
return []
try:
decoded = json.loads(value)
except (json.JSONDecodeError, TypeError):
return []
if not isinstance(decoded, list):
return []
details: List[Dict[str, str]] = []
for item in decoded:
if isinstance(item, dict):
details.append({str(key): str(val) for key, val in item.items()})
return details
def _import_to_response(row: MailSourceImport) -> MailSourceImportResponse:
"""Convert an import-history ORM row to an API response."""
return MailSourceImportResponse(
@@ -196,6 +215,7 @@ def _import_to_response(row: MailSourceImport) -> MailSourceImportResponse:
error_count=row.error_count,
new_domains=_decode_json_list(row.new_domains),
errors=_decode_json_list(row.errors),
details=_decode_json_details(row.details),
started_at=row.started_at,
finished_at=row.finished_at,
created_at=row.created_at,