]> git.ipfire.org Git - dbl.git/commitdiff
reports: Send an email after a report has been reviewed
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Jan 2026 16:18:56 +0000 (16:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Jan 2026 16:18:56 +0000 (16:18 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dnsbl/reports.py
src/dnsbl/users.py

index 6a4e2adf5906a9ff38f1627e13405061667f1be5..2c68a111921398007ce94636b47061f00e1b3fb0 100644 (file)
@@ -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
index 7752b04195e1063934d43aed1805157794d6d56b..f714fbe0cb12990b1b7ac6675c59b5d27555bb7d 100644 (file)
@@ -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())