From 5dca8aafe1527324f32326d368547b91f98c9ce6 Mon Sep 17 00:00:00 2001 From: Yax <1949284+kianby@users.noreply.github.com> Date: Tue, 19 Jan 2021 18:59:57 +0100 Subject: [PATCH] get rid of site token retrieved from DB --- stacosys/core/cron.py | 13 ++++++------- stacosys/interface/scheduler.py | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/stacosys/core/cron.py b/stacosys/core/cron.py index 9974889..292d4e8 100644 --- a/stacosys/core/cron.py +++ b/stacosys/core/cron.py @@ -19,14 +19,14 @@ template_path = os.path.abspath(os.path.join(current_path, "../templates")) templater = Templater(template_path) -def fetch_mail_answers(lang, mailer, rss): +def fetch_mail_answers(lang, mailer, 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): + if _reply_comment_email(lang, mailer, rss, msg, site_token): mailer.delete(msg.id) -def _reply_comment_email(lang, mailer, rss, email: Email): +def _reply_comment_email(lang, mailer, rss, email: Email, site_token): m = re.search(r"\[(\d+)\:(\w+)\]", email.subject) if not m: @@ -34,6 +34,9 @@ def _reply_comment_email(lang, mailer, rss, email: Email): return comment_id = int(m.group(1)) token = m.group(2) + if token != site_token: + logger.warn("ignore corrupted email. Unknown token %d" % comment_id) + return # retrieve site and comment rows try: @@ -46,10 +49,6 @@ def _reply_comment_email(lang, mailer, rss, email: Email): logger.warn("ignore already published email. token %d" % comment_id) return - if comment.site.token != token: - logger.warn("ignore corrupted email. Unknown token %d" % comment_id) - return - if not email.plain_text_content: logger.warn("ignore empty email") return diff --git a/stacosys/interface/scheduler.py b/stacosys/interface/scheduler.py index 6762ef0..832a0d6 100644 --- a/stacosys/interface/scheduler.py +++ b/stacosys/interface/scheduler.py @@ -16,7 +16,7 @@ class JobConfig(object): { "id": "fetch_mail", "func": "stacosys.core.cron:fetch_mail_answers", - "args": [lang, mailer, rss], + "args": [lang, mailer, rss, site_token], "trigger": "interval", "seconds": imap_polling_seconds, },