Generelize this checker: it's no more used only for virli

This commit is contained in:
nemunaire 2018-03-18 14:03:50 +01:00
parent 2e05a9f7fe
commit 9f3c814469

View File

@ -10,7 +10,7 @@ import subprocess
GNUPG_DIRECTORY = "~/.gnupg-checker" GNUPG_DIRECTORY = "~/.gnupg-checker"
SOFT_MAX_SUBMISSION = None SOFT_MAX_SUBMISSION = None
HARD_MAX_SUBMISSION = None HARD_MAX_SUBMISSION = None
FROM = "Automatic VIRLI Mail Checker <virli@nemunai.re>" FROM = "Peret - Automatic Mail Checker <peret@nemunai.re>"
SEND_TO_REALUSER = False SEND_TO_REALUSER = False
REVIEW_BEFORE_SEND = False REVIEW_BEFORE_SEND = False
BETA = False BETA = False
@ -50,7 +50,7 @@ def gen_checks(submissions_dir, check_content=False, check_submission_hash=None)
yield ( archive.extract, [submissions_dir] ) yield ( archive.extract, [submissions_dir] )
def respondmail(to, subject, ref, checks): def respondmail(to, subject, ref, checks, initial_to=None):
from email.message import EmailMessage from email.message import EmailMessage
if not isinstance(checks, list): if not isinstance(checks, list):
@ -70,7 +70,7 @@ def respondmail(to, subject, ref, checks):
return respondmail(to, subject, ref, [maxitem]) return respondmail(to, subject, ref, [maxitem])
msg = EmailMessage() msg = EmailMessage()
msg["X-loop"] = "virli" msg["X-loop"] = "peret"
msg["From"] = FROM msg["From"] = FROM
msg["To"] = to msg["To"] = to
if ref is not None: if ref is not None:
@ -124,7 +124,7 @@ running for nemunaire@nemunai.re""")
time.sleep(1) time.sleep(1)
if SEND_TO_REALUSER: if SEND_TO_REALUSER:
smtp.send_message(msg) smtp.send_message(msg)
smtp.send_message(msg, to_addrs=["virli-report@nemunai.re"]) smtp.send_message(msg, to_addrs=["peret-report@nemunai.re" if initial_to is None else initial_to + "-report@nemunai.re"])
def readmail(fp): def readmail(fp):
@ -132,8 +132,9 @@ def readmail(fp):
frm = cnt.get("From") or "someone" frm = cnt.get("From") or "someone"
subject = cnt.get("Subject") or "your mail" subject = cnt.get("Subject") or "your mail"
ref = cnt.get("Message-ID") or "" ref = cnt.get("Message-ID") or ""
to = cnt.get("To").split("@", 1)[0] or cnt.get("Cc").split("@", 1)[0] or None
return cnt, frm, subject, ref return cnt, frm, subject, ref, to
def check_mail(cnt, submissions_dir, check_content=False, check_submission_hash=None): def check_mail(cnt, submissions_dir, check_content=False, check_submission_hash=None):
@ -250,5 +251,5 @@ if __name__ == '__main__':
REVIEW_BEFORE_SEND = args.review_before_send REVIEW_BEFORE_SEND = args.review_before_send
BETA = args.beta BETA = args.beta
cnt, frm, subject, ref = readmail(sys.stdin.buffer) cnt, frm, subject, ref, to = readmail(sys.stdin.buffer)
respondmail(frm, subject, ref, [c for c in check_mail(cnt, submissions_dir=args.submissions, check_content=not args.sign, check_submission_hash=args.expected_submission_hash)]) respondmail(frm, subject, ref, [c for c in check_mail(cnt, submissions_dir=args.submissions, check_content=not args.sign, check_submission_hash=args.expected_submission_hash)], to)