From d75cc3e904130375e9ac52f0791871f05f4e7f60 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Sat, 3 Aug 2024 15:42:58 +0300 Subject: [PATCH] Fix sender template --- mastodon_email_bridge/mastodon_email_bridge.py | 13 +++++++------ templates/new_post.html.j2 | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/mastodon_email_bridge/mastodon_email_bridge.py b/mastodon_email_bridge/mastodon_email_bridge.py index 83f73cf..2a470a1 100755 --- a/mastodon_email_bridge/mastodon_email_bridge.py +++ b/mastodon_email_bridge/mastodon_email_bridge.py @@ -167,13 +167,15 @@ class MastodonEmailBridge: def send_mail(self, data): '''Send an email with the post composed''' + sender = self._str_template(self.config['sender'], data) + recipient = self._str_template(self.config['recipient'], data) msg = MIMEMultipart('alternative') if data['in_reply_to_id']: msg['Subject'] = f"FediReply from {data['account']['display_name']} ({data['account']['username']})" else: msg['Subject'] = f"FediPost from {data['account']['display_name']} ({data['account']['username']})" - msg['From'] = self.config['sender'] - msg['To'] = self.config['recipient'] + msg['From'] = sender + msg['To'] = recipient html_template = self.j2env.get_template("new_post.html.j2") html_source = html_template.render( data=data, @@ -207,8 +209,6 @@ class MastodonEmailBridge: if self.config['mail_user'] is not None: conn.login(self.config['mail_user'], self.config['mail_pass']) self._log.debug("Sending email for post with id '%s'...", data['id']) - sender = self._str_replace_template(self.config['sender'], data) - recipient = self._str_replace_template(self.config['recipient'], data) conn.sendmail(sender, recipient, msg.as_string()) conn.quit() self._log.debug("Adding entry to database...") @@ -218,9 +218,10 @@ class MastodonEmailBridge: self.sent_items.append(data['id']) return True - def _str_replace_template(self, template_string, data): + def _str_template(self, template_string, data): template = self.j2env.from_string(template_string) - return template.render(data=data) + result = template.render(data=data) + return result def _init_log(self): ''' Initialize log object ''' diff --git a/templates/new_post.html.j2 b/templates/new_post.html.j2 index 7b95857..dbb6489 100644 --- a/templates/new_post.html.j2 +++ b/templates/new_post.html.j2 @@ -58,7 +58,7 @@
{% if media['type'] == 'image' %} {{ media['description'] }} - {% elif media['type'] == 'video' %} + {% elif media['type'] == 'video' or media['type'] == 'gifv' %}