feat(mail): add governed POP3 legacy import
Module Package Release / publish-packages (push) Successful in 11s
Module Package Release / publish-packages (push) Successful in 11s
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pydantic import Field, model_validator
|
||||
|
||||
from govoplan_core.mail.config import (
|
||||
ImapConfig,
|
||||
ImapFolderMappings,
|
||||
@@ -12,10 +14,49 @@ from govoplan_core.mail.config import (
|
||||
normalize_split_transport_credentials,
|
||||
)
|
||||
|
||||
|
||||
class Pop3ServerConfig(StrictModel):
|
||||
"""Server-only settings for an explicitly enabled legacy POP3 source."""
|
||||
|
||||
host: str | None = None
|
||||
port: int | None = Field(default=None, ge=1, le=65535)
|
||||
security: TransportSecurity = TransportSecurity.TLS
|
||||
timeout_seconds: int = Field(default=30, ge=1, le=300)
|
||||
max_message_bytes: int = Field(default=25 * 1024 * 1024, ge=1_024, le=50 * 1024 * 1024)
|
||||
max_batch_bytes: int = Field(default=100 * 1024 * 1024, ge=1_048_576, le=500 * 1024 * 1024)
|
||||
preview_body_lines: int = Field(default=20, ge=0, le=100)
|
||||
legacy_import_enabled: bool = False
|
||||
allow_delete_after_import: bool = False
|
||||
|
||||
@model_validator(mode="after")
|
||||
def apply_default_port(self) -> "Pop3ServerConfig":
|
||||
if self.port is None:
|
||||
self.port = 995 if self.security == TransportSecurity.TLS else 110
|
||||
if self.legacy_import_enabled and not str(self.host or "").strip():
|
||||
raise ValueError(
|
||||
"POP3 host is required when legacy import is enabled"
|
||||
)
|
||||
if self.max_batch_bytes < self.max_message_bytes:
|
||||
raise ValueError(
|
||||
"POP3 batch size limit cannot be lower than the per-message limit"
|
||||
)
|
||||
if self.allow_delete_after_import and not self.legacy_import_enabled:
|
||||
raise ValueError(
|
||||
"POP3 delete-after-import cannot be enabled while legacy import is disabled"
|
||||
)
|
||||
return self
|
||||
|
||||
|
||||
class Pop3Config(Pop3ServerConfig):
|
||||
username: str | None = None
|
||||
password: str | None = None
|
||||
|
||||
__all__ = [
|
||||
"ImapConfig",
|
||||
"ImapFolderMappings",
|
||||
"ImapServerConfig",
|
||||
"Pop3Config",
|
||||
"Pop3ServerConfig",
|
||||
"SmtpConfig",
|
||||
"SmtpServerConfig",
|
||||
"StrictModel",
|
||||
|
||||
Reference in New Issue
Block a user