Files
DECNET/decnet/services/imap.py
anti f2b3393669 chore: relicense to AGPL-3.0-or-later and add SPDX headers
Replaces LICENSE (GPLv3 -> AGPLv3) and prepends
`SPDX-License-Identifier: AGPL-3.0-or-later` to every source file
across decnet/, decnet_web/, tests/, scripts/, and tools/.

Rationale: closes the GPLv3 ASP loophole so any party operating a
modified DECNET as a network service must offer their modified
source. Personal copyright (Samuel Paschuan) + inbound=outbound
contributions make a future unilateral relicense infeasible.

- LICENSE: full AGPL-3.0 text (gnu.org/licenses/agpl-3.0.txt)
- COPYRIGHT: project copyright notice
- tools/add_spdx_headers.py: idempotent header injector
  (shebang- and PEP 263-aware)

Touches 1565 source files (.py, .ts, .tsx, .js, .jsx, .css, .sh).
No behavior change; comments only.
2026-05-22 21:04:16 -04:00

65 lines
2.4 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
from pathlib import Path
from decnet.services.base import BaseService
TEMPLATES_DIR = Path(__file__).parent.parent / "templates" / "imap"
# Repo-root default seed dir. When service_cfg["email_seed"] is unset,
# fall back to ``$PROJROOT/bait/`` if that directory exists on the host.
# Operator drops .eml / .json files there to ship a deployment-wide bait
# corpus without per-decky config. Missing dir → no env var, no volume,
# template uses its hardcoded baseline alone.
_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:
"""Return the host path to bind-mount, or None.
Precedence:
1. service_cfg["email_seed"] if set + truthy.
2. ``$PROJROOT/bait/`` if it exists.
3. 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 IMAPService(BaseService):
name = "imap"
ports = [143, 993]
default_image = "build"
# Optional config:
# email_seed: host path to a directory of .eml/.json files OR a
# single .json/.eml. Mounted read-only into the
# container; entries concatenate with the hardcoded
# bait list (additive to realism-engine output).
# 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 = {
"build": {"context": str(TEMPLATES_DIR)},
"container_name": f"{decky_name}-imap",
"restart": "unless-stopped",
"environment": {"NODE_NAME": decky_name},
}
if log_target:
fragment["environment"]["LOG_TARGET"] = log_target
host_path = _resolve_seed_path(service_cfg)
if host_path:
fragment["environment"]["IMAP_EMAIL_SEED"] = _SEED_CONTAINER_PATH
fragment.setdefault("volumes", []).append(
f"{host_path}:{_SEED_CONTAINER_PATH}:ro"
)
return fragment
def dockerfile_context(self) -> Path | None:
return TEMPLATES_DIR