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
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.
--config FILE Read configuration from FILE.
--help Show this message and exit.

View file

@ -171,10 +171,7 @@ class MastodonEmailBridge:
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['Subject'] = self._str_template(self.config['subjet_template'], data)
msg['From'] = sender
msg['To'] = recipient
html_template = self.j2env.get_template("new_post.html.j2")
@ -324,6 +321,12 @@ class MastodonEmailBridge:
default=465,
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("--dummy","-n", is_flag=True,
# 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]
name = "mastodon_email_bridge"
version = "0.0.7"
version = "0.0.8"
description = "Redirect your Mastodon Home timeline to your email"
readme = "README.md"
authors = [{ name = "Antonio J. Delgado", email = "ad@susurrando.com" }]

View file

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

View file

@ -7,7 +7,10 @@
<style>
body { background-color: black; color: #999;}
p { }
div { margin: 1%; }
div {
margin: 1%;
{# border-style: dashed; #}
}
/* unvisited link */
a:link {
color: blueviolet;
@ -28,36 +31,43 @@
<BODY>
{% if data['url'] != "" %}
<!-- URL -->
<DIV>
<A TARGET="_blank" HREF="{{ data['url'] }}">Post original page</A>
</DIV>
<A TARGET="_blank" HREF="{{ data['url'] }}">Post original page</A>
{% 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 -->
<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') %}
{{ 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 -->
<DIV STYLE='font-size: 24px;'>
{% if data['spoiler'] != "" and data['spoiler'] != null %}
<!-- spoiler -->
<DIV CLASS='item-spoiler'>
{{ data['spoiler'] }}
</DIV>
{% endif %}
<!-- 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'] }}
<!-- media -->
{% if data['media_attachments'] %}
{% for media in data['media_attachments'] %}
<DIV STYLE="margin:2%;">
{% if media['type'] == 'image' %}
<IMG SRC="{{ media['preview_url'] }}" ALT="{{ media['description'] }}">
{% elif media['type'] == 'video' or media['type'] == 'gifv' %}
@ -69,7 +79,6 @@
<audio controls src="{{ media['url'] }}"></audio>
<A HREF="{{ media['url'] }}">Download audio</A>
{% endif %}
</DIV>
{% endfor %}
{% endif %}
{% if data['meb_reply_to'] %}
@ -171,9 +180,10 @@
</DIV>
</DIV>
{# <!-- card -->{{ data['card'] }} #}
<!-- Raw JSON data -->
<!-- Raw JSON data
<DIV STYLE="margin-top:15%;font-size: 12px;">
Raw JSON data:
<PRE>{{ json_raw }}</PRE>
</DIV>
-->
</BODY>