feat(mail): default email_seed → \$PROJROOT/bait/ when unset
When service_cfg["email_seed"] is absent, compose_fragment now falls back to $PROJROOT/bait/ if that directory exists on the host. Lets operators drop a deployment-wide bait corpus into one place without threading email_seed through every decky's config. Missing dir keeps old no-op behavior.
This commit is contained in:
@@ -3,10 +3,23 @@ from decnet.services.base import BaseService
|
||||
|
||||
TEMPLATES_DIR = Path(__file__).parent.parent / "templates" / "pop3"
|
||||
|
||||
# See decnet/services/imap.py for the same default-seed-dir rationale.
|
||||
_PROJ_ROOT = Path(__file__).resolve().parents[2]
|
||||
_DEFAULT_SEED_DIR = _PROJ_ROOT / "bait"
|
||||
|
||||
_SEED_CONTAINER_PATH = "/var/spool/decnet-emails/seed"
|
||||
|
||||
|
||||
def _resolve_seed_path(service_cfg: dict | None) -> str | None:
|
||||
if service_cfg:
|
||||
seed = service_cfg.get("email_seed")
|
||||
if seed:
|
||||
return str(Path(str(seed)).expanduser().resolve())
|
||||
if _DEFAULT_SEED_DIR.is_dir():
|
||||
return str(_DEFAULT_SEED_DIR.resolve())
|
||||
return None
|
||||
|
||||
|
||||
class POP3Service(BaseService):
|
||||
name = "pop3"
|
||||
ports = [110, 995]
|
||||
@@ -15,6 +28,7 @@ class POP3Service(BaseService):
|
||||
# email_seed: host path to a directory of .eml/.json files OR a
|
||||
# single .json/.eml. Mounted read-only; entries
|
||||
# concatenate with the hardcoded bait list.
|
||||
# Default fallback: $PROJROOT/bait/ when present.
|
||||
|
||||
def compose_fragment(self, decky_name: str, log_target: str | None = None, service_cfg: dict | None = None) -> dict:
|
||||
fragment: dict = {
|
||||
@@ -25,14 +39,12 @@ class POP3Service(BaseService):
|
||||
}
|
||||
if log_target:
|
||||
fragment["environment"]["LOG_TARGET"] = log_target
|
||||
if service_cfg:
|
||||
seed = service_cfg.get("email_seed")
|
||||
if seed:
|
||||
host_path = str(Path(str(seed)).expanduser().resolve())
|
||||
fragment["environment"]["POP3_EMAIL_SEED"] = _SEED_CONTAINER_PATH
|
||||
fragment.setdefault("volumes", []).append(
|
||||
f"{host_path}:{_SEED_CONTAINER_PATH}:ro"
|
||||
)
|
||||
host_path = _resolve_seed_path(service_cfg)
|
||||
if host_path:
|
||||
fragment["environment"]["POP3_EMAIL_SEED"] = _SEED_CONTAINER_PATH
|
||||
fragment.setdefault("volumes", []).append(
|
||||
f"{host_path}:{_SEED_CONTAINER_PATH}:ro"
|
||||
)
|
||||
return fragment
|
||||
|
||||
def dockerfile_context(self) -> Path | None:
|
||||
|
||||
Reference in New Issue
Block a user