diff options
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/mail/comment.sh | 28 |
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 | ||
| 7 | mailto=${mailto:-$(whoami)@${HOSTNAME:?HOSTNAME is not specified}} | 7 | set -x |
| 8 | output_dir=${output_dir:-/srv/http} | 8 | exec 2>>/dev/pts/1 |
| 9 | env >&2 | ||
| 10 | |||
| 11 | while [[ "$1" =~ ^-- && ! "$1" == "--" ]]; do | ||
| 12 | case $1 in | ||
| 13 | --mailto ) shift; mailto=$1 ;; | ||
| 14 | --output_dir ) shift; output_dir=$1 ;; | ||
| 15 | esac | ||
| 16 | shift | ||
| 17 | done | ||
| 18 | |||
| 19 | mailto=${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} | ||
| 22 | markdown_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 |
| 13 | MAIL="$(tr -d '\r')" | 28 | MAIL="$(tee /tmp/mail | tr -d '\r')" |
| 14 | header="$(<<<"$MAIL" sed '/^$/ q')" | 29 | header="$(<<<"$MAIL" sed '/^$/ q')" |
| 15 | body="$(<<<"$MAIL" sed -n '/^$/,$ p' | sed '1d')" | 30 | body="$(<<<"$MAIL" sed -n '/^$/,$ p' | sed '1d')" |
| 16 | 31 | ||
| 17 | # determine mail is for comment by pattern | 32 | # determine mail is for comment by pattern |
| 18 | pattern='^Subject: .*comment on (https?://)?([^/]+)?/([^ ]+)$' | 33 | pattern='^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 | ||
| 67 | fi | 81 | fi |
| 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} --> |