From: Michael Tremer Date: Fri, 9 Jan 2026 16:18:56 +0000 (+0000) Subject: reports: Send an email after a report has been reviewed X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3281135caac222b81873df682e7b3e064a08d7a6;p=dbl.git reports: Send an email after a report has been reviewed Signed-off-by: Michael Tremer --- diff --git a/src/dnsbl/reports.py b/src/dnsbl/reports.py index 6a4e2ad..2c68a11 100644 --- a/src/dnsbl/reports.py +++ b/src/dnsbl/reports.py @@ -239,7 +239,8 @@ class Report(sqlmodel.SQLModel, database.BackendMixin, table=True): # Decrement the counter for pending reports self.list.pending_reports -= 1 - # XXX Send a message to the reporter? + # Send a message to the reporter? + self._send_closing_notification() # We are done if the report has not been accepted if not self.accepted: @@ -268,6 +269,76 @@ class Report(sqlmodel.SQLModel, database.BackendMixin, table=True): # Notified At notified_at: datetime.datetime | None = None + def _send_closing_notification(self): + """ + Sends a notification to the reporter when this report gets closed. + """ + # Fetch the reporter + reporter = self.backend.users.get_by_uid(self.reported_by) + + # Do nothing if we could not find the reporter + if not reporter: + return + + # Fetch the person who closed the report + sender = self.backend.users.get_by_uid(self.closed_by) + + # Fail if we could not find the sender + if not sender: + raise RuntimeError("Failed to fetch the sender '%s'" % self.closed_by) + + # ACCEPTED + if self.accepted: + subject = "[IPFire DNSBL] %s" % (_("Your report for %s has been accepted") % self.name) + + lines = ( + _("Hello,"), + "", + _("Thank you for taking the time to report %s to our IPFire DNSBL service.") % self.name, + "", + _("We've reviewed your submission and are pleased to inform you that your report has been ACCEPTED." + " The domain has been added to our blocklist and will now be flagged by systems using our service."), + "", + _("Your contribution helps make the internet safer for everyone." + " We appreciate your vigilance in identifying and reporting problematic domains."), + "", + _("If you have any questions about this decision, please don't hesitate to reach out."), + "", + _("Best regards,"), + "-%s" % sender, + ) + + # DECLINED + else: + subject = "[IPFire DNSBL] %s" % (_("Your report for %s has been reviewed") % self.name) + + lines = ( + _("Hello,"), + "", + _("Thank you for taking the time to report %s to our IPFire DNSBL service.") % self.name, + "", + _("We've carefully reviewed your submission." + " After investigation, we've determined that this domain does not meet our criteria" + " for inclusion in the blocklist at this time, and your report has been DECLINED."), + "", + _("This decision may be due to various factors, such as insufficient evidence of malicious" + " activity, the domain being legitimately used, or the issue having already been resolved."), + "", + _("We genuinely appreciate you taking the time to help keep the internet safer." + " Your vigilance matters, and we encourage you to continue reporting suspicious domains in the future."), + "", + _("If you believe this decision was made in error or have additional information to share," + " please feel free to reply to this email."), + "", + _("Best regards,"), + "-%s" % sender, + ) + + # Send the email + reporter.sendmail("\n".join(lines), sender=sender, headers={ + "Subject" : subject, + }) + # URL @property diff --git a/src/dnsbl/users.py b/src/dnsbl/users.py index 7752b04..f714fbe 100644 --- a/src/dnsbl/users.py +++ b/src/dnsbl/users.py @@ -165,7 +165,7 @@ class User(LDAPObject): """ return self._get_string("mail") - def sendmail(self, message, headers=None): + def sendmail(self, message, sender=None, headers=None): """ Sends the given message to this user """ @@ -176,9 +176,19 @@ class User(LDAPObject): message = email.message.EmailMessage() message.set_content(content) + # no-reply@ipfire.org + no_reply = email.utils.formataddr(("IPFire DNSBL", "no-reply@ipfire.org")) + # Set the recipient message["To"] = email.utils.formataddr((self.cn, self.mail)) + # Set the sender + if sender: + message["From"] = email.utils.formataddr((sender.cn, sender.mail)) + + # Set Sender: because the email is not actually coming from the sender + message["Sender"] = no_reply + # Set headers if headers: for header in headers: @@ -186,7 +196,7 @@ class User(LDAPObject): # Set a sender if none set if not "From" in message: - message["From"] = email.utils.formataddr(("IPFire DNSBL", "no-reply@ipfire.org")) + message["From"] = no_reply # Log the email log.debug("Sending email:\n%s" % message.as_string())