Reject empty mail CLI recipients (#1581)

* Reject empty mail CLI recipients

* Keep mail CLI test imports isolated
This commit is contained in:
red person
2026-06-03 02:57:23 +03:00
committed by GitHub
parent 8051e25c65
commit 0cc1814658
2 changed files with 71 additions and 5 deletions

View File

@@ -107,6 +107,19 @@ def _q(name: str) -> str:
return '"' + (name or "").replace("\\", "\\\\").replace('"', '\\"') + '"'
def _split_recipients(value: str) -> list[str]:
return [r.strip() for r in (value or "").split(",") if r.strip()]
def _recipient_list(to: str, cc: str = "", bcc: str = "") -> list[str]:
recipients = _split_recipients(to)
recipients.extend(_split_recipients(cc))
recipients.extend(_split_recipients(bcc))
if not recipients:
fail("at least one recipient is required")
return recipients
# ─── list ────────────────────────────────────────────────────────────
def cmd_list(args) -> None:
@@ -302,11 +315,7 @@ def cmd_send(args) -> None:
outer["Date"] = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S +0000")
outer.attach(MIMEText(body, "plain", "utf-8"))
recipients = [r.strip() for r in args.to.split(",") if r.strip()]
if args.cc:
recipients.extend([r.strip() for r in args.cc.split(",") if r.strip()])
if args.bcc:
recipients.extend([r.strip() for r in args.bcc.split(",") if r.strip()])
recipients = _recipient_list(args.to, args.cc, args.bcc)
if args.dry_run:
emit({