fix a couple of bugs

pull/6/head
Yax 4 years ago
parent 542a923cbe
commit 59e020228a

@ -31,6 +31,7 @@ password = MYPASSWORD
[smtp]
host = mail.gandi.net
starttls = true
ssl = false
port = 587
login = blog@mydomain.com
password = MYPASSWORD

@ -1,6 +1,6 @@
[tool.poetry]
name = "stacosys"
version = "2.0b2"
version = "2.0b3"
description = "STAtic COmmenting SYStem"
authors = ["Yax"]
readme = "README.md"

@ -11,6 +11,8 @@ from stacosys.core import database
from stacosys.core.rss import Rss
from stacosys.core.mailer import Mailer
from stacosys.interface import app
from stacosys.interface import api
from stacosys.interface import form
from stacosys.interface import scheduler
@ -43,7 +45,8 @@ def stacosys_server(config_pathname):
# initialize config
conf = Config.load(config_pathname)
logger.info(conf.__repr__())
# check database file exists (prevents from creating a fresh db)
db_pathname = conf.get(ConfigParameter.DB_SQLITE_FILE)
if not os.path.isfile(db_pathname):
@ -76,6 +79,7 @@ def stacosys_server(config_pathname):
conf.get(ConfigParameter.SMTP_HOST),
conf.get_int(ConfigParameter.SMTP_PORT),
conf.get_bool(ConfigParameter.SMTP_STARTTLS),
conf.get_bool(ConfigParameter.SMTP_SSL),
conf.get(ConfigParameter.SMTP_LOGIN),
conf.get(ConfigParameter.SMTP_PASSWORD),
)
@ -94,6 +98,7 @@ def stacosys_server(config_pathname):
# inject config parameters into flask
app.config.update(SITE_TOKEN=conf.get(ConfigParameter.SITE_TOKEN))
logger.info(f"start interfaces {api} {form}")
# start Flask
app.run(

@ -25,6 +25,7 @@ class ConfigParameter(Enum):
IMAP_PASSWORD = "imap.password"
SMTP_STARTTLS = "smtp.starttls"
SMTP_SSL = "smtp.ssl"
SMTP_HOST = "smtp.host"
SMTP_PORT = "smtp.port"
SMTP_LOGIN = "smtp.login"
@ -62,3 +63,6 @@ class Config:
def get_bool(self, key: ConfigParameter):
return self._params[key.value].lower() in ("yes", "true")
def __repr__(self):
return self._params.__repr__()

@ -8,6 +8,8 @@ import re
from stacosys.core.templater import Templater, Template
from stacosys.model.comment import Comment
from stacosys.model.email import Email
from stacosys.core.rss import Rss
from stacosys.core.mailer import Mailer
logger = logging.getLogger(__name__)
@ -16,14 +18,14 @@ template_path = os.path.abspath(os.path.join(current_path, "../templates"))
templater = Templater(template_path)
def fetch_mail_answers(lang, mailer, rss, site_token):
def fetch_mail_answers(lang, mailer: Mailer, rss: Rss, site_token):
for msg in mailer.fetch():
if re.search(r".*STACOSYS.*\[(\d+)\:(\w+)\]", msg.subject, re.DOTALL):
if _reply_comment_email(lang, mailer, rss, msg, site_token):
mailer.delete(msg.id)
def _reply_comment_email(lang, mailer, rss, email: Email, site_token):
def _reply_comment_email(lang, mailer: Mailer, rss: Rss, email: Email, site_token):
m = re.search(r"\[(\d+)\:(\w+)\]", email.subject)
if not m:
@ -64,7 +66,7 @@ def _reply_comment_email(lang, mailer, rss, email: Email, site_token):
logger.info("commit comment: %d" % comment_id)
# rebuild RSS
rss.generate_site(token)
rss.generate()
# send approval confirmation email to admin
new_email_body = templater.get_template(lang, Template.APPROVE_COMMENT).render(
@ -77,9 +79,7 @@ def _reply_comment_email(lang, mailer, rss, email: Email, site_token):
def submit_new_comment(lang, site_name, site_token, site_admin_email, mailer):
for comment in Comment.select().where(Comment.notified.is_null()):
comment_list = (
"author: %s" % comment.author_name,
"site: %s" % comment.author_site,
@ -103,4 +103,3 @@ def submit_new_comment(lang, site_name, site_token, site_admin_email, mailer):
comment.notify_site_admin()
else:
logger.warn("rescheduled. send mail failure " + subject)

@ -21,6 +21,7 @@ class Mailer:
smtp_host,
smtp_port,
smtp_starttls,
smtp_ssl,
smtp_login,
smtp_password,
):
@ -32,6 +33,7 @@ class Mailer:
self._smtp_host = smtp_host
self._smtp_port = smtp_port
self._smtp_starttls = smtp_starttls
self._smtp_ssl = smtp_ssl
self._smtp_login = smtp_login
self._smtp_password = smtp_password
@ -65,7 +67,10 @@ class Mailer:
success = True
try:
s = smtplib.SMTP(self._smtp_host, self._smtp_port)
if self._smtp_ssl:
s = smtplib.SMTP_SSL(self._smtp_host, self._smtp_port)
else:
s = smtplib.SMTP(self._smtp_host, self._smtp_port)
if self._smtp_starttls:
s.starttls()
s.login(self._smtp_login, self._smtp_password)

@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask
app = Flask(__name__)
from flask import Flask
app = Flask(__name__)

@ -1,21 +1,25 @@
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from dataclasses import dataclass
from datetime import datetime
from typing import List
@dataclass
class Part:
content: str
content_type: str
@dataclass
class Attachment:
filename: str
content: str
content_type: str
@dataclass
class Email:
id: int
encoding: str

Loading…
Cancel
Save