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
1 changed files with 8 additions and 7 deletions

View File

@ -10,7 +10,7 @@ import subprocess
GNUPG_DIRECTORY = "~/.gnupg-checker"
SOFT_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
REVIEW_BEFORE_SEND = False
BETA = False
@ -50,7 +50,7 @@ def gen_checks(submissions_dir, check_content=False, check_submission_hash=None)
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
if not isinstance(checks, list):
@ -70,7 +70,7 @@ def respondmail(to, subject, ref, checks):
return respondmail(to, subject, ref, [maxitem])
msg = EmailMessage()
msg["X-loop"] = "virli"
msg["X-loop"] = "peret"
msg["From"] = FROM
msg["To"] = to
if ref is not None:
@ -124,7 +124,7 @@ running for nemunaire@nemunai.re""")
time.sleep(1)
if SEND_TO_REALUSER:
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):
@ -132,8 +132,9 @@ def readmail(fp):
frm = cnt.get("From") or "someone"
subject = cnt.get("Subject") or "your mail"
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):
@ -250,5 +251,5 @@ if __name__ == '__main__':
REVIEW_BEFORE_SEND = args.review_before_send
BETA = args.beta
cnt, frm, subject, ref = 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)])
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)], to)