|
|
@ -88,7 +88,7 @@ class SMTP(object):
|
|
|
|
def __iter__(self):
|
|
|
|
def __iter__(self):
|
|
|
|
yield "comments.new:after-save", self.notify
|
|
|
|
yield "comments.new:after-save", self.notify
|
|
|
|
|
|
|
|
|
|
|
|
def format(self, thread, comment):
|
|
|
|
def format(self, thread, comment, admin=False):
|
|
|
|
|
|
|
|
|
|
|
|
rv = io.StringIO()
|
|
|
|
rv = io.StringIO()
|
|
|
|
|
|
|
|
|
|
|
@ -101,40 +101,51 @@ class SMTP(object):
|
|
|
|
rv.write(comment["text"] + "\n")
|
|
|
|
rv.write(comment["text"] + "\n")
|
|
|
|
rv.write("\n")
|
|
|
|
rv.write("\n")
|
|
|
|
|
|
|
|
|
|
|
|
if comment["website"]:
|
|
|
|
if admin:
|
|
|
|
rv.write("User's URL: %s\n" % comment["website"])
|
|
|
|
if comment["website"]:
|
|
|
|
|
|
|
|
rv.write("User's URL: %s\n" % comment["website"])
|
|
|
|
|
|
|
|
|
|
|
|
rv.write("IP address: %s\n" % comment["remote_addr"])
|
|
|
|
rv.write("IP address: %s\n" % comment["remote_addr"])
|
|
|
|
rv.write("Link to comment: %s\n" %
|
|
|
|
rv.write("Link to comment: %s\n" %
|
|
|
|
(local("origin") + thread["uri"] + "#isso-%i" % comment["id"]))
|
|
|
|
(local("origin") + thread["uri"] + "#isso-%i" % comment["id"]))
|
|
|
|
rv.write("\n")
|
|
|
|
rv.write("\n")
|
|
|
|
|
|
|
|
|
|
|
|
uri = local("host") + "/id/%i" % comment["id"]
|
|
|
|
uri = local("host") + "/id/%i" % comment["id"]
|
|
|
|
key = self.isso.sign(comment["id"])
|
|
|
|
key = self.isso.sign(comment["id"])
|
|
|
|
|
|
|
|
|
|
|
|
rv.write("---\n")
|
|
|
|
rv.write("---\n")
|
|
|
|
rv.write("Delete comment: %s\n" % (uri + "/delete/" + key))
|
|
|
|
rv.write("Delete comment: %s\n" % (uri + "/delete/" + key))
|
|
|
|
|
|
|
|
|
|
|
|
if comment["mode"] == 2:
|
|
|
|
if comment["mode"] == 2:
|
|
|
|
rv.write("Activate comment: %s\n" % (uri + "/activate/" + key))
|
|
|
|
rv.write("Activate comment: %s\n" % (uri + "/activate/" + key))
|
|
|
|
|
|
|
|
|
|
|
|
rv.seek(0)
|
|
|
|
rv.seek(0)
|
|
|
|
return rv.read()
|
|
|
|
return rv.read()
|
|
|
|
|
|
|
|
|
|
|
|
def notify(self, thread, comment):
|
|
|
|
def notify(self, thread, comment):
|
|
|
|
|
|
|
|
if "parent" in comment:
|
|
|
|
body = self.format(thread, comment)
|
|
|
|
comment_parent = self.isso.db.comments.get(comment["parent"])
|
|
|
|
|
|
|
|
# Notify the author that a new comment is posted if requested
|
|
|
|
|
|
|
|
if comment_parent and "email" in comment_parent and comment_parent["notification"]:
|
|
|
|
|
|
|
|
body = self.format(thread, comment, admin=False)
|
|
|
|
|
|
|
|
subject = "Re: New comment posted on %s" % thread["title"]
|
|
|
|
|
|
|
|
self.sendmail(subject, body, thread, comment, to=comment_parent["email"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
body = self.format(thread, comment, admin=True)
|
|
|
|
|
|
|
|
self.sendmail(thread["title"], body, thread, comment)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def sendmail(self, subject, body, thread, comment, to=None):
|
|
|
|
if uwsgi:
|
|
|
|
if uwsgi:
|
|
|
|
uwsgi.spool({b"subject": thread["title"].encode("utf-8"),
|
|
|
|
uwsgi.spool({b"subject": subject.encode("utf-8"),
|
|
|
|
b"body": body.encode("utf-8")})
|
|
|
|
b"body": body.encode("utf-8"),
|
|
|
|
|
|
|
|
b"to": to})
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
start_new_thread(self._retry, (thread["title"], body))
|
|
|
|
start_new_thread(self._retry, (subject, body, to))
|
|
|
|
|
|
|
|
|
|
|
|
def _sendmail(self, subject, body):
|
|
|
|
def _sendmail(self, subject, body, to=None):
|
|
|
|
|
|
|
|
|
|
|
|
from_addr = self.conf.get("from")
|
|
|
|
from_addr = self.conf.get("from")
|
|
|
|
to_addr = self.conf.get("to")
|
|
|
|
to_addr = to or self.conf.get("to")
|
|
|
|
|
|
|
|
|
|
|
|
msg = MIMEText(body, 'plain', 'utf-8')
|
|
|
|
msg = MIMEText(body, 'plain', 'utf-8')
|
|
|
|
msg['From'] = from_addr
|
|
|
|
msg['From'] = from_addr
|
|
|
@ -145,10 +156,10 @@ class SMTP(object):
|
|
|
|
with self as con:
|
|
|
|
with self as con:
|
|
|
|
con.sendmail(from_addr, to_addr, msg.as_string())
|
|
|
|
con.sendmail(from_addr, to_addr, msg.as_string())
|
|
|
|
|
|
|
|
|
|
|
|
def _retry(self, subject, body):
|
|
|
|
def _retry(self, subject, body, to):
|
|
|
|
for x in range(5):
|
|
|
|
for x in range(5):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
self._sendmail(subject, body)
|
|
|
|
self._sendmail(subject, body, to)
|
|
|
|
except smtplib.SMTPConnectError:
|
|
|
|
except smtplib.SMTPConnectError:
|
|
|
|
time.sleep(60)
|
|
|
|
time.sleep(60)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|