Fix sender template
This commit is contained in:
parent
f3c2d0acf6
commit
d75cc3e904
2 changed files with 8 additions and 7 deletions
|
@ -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 '''
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
<DIV STYLE="margin:2%;">
|
||||
{% if media['type'] == 'image' %}
|
||||
<IMG SRC="{{ media['preview_url'] }}" ALT="{{ media['description'] }}">
|
||||
{% elif media['type'] == 'video' %}
|
||||
{% elif media['type'] == 'video' or media['type'] == 'gifv' %}
|
||||
<video controls width="100%">
|
||||
<source src="{{ media['url'] }}" type="video/webm" />
|
||||
<A HREF="{{ media['url'] }}">Download video</A>
|
||||
|
|
Loading…
Reference in a new issue