From d1b57c1d68fa60a4a67c208f29b739ef0f20d5c5 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Tue, 3 Dec 2024 17:33:13 +0800 Subject: Update --- bin/log/shellrc | 2 +- bin/mail/append_authorized_key.sh | 2 +- bin/mail/comment.sh | 41 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100755 bin/mail/comment.sh (limited to 'bin') diff --git a/bin/log/shellrc b/bin/log/shellrc index a39e291..b3c95fc 100644 --- a/bin/log/shellrc +++ b/bin/log/shellrc @@ -1,7 +1,7 @@ # about vimwiki alias cdl='cd ~/log' alias chw='tig -C ~/log' -ww() { entry="${1:-plan.context}"; vim ~/log/${entry%%.md}.md; } +ww() { entry="${1:-inbox}"; vim ~/log/${entry%%.md}.md; } wj() { echo "$@" >>~/log/buffer.md; } wg() { grep -r "$@" --color --exclude-dir={logseq,.git,.obsidian} ~/log; } wi() { cat ~/log/${1%%.md}.md; } diff --git a/bin/mail/append_authorized_key.sh b/bin/mail/append_authorized_key.sh index 950be90..3686959 100755 --- a/bin/mail/append_authorized_key.sh +++ b/bin/mail/append_authorized_key.sh @@ -13,7 +13,7 @@ MAIL="$(cat)" test -f ~/.config/passphase || exit 1 PASSPHASE="$(cat ~/.config/passphase)" -# Only execute the following script when header matched +# Check passphase, or exit 0 grep -qE "^Passphase: ${PASSPHASE}" <<<"$MAIL" || exit 0 # Append comment and last line to ~/.ssh/authorized_keys diff --git a/bin/mail/comment.sh b/bin/mail/comment.sh new file mode 100755 index 0000000..807bcb2 --- /dev/null +++ b/bin/mail/comment.sh @@ -0,0 +1,41 @@ +#! /bin/bash + +output_dir=${output_dir:-/srv/http} + +# Restore mail into variable +MAIL="$(tr -d '\r')" +headers="$(<<<"$MAIL" sed '/^$/ q')" +contents="$(<<<"$MAIL" sed -n '/^$/,$ p' | sed '1d')" + +# enable execute last command in pipe under current shell +shopt -s lastpipe; set +m; + +# get route (target page of comment) and id +<<<"$MAIL" sed -En '/^To: comment+/ {s/^To: comment\+([^+]+)\+?(.*)@.*$/\1 \2/p; q}; /^$/q' \ +| read route id + +# sender want comment on some page, but find no route for this +if [ $route = "" ]; then + echo 'rcpt "comment+" not matched' >&2 + exit 1 +fi + +output=$output_dir/${route#/}.comment +exec 1>>$output + +# check mail includes multiple part +<<<"$headers" grep '^Content-Type:.*mixed' >/dev/null +if [ $? -eq 0 ]; then + boundary="$(<<<"$headers" sed -En 's/^Content-Type:.*boundary="(.*)".*$/\1/p')" + if [ $boundary = "" ]; then + echo 'cannot get boundary from mail header' >&2 + exit 1 + fi + + # print content of first mail part + pattern="\\@^--${boundary}\$@" + <<<"$contents" sed -n "${pattern},${pattern} p" | sed -n "1,4d; ${pattern} q; p" +else + # print content + <<<"$contents" sed '/^$/,$ p' +fi -- cgit v1.2.3-70-g09d2