From 1dd95d5aad6c9cc53db7e8ed5d7764ec497e62f2 Mon Sep 17 00:00:00 2001 From: Pelle Nilsson Date: Tue, 24 Jul 2018 18:17:41 +0200 Subject: [PATCH] New setting general.reply-notifications --- isso/__init__.py | 5 ++++- isso/ext/notifications.py | 13 ++++++++----- share/isso-dev.conf | 1 + share/isso.conf | 5 +++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/isso/__init__.py b/isso/__init__.py index 0af5b43..a3da85b 100644 --- a/isso/__init__.py +++ b/isso/__init__.py @@ -96,13 +96,16 @@ class Isso(object): super(Isso, self).__init__(conf) subscribers = [] + smtp_backend = False for backend in conf.getlist("general", "notify"): if backend == "stdout": subscribers.append(Stdout(None)) elif backend in ("smtp", "SMTP"): - subscribers.append(SMTP(self)) + smtp_backend = True else: logger.warn("unknown notification backend '%s'", backend) + if smtp_backend or conf.getboolean("general", "reply-notifications"): + subscribers.append(SMTP(self)) self.signal = ext.Signal(*subscribers) diff --git a/isso/ext/notifications.py b/isso/ext/notifications.py index dc521dc..0bf1ac1 100644 --- a/isso/ext/notifications.py +++ b/isso/ext/notifications.py @@ -76,6 +76,8 @@ class SMTP(object): self.isso = isso self.conf = isso.conf.section("smtp") self.public_endpoint = isso.conf.get("server", "public-endpoint") or local("host") + self.admin_notify = any((n in ("smtp", "SMTP")) for n in isso.conf.getlist("general", "notify")) + self.reply_notify = isso.conf.getboolean("general", "reply-notifications") # test SMTP connectivity try: @@ -143,8 +145,9 @@ class SMTP(object): return rv.read() def notify_new(self, thread, comment): - body = self.format(thread, comment, None, admin=True) - self.sendmail(thread["title"], body, thread, comment) + if self.admin_notify: + body = self.format(thread, comment, None, admin=True) + self.sendmail(thread["title"], body, thread, comment) if comment["mode"] == 1: self.notify_users(thread, comment) @@ -153,7 +156,7 @@ class SMTP(object): self.notify_users(thread, comment) def notify_users(self, thread, comment): - if "parent" in comment and comment["parent"] is not None: + if self.reply_notify and "parent" in comment and comment["parent"] is not None: # Notify interested authors that a new comment is posted notified = [] parent_comment = self.isso.db.comments.get(comment["parent"]) @@ -226,5 +229,5 @@ class Stdout(object): def _delete_comment(self, id): logger.info('comment %i deleted', id) - def _activate_comment(self, id): - logger.info("comment %s activated" % id) + def _activate_comment(self, thread, comment): + logger.info("comment %(id)s activated" % thread) diff --git a/share/isso-dev.conf b/share/isso-dev.conf index 970c1b0..18400ee 100644 --- a/share/isso-dev.conf +++ b/share/isso-dev.conf @@ -9,6 +9,7 @@ dbpath = /var/isso/comments.db host = http://isso-dev.local/ max-age = 15m notify = stdout +reply-notifications = false log-file = /var/log/isso.log admin_password = strong_default_password_for_isso_admin diff --git a/share/isso.conf b/share/isso.conf index 16afce1..9828ca4 100644 --- a/share/isso.conf +++ b/share/isso.conf @@ -43,6 +43,11 @@ max-age = 15m # moderated) and deletion links. notify = stdout +# Allow users to request E-mail notifications for replies to their post. +# WARNING: It is highly recommended to also turn on moderation when enabling +# this setting, as Isso can otherwise be easily exploited for sending spam. +reply-notifications=false + # Log console messages to file instead of standard output. log-file =