Add template subject

This commit is contained in:
Antonio J. Delgado 2024-08-10 18:03:31 +03:00
parent 83c23ffe69
commit 92c40adcd7
5 changed files with 39 additions and 24 deletions

View file

@ -48,6 +48,8 @@ Customize the templates (if you know HTML, CSS and Jinja2) and run the command.
-P, --mail-pass TEXT User password for SMTP Mail server to send -P, --mail-pass TEXT User password for SMTP Mail server to send
emails. emails.
-p, --mail-server-port INTEGER SMTP Mail server port to send emails. -p, --mail-server-port INTEGER SMTP Mail server port to send emails.
-t, --subjet-template TEXT Jinja2 template for the subject of the
emails.
-l, --log-file TEXT File to store all debug messages. -l, --log-file TEXT File to store all debug messages.
--config FILE Read configuration from FILE. --config FILE Read configuration from FILE.
--help Show this message and exit. --help Show this message and exit.

View file

@ -171,10 +171,7 @@ class MastodonEmailBridge:
sender = self._str_template(self.config['sender'], data) sender = self._str_template(self.config['sender'], data)
recipient = self._str_template(self.config['recipient'], data) recipient = self._str_template(self.config['recipient'], data)
msg = MIMEMultipart('alternative') msg = MIMEMultipart('alternative')
if data['in_reply_to_id']: msg['Subject'] = self._str_template(self.config['subjet_template'], data)
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'] = sender msg['From'] = sender
msg['To'] = recipient msg['To'] = recipient
html_template = self.j2env.get_template("new_post.html.j2") html_template = self.j2env.get_template("new_post.html.j2")
@ -324,6 +321,12 @@ class MastodonEmailBridge:
default=465, default=465,
help='SMTP Mail server port to send emails.' help='SMTP Mail server port to send emails.'
) )
@click.option(
'--subjet-template',
'-t',
default='{% if data["in_reply_to_id"] %}FediReply{% else %}FediPost{% endif %} from {{ data["account"]["display_name"] }} ({{ data["account"]["username"] }}){% for tag in data["tags"] %} #{{ tag["name"] }}{% endfor %}',
help='Jinja2 template for the subject of the emails.'
)
@click.option('--log-file', '-l', help="File to store all debug messages.") @click.option('--log-file', '-l', help="File to store all debug messages.")
# @click.option("--dummy","-n", is_flag=True, # @click.option("--dummy","-n", is_flag=True,
# help="Don't do anything, just show what would be done.") # help="Don't do anything, just show what would be done.")

View file

@ -7,7 +7,7 @@ Homepage = "https://codeberg.org/adelgado/mastodon_email_bridge"
[project] [project]
name = "mastodon_email_bridge" name = "mastodon_email_bridge"
version = "0.0.7" version = "0.0.8"
description = "Redirect your Mastodon Home timeline to your email" description = "Redirect your Mastodon Home timeline to your email"
readme = "README.md" readme = "README.md"
authors = [{ name = "Antonio J. Delgado", email = "ad@susurrando.com" }] authors = [{ name = "Antonio J. Delgado", email = "ad@susurrando.com" }]

View file

@ -1,6 +1,6 @@
[metadata] [metadata]
name = mastodon_email_bridge name = mastodon_email_bridge
version = 0.0.7 version = 0.0.8
[options] [options]
packages = mastodon_email_bridge packages = mastodon_email_bridge

View file

@ -7,7 +7,10 @@
<style> <style>
body { background-color: black; color: #999;} body { background-color: black; color: #999;}
p { } p { }
div { margin: 1%; } div {
margin: 1%;
{# border-style: dashed; #}
}
/* unvisited link */ /* unvisited link */
a:link { a:link {
color: blueviolet; color: blueviolet;
@ -28,36 +31,43 @@
<BODY> <BODY>
{% if data['url'] != "" %} {% if data['url'] != "" %}
<!-- URL --> <!-- URL -->
<DIV> <A TARGET="_blank" HREF="{{ data['url'] }}">Post original page</A>
<A TARGET="_blank" HREF="{{ data['url'] }}">Post original page</A>
</DIV>
{% endif %} {% endif %}
<!-- account bloc -->
<DIV>
<A HREF="{{ data['account']['url'] }}" TARGET="_blank"></A>
<IMG ALT="{{ data['account']['display_name'] }} avatar image" SRC="{{ data['account']['avatar_static'] }}" STYLE="width:64px;height:64px;margin:1%;float: left;">
<B>{{ data['account']['display_name'] }} ({{ data['account']['username'] }})</B>
</A>
</DIV>
<!-- creation_date --> <!-- creation_date -->
<DIV STYLE='font-size: 12px;'> <P STYLE='font-size: 12px;'>
{% set created_date = time.strptime(data['created_at'], '%Y-%m-%dT%H:%M:%S.%fZ') %} {% set created_date = time.strptime(data['created_at'], '%Y-%m-%dT%H:%M:%S.%fZ') %}
{{ time.strftime('%Y-%m-%d %H:%M:%S %zUTC', created_date) }} {{ time.strftime('%Y-%m-%d %H:%M:%S %zUTC', created_date) }}
</DIV> </P>
<!-- account bloc -->
<TABLE>
<TR>
<TD>
<A HREF="{{ data['account']['url'] }}" TARGET="_blank">
<IMG ALT="{{ data['account']['display_name'] }} avatar image" SRC="{{ data['account']['avatar_static'] }}" STYLE="width:64px;height:64px;margin:1%;float: left;">
</A>
</TD>
<TD>
<A HREF="{{ data['account']['url'] }}" TARGET="_blank">
<B>{{ data['account']['display_name'] }} ({{ data['account']['acct'] }})</B>
</A>
</TD>
</TR>
</TABLE>
<!-- content block --> <!-- content block -->
<DIV STYLE='font-size: 24px;'> <DIV STYLE='font-size: 24px;'>
{% if data['spoiler'] != "" and data['spoiler'] != null %}
<!-- spoiler --> <!-- spoiler -->
<DIV CLASS='item-spoiler'> <DIV CLASS='item-spoiler'>
{{ data['spoiler'] }} {{ data['spoiler'] }}
</DIV> </DIV>
{% endif %}
<!-- item-content --> <!-- item-content -->
<DIV CLASS='item-content' STYLE="margin:5%;"> <DIV CLASS='item-content' STYLE="margin:0.5%;background-color:#111;padding:0.5%;">
{{ data['content'] }} {{ data['content'] }}
<!-- media --> <!-- media -->
{% if data['media_attachments'] %} {% if data['media_attachments'] %}
{% for media in data['media_attachments'] %} {% for media in data['media_attachments'] %}
<DIV STYLE="margin:2%;">
{% if media['type'] == 'image' %} {% if media['type'] == 'image' %}
<IMG SRC="{{ media['preview_url'] }}" ALT="{{ media['description'] }}"> <IMG SRC="{{ media['preview_url'] }}" ALT="{{ media['description'] }}">
{% elif media['type'] == 'video' or media['type'] == 'gifv' %} {% elif media['type'] == 'video' or media['type'] == 'gifv' %}
@ -69,7 +79,6 @@
<audio controls src="{{ media['url'] }}"></audio> <audio controls src="{{ media['url'] }}"></audio>
<A HREF="{{ media['url'] }}">Download audio</A> <A HREF="{{ media['url'] }}">Download audio</A>
{% endif %} {% endif %}
</DIV>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% if data['meb_reply_to'] %} {% if data['meb_reply_to'] %}
@ -171,9 +180,10 @@
</DIV> </DIV>
</DIV> </DIV>
{# <!-- card -->{{ data['card'] }} #} {# <!-- card -->{{ data['card'] }} #}
<!-- Raw JSON data --> <!-- Raw JSON data
<DIV STYLE="margin-top:15%;font-size: 12px;"> <DIV STYLE="margin-top:15%;font-size: 12px;">
Raw JSON data: Raw JSON data:
<PRE>{{ json_raw }}</PRE> <PRE>{{ json_raw }}</PRE>
</DIV> </DIV>
-->
</BODY> </BODY>