diff --git a/mastodon_email_bridge/mastodon_email_bridge.py b/mastodon_email_bridge/mastodon_email_bridge.py index 2bc7844..602da78 100755 --- a/mastodon_email_bridge/mastodon_email_bridge.py +++ b/mastodon_email_bridge/mastodon_email_bridge.py @@ -129,6 +129,12 @@ class MastodonEmailBridge: ) return url for data in result.json(): + if data['in_reply_to_id']: + self._log.debug( + "This post is a reply to '%s', fetching it", + data['in_reply_to_id'] + ) + data['meb_reply_to'] = self.get_post(data['in_reply_to_id']) if int(data['id']) not in self.sent_items: self.send_mail(data) else: @@ -140,10 +146,25 @@ class MastodonEmailBridge: next_url = slink[0].replace('<', '').replace('>', '') return next_url + def get_post(self, post_id): + '''Get a single post''' + post = {} + self._log.debug( + "Getting post URL 'https://%s/api/v1/statuses/%s'...", + self.config['server'], + post_id + ) + result = self.session.get(f"https://{self.config['server']}/api/v1/statuses/{post_id}") + post = result.json() + return post + def send_mail(self, data): '''Send an email with the post composed''' msg = MIMEMultipart('alternative') - msg['Subject'] = f"FediPost from {data['account']['display_name']} ({data['account']['username']})" + 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'] html_template = self.j2env.get_template("new_post.html.j2") @@ -248,7 +269,7 @@ class MastodonEmailBridge: ) @click.option('--limit', '-L', default=0, help='Mastodon token with read access.') @click.option('--limit-per-request', '-R', default=40, help='Mastodon token with read access.') -@click.option('--wait', '-w', default=5, help='Seconds to wait between requests to avoid rate limits.') +@click.option('--wait', '-w', default=60, help='Seconds to wait between requests to avoid rate limits.') @click.option('--recipient', '-r', required=True, help='Recipient email to get the posts.') @click.option( '--sender',