From feee1a1bdd0afb5657a0e08198b6a35123c0bc38 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Sat, 3 Dec 2022 20:57:27 +0800 Subject: Update script of mastodon --- tools/sns/mastodon.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/sns/mastodon.sh b/tools/sns/mastodon.sh index 1118c20..fb93bcd 100755 --- a/tools/sns/mastodon.sh +++ b/tools/sns/mastodon.sh @@ -1,12 +1,17 @@ #! /bin/bash +# Restore mail in variable MAIL="$(cat)" # Only execute the following script when mail receiver is mastodon@topo.tw -grep -qE "^To: .*mastodon@topo.tw[>]?$" <<<"$MAIL" || exit 0 +grep -qE "^X-Original-To: .*mastodon@topo.tw[>]?$" <<<"$MAIL" || exit 0 +# A little hacky way to check if mail is sent from me +sed -nE '/^Received: /p;/^$/q' <<<"$(MAIL)" | wc -l | xargs -i test {} -lt 2 || exit 0 +# Leave log date >>~/Downloads/mastodon.log echo $$ >>~/Downloads/mastodon.log awk -v RS= 'NR>1' <<<"$MAIL" >>~/Downloads/mastodon.log -#awk -v RS= 'NR>1' <<<"$MAIL" | toot post >/tmp/mastodon.log +# Use toot to send message on g0v.social +awk -v RS= 'NR>1' <<<"$MAIL" | toot post >>/tmp/mastodon.log -- cgit v1.2.3-70-g09d2