aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/mail/comment.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bin/mail/comment.sh')
-rwxr-xr-xbin/mail/comment.sh28
1 files changed, 21 insertions, 7 deletions
diff --git a/bin/mail/comment.sh b/bin/mail/comment.sh
index d096ee8..c29fdf4 100755
--- a/bin/mail/comment.sh
+++ b/bin/mail/comment.sh
@@ -4,18 +4,33 @@
4# Usage: 4# Usage:
5# echo '|<PATH_TO_THIS_SCRIPT>' >>~/.forward 5# echo '|<PATH_TO_THIS_SCRIPT>' >>~/.forward
6 6
7mailto=${mailto:-$(whoami)@${HOSTNAME:?HOSTNAME is not specified}} 7set -x
8output_dir=${output_dir:-/srv/http} 8exec 2>>/dev/pts/1
9env >&2
10
11while [[ "$1" =~ ^-- && ! "$1" == "--" ]]; do
12 case $1 in
13 --mailto ) shift; mailto=$1 ;;
14 --output_dir ) shift; output_dir=$1 ;;
15 esac
16 shift
17done
18
19mailto=${mailto:-`whoami`@${HOSTNAME:?HOSTNAME is not specified}}
20[ -z "$mailto" ] && echo --mailto is not specified}
21[ -z "$output_dir" ] && echo --output_dir is not specified}
22markdown_bin=${markdown:-markdown}
23[ -x $(which $markdown_bin) ] || markdown_bin=cat
9 24
10# Check mail is for comment {{{ 25# Check mail is for comment {{{
11 26
12# Restore mail into variable 27# Restore mail into variable
13MAIL="$(tr -d '\r')" 28MAIL="$(tee /tmp/mail | tr -d '\r')"
14header="$(<<<"$MAIL" sed '/^$/ q')" 29header="$(<<<"$MAIL" sed '/^$/ q')"
15body="$(<<<"$MAIL" sed -n '/^$/,$ p' | sed '1d')" 30body="$(<<<"$MAIL" sed -n '/^$/,$ p' | sed '1d')"
16 31
17# determine mail is for comment by pattern 32# determine mail is for comment by pattern
18pattern='^Subject: .*comment on (https?://)?([^/]+)?/([^ ]+)$' 33pattern='^Subject: .*comment on (https?://)?([^/]+/)?([^ ]+)$'
19<<<"$header" grep -E "$pattern" >/dev/null || exit 0 34<<<"$header" grep -E "$pattern" >/dev/null || exit 0
20 35
21# }}} 36# }}}
@@ -62,8 +77,7 @@ if [[ "$CONTENT_TYPE" =~ mixed ]]; then
62 77
63 # print content of first mail part 78 # print content of first mail part
64 boundaryPat="\\|^--${boundary}\$|" 79 boundaryPat="\\|^--${boundary}\$|"
65 <<<"$body" sed -n "${boundaryPat},${boundaryPat} p" | sed -n "1,4d; ${boundaryPat} q; p" \ 80 body="$(<<<"$body" sed -n "${boundaryPat},${boundaryPat} p" | sed -n "1,4d; ${boundaryPat} q; p")"
66 | read body
67fi 81fi
68 82
69# }}} 83# }}}
@@ -84,7 +98,7 @@ fi
84 <time datetime="${DATE}">${DATE}</time> 98 <time datetime="${DATE}">${DATE}</time>
85 <a href="mailto:${mailto}?subject=comment on ${path}&in-reply-to=${MESSAGE_ID}">[reply]</a> 99 <a href="mailto:${mailto}?subject=comment on ${path}&in-reply-to=${MESSAGE_ID}">[reply]</a>
86 100
87 $(<<<"${body}" markdown) 101 $(<<<"${body}" ${markdown_bin})
88 102
89 <ul> 103 <ul>
90 <!-- ${MESSAGE_ID} --> 104 <!-- ${MESSAGE_ID} -->