This commit also introduces a new db which maps path to thread title. The title is read by parsing the HTML for a related <h1> tag using `html5lib`. You can set up SMTP in your configuration (here the defaults): [SMTP] host = localhost port = 465 ssl = on username = password = recipient = sender = In short, by default Isso uses a local SMTP server using SSL without any authentication. An email is send on comment creation to "recipient" from "Ich schrei sonst <sender>". This commit also uses a simple ANSI colorization module from my static blog compiler project. On server startup, Isso will connect to the SMTP server and fall back to a null mailer. It also tries to connect to your website, so if that doesn't work, you probably can't comment on your website either.pull/16/head
parent
9edd34d079
commit
adb3d40c03
@ -0,0 +1,51 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
# from isso import compat
|
||||
# from isso.compat import text_type as str, string_types
|
||||
|
||||
str = unicode
|
||||
string_types = (unicode, str)
|
||||
|
||||
|
||||
# @compat.implements_to_string
|
||||
class ANSIString(object):
|
||||
|
||||
style = 0
|
||||
color = 30
|
||||
|
||||
def __init__(self, obj, style=None, color=None):
|
||||
|
||||
if isinstance(obj, ANSIString):
|
||||
if style is None:
|
||||
style = obj.style
|
||||
if color is None:
|
||||
color = obj.color
|
||||
obj = obj.obj
|
||||
elif not isinstance(obj, string_types):
|
||||
obj = str(obj)
|
||||
|
||||
self.obj = obj
|
||||
if style:
|
||||
self.style = style
|
||||
if color:
|
||||
self.color = color
|
||||
|
||||
def __str__(self):
|
||||
return '\033[%i;%im' % (self.style, self.color) + self.obj + '\033[0m'
|
||||
|
||||
def __add__(self, other):
|
||||
return str.__add__(str(self), other)
|
||||
|
||||
def __radd__(self, other):
|
||||
return other + str(self)
|
||||
|
||||
def encode(self, encoding):
|
||||
return str(self).encode(encoding)
|
||||
|
||||
|
||||
normal, bold, underline = [lambda obj, x=x: ANSIString(obj, style=x)
|
||||
for x in (0, 1, 4)]
|
||||
|
||||
black, red, green, yellow, blue, \
|
||||
magenta, cyan, white = [lambda obj, y=y: ANSIString(obj, color=y)
|
||||
for y in range(30, 38)]
|
@ -0,0 +1,60 @@
|
||||
|
||||
import time
|
||||
import logging
|
||||
|
||||
from smtplib import SMTP, SMTP_SSL, SMTPException
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
|
||||
def create(comment, subject, permalink, remote_addr):
|
||||
|
||||
rv = []
|
||||
rv.append("%s schrieb:" % (comment["author"] or "Jemand"))
|
||||
rv.append("")
|
||||
rv.append(comment["text"])
|
||||
rv.append("")
|
||||
|
||||
if comment["website"]:
|
||||
rv.append("Webseite des Kommentators: %s" % comment["website"])
|
||||
|
||||
rv.append("IP Adresse: %s" % remote_addr)
|
||||
rv.append("Link zum Kommentar: %s" % permalink)
|
||||
|
||||
return subject, u'\n'.join(rv)
|
||||
|
||||
|
||||
class SMTPMailer(object):
|
||||
|
||||
def __init__(self, conf):
|
||||
|
||||
self.server = (SMTP_SSL if conf.getboolean('SMTP', 'ssl') else SMTP)(
|
||||
host=conf.get('SMTP', 'host'), port=conf.getint('SMTP', 'port'))
|
||||
|
||||
if conf.get('SMTP', 'username') and conf.get('SMTP', 'password'):
|
||||
self.server.login(conf.get('SMTP', 'username'), conf.get('SMTP', 'password'))
|
||||
|
||||
self.from_addr = conf.get('SMTP', 'from')
|
||||
self.to_addr = conf.get('SMTP', 'to')
|
||||
|
||||
def sendmail(self, subject, body, retries=5):
|
||||
|
||||
msg = MIMEText(body, 'plain', 'utf-8')
|
||||
msg['From'] = "Ich schrei sonst! <%s>" % self.from_addr
|
||||
msg['To'] = self.to_addr
|
||||
msg['Subject'] = subject.encode('utf-8')
|
||||
|
||||
for i in range(retries):
|
||||
try:
|
||||
self.server.sendmail(self.from_addr, self.to_addr, msg.as_string())
|
||||
except SMTPException:
|
||||
logging.exception("uncaught exception, %i of %i:", i + 1, retries)
|
||||
else:
|
||||
return
|
||||
|
||||
time.sleep(60)
|
||||
|
||||
|
||||
class NullMailer(object):
|
||||
|
||||
def sendmail(self, subject, body, retries=5):
|
||||
pass
|
Loading…
Reference in new issue