From 92c40adcd77c9149eff061ae227e7c7fc59f4a78 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Sat, 10 Aug 2024 18:03:31 +0300 Subject: [PATCH] Add template subject --- README.md | 2 + .../mastodon_email_bridge.py | 11 +++-- pyproject.toml | 2 +- setup.cfg | 2 +- templates/new_post.html.j2 | 46 +++++++++++-------- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index aefb682..7a5266c 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/mastodon_email_bridge/mastodon_email_bridge.py b/mastodon_email_bridge/mastodon_email_bridge.py index 22e89b4..6abc34f 100755 --- a/mastodon_email_bridge/mastodon_email_bridge.py +++ b/mastodon_email_bridge/mastodon_email_bridge.py @@ -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.") diff --git a/pyproject.toml b/pyproject.toml index 9ce302c..0c77084 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" }] diff --git a/setup.cfg b/setup.cfg index 28f4fab..0c64a1e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = mastodon_email_bridge -version = 0.0.7 +version = 0.0.8 [options] packages = mastodon_email_bridge diff --git a/templates/new_post.html.j2 b/templates/new_post.html.j2 index 051add3..1e82ded 100644 --- a/templates/new_post.html.j2 +++ b/templates/new_post.html.j2 @@ -7,7 +7,10 @@