]>
Commit | Line | Data |
---|---|---|
5613b94b MT |
1 | #!/usr/bin/python3 |
2 | ||
3 | import email.mime.text | |
4 | import logging | |
5 | import tornado.gen | |
6 | import tornado.process | |
7 | ||
124a8404 | 8 | from . import base |
5613b94b MT |
9 | |
10 | class SubscribeHandler(base.BaseHandler): | |
11 | @tornado.gen.coroutine | |
12 | def post(self): | |
13 | address = self.get_argument("email") | |
14 | ||
15 | # Create an email with us as sender | |
16 | m = email.mime.text.MIMEText("") | |
17 | m.add_header("To", "ipfire-announce-join@lists.ipfire.org") | |
18 | m.add_header("From", address) | |
19 | m.add_header("Sender", "no-reply@ipfire.org") | |
20 | m.add_header("Subject", "Subscribe") | |
21 | ||
22 | logging.debug("Sending email:\n%s" % m.as_string()) | |
23 | ||
24 | # Call sendmail | |
25 | p = tornado.process.Subprocess(["sendmail", "-t"], | |
26 | stdin=tornado.process.Subprocess.STREAM) | |
27 | ||
28 | # Pipe the email into sendmail | |
29 | yield tornado.gen.Task(p.stdin.write, m.as_bytes()) | |
30 | ||
31 | # Close standard input | |
32 | p.stdin.close() | |
33 | ||
34 | # Wait until sendmail is done | |
35 | ret = yield p.wait_for_exit() | |
36 | ||
37 | logging.info("%s has subscribed to the newsletter" % address) | |
38 | ||
39 | self.render("newsletter/subscribed.html", address=address) |