]> git.ipfire.org Git - ipfire.org.git/commitdiff
Use our internal mail framework for sending newsletter subscriptions
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 31 Oct 2019 18:59:00 +0000 (18:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 31 Oct 2019 18:59:00 +0000 (18:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/backend/messages.py
src/templates/newsletter/subscribe.txt [new file with mode: 0644]
src/web/newsletter.py

index 08ed643b63f89c7e9807adddbf159f596754245f..2fdbd9abae2bf5f6e08f09d0feac1b32f15df992 100644 (file)
@@ -213,6 +213,7 @@ templates_netboot_DATA = \
 templates_netbootdir = $(templatesdir)/netboot
 
 templates_newsletter_DATA = \
+       src/templates/newsletter/subscribe.txt \
        src/templates/newsletter/subscribed.html
 
 templates_newsletterdir = $(templatesdir)/newsletter
index b618a95123e78041df044acb22777b7c41f6677f..67d0a8635eefc4ede33714f679da68c5618bce4d 100644 (file)
@@ -71,6 +71,10 @@ class Messages(misc.Object):
                        except KeyError:
                                message.add_header(k, v)
 
+               # Read recipients from To: header
+               if not recipients:
+                       recipients = message.get("To").split(", ")
+
                # Add date if the message doesn't have one already
                if "Date" not in message:
                        message.add_header("Date", email.utils.formatdate())
@@ -82,7 +86,7 @@ class Messages(misc.Object):
                # Send the message
                self._send(recipients, message.as_string(), priority=priority)
 
-       def send_template(self, template_name, recipients,
+       def send_template(self, template_name, recipients=[],
                        sender=None, priority=0, headers={}, **kwargs):
                """
                        Send a message based on the given template
diff --git a/src/templates/newsletter/subscribe.txt b/src/templates/newsletter/subscribe.txt
new file mode 100644 (file)
index 0000000..126eff7
--- /dev/null
@@ -0,0 +1,4 @@
+To: ipfire-announce-join@lists.ipfire.org
+From: {{ address }}
+Sender: no-reply@ipfire.org
+Subject: Subscribe
index 28fea1014a02ebc6a4bc242a8830ff333df3c30b..abf31ce0f314b65399446ad8db86ab761ca3107b 100644 (file)
@@ -18,27 +18,9 @@ class SubscribeHandler(base.BaseHandler):
        def post(self):
                address = self.get_argument("email")
 
-               # Create an email with us as sender
-               m = email.mime.text.MIMEText("")
-               m.add_header("To", "ipfire-announce-join@lists.ipfire.org")
-               m.add_header("From", address)
-               m.add_header("Sender", "no-reply@ipfire.org")
-               m.add_header("Subject", "Subscribe")
-
-               logging.debug("Sending email:\n%s" % m.as_string())
-
-               # Call sendmail
-               p = tornado.process.Subprocess(["sendmail", "-t"],
-                       stdin=tornado.process.Subprocess.STREAM)
-
-               # Pipe the email into sendmail
-               yield tornado.gen.Task(p.stdin.write, m.as_bytes())
-
-               # Close standard input
-               p.stdin.close()
-
-               # Wait until sendmail is done
-               ret = yield p.wait_for_exit()
+               with self.db.transaction():
+                       self.backend.messages.send_template(
+                               "newsletter/subscribe", address=address)
 
                logging.info("%s has subscribed to the newsletter" % address)