aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/mail
diff options
context:
space:
mode:
Diffstat (limited to 'bin/mail')
-rwxr-xr-xbin/mail/comment.sh37
1 files changed, 24 insertions, 13 deletions
diff --git a/bin/mail/comment.sh b/bin/mail/comment.sh
index 299299a..f13b03d 100755
--- a/bin/mail/comment.sh
+++ b/bin/mail/comment.sh
@@ -6,9 +6,10 @@
6 6
7# 1. Check mail is for comment {{{ 7# 1. Check mail is for comment {{{
8 8
9# Restore mail into variable 9# Restore mail into variables
10MAIL="$(tr -d '\r')" 10MAIL="$(tr -d '\r')"
11header="$(<<<"$MAIL" sed '/^$/ q')" 11# join multi-line field value into one line
12header="$(<<<"$MAIL" sed '/^$/ q; :a; N; s/\n\s\+//; ta')"
12body="$(<<<"$MAIL" sed -n '/^$/,$ p' | sed '1d')" 13body="$(<<<"$MAIL" sed -n '/^$/,$ p' | sed '1d')"
13 14
14# determine mail is for comment by pattern 15# determine mail is for comment by pattern
@@ -38,8 +39,9 @@ markdown_bin=${markdown_bin:-markdown}
38shopt -s lastpipe; set +m; 39shopt -s lastpipe; set +m;
39 40
40# save each field of header into variables 41# save each field of header into variables
41<<<"$header" grep '^[a-zA-Z]' \ 42echo "$header" | \
42| while read field value; do 43while read field value; do
44 echo "$field" "$value" >>/tmp/header
43 declare field=$(<<<$field tr [:lower:] [:upper:] | tr '-' '_' | tr -d ':') 45 declare field=$(<<<$field tr [:lower:] [:upper:] | tr '-' '_' | tr -d ':')
44 declare $field="${value}" 46 declare $field="${value}"
45done 47done
@@ -66,13 +68,8 @@ output=$output_dir/${path}.comment.html
66# 5. Get comment from mail body {{{ 68# 5. Get comment from mail body {{{
67 69
68# check mail includes multiple part 70# check mail includes multiple part
69if [[ "$CONTENT_TYPE" =~ mixed ]]; then 71boundary="$(<<<"$CONTENT_TYPE" sed -En 's/^.*boundary="?([^"]+)"?.*$/\1/p')"
70 boundary="$(<<<"$CONTENT_TYPE" sed -En 's/^.*boundary="(.*)".*$/\1/p')" 72if [ -n "${boundary}" ]; then
71 if [ $boundary = "" ]; then
72 echo 'cannot get boundary from mail header' >&2
73 exit 1
74 fi
75
76 # print content of first mail part 73 # print content of first mail part
77 boundaryPat="\\|^--${boundary}\$|" 74 boundaryPat="\\|^--${boundary}\$|"
78 body="$(<<<"$body" sed -n "${boundaryPat},${boundaryPat} p" | sed -n "1,4d; ${boundaryPat} q; p")" 75 body="$(<<<"$body" sed -n "${boundaryPat},${boundaryPat} p" | sed -n "1,4d; ${boundaryPat} q; p")"
@@ -85,10 +82,17 @@ fi
85if [ ! -f $output ] || ! xmllint --html --nofixup-base-uris $output &>/dev/null; then 82if [ ! -f $output ] || ! xmllint --html --nofixup-base-uris $output &>/dev/null; then
86 <<-LAYOUT cat >$output 83 <<-LAYOUT cat >$output
87 <style> 84 <style>
85 ul {
86 padding-inline: 1rem;
87 li {
88 margin-block: 1rem;
89 }
90 }
88 .comment-body { 91 .comment-body {
92 margin-top: 0.5rem;
89 padding: 0.5rem; 93 padding: 0.5rem;
90 width: fit-content; 94 overflow-x: scroll;
91 border-radius: 8px; 95 border-radius: 4px;
92 background: lightblue; 96 background: lightblue;
93 p { 97 p {
94 margin: 0.5rem; 98 margin: 0.5rem;
@@ -100,6 +104,9 @@ if [ ! -f $output ] || ! xmllint --html --nofixup-base-uris $output &>/dev/null;
100 &:has(li) { 104 &:has(li) {
101 display: block; 105 display: block;
102 } 106 }
107 ul {
108 padding-inline: 1rem 0;
109 }
103 } 110 }
104 </style> 111 </style>
105 <ul> 112 <ul>
@@ -113,6 +120,8 @@ if [ -n "${IN_REPLY_TO}" ]; then
113fi 120fi
114# }}} 121# }}}
115# insert comment into output file {{{ 122# insert comment into output file {{{
123
124# FIXME prevent pattern <!-- ${MESSAGE_ID} --> shown in <pre> block
116<<-COMMENT sed -i "${line:-/<ul>/}r /dev/stdin" $output 125<<-COMMENT sed -i "${line:-/<ul>/}r /dev/stdin" $output
117 <li> 126 <li>
118 127
@@ -136,3 +145,5 @@ COMMENT
136# }}} 145# }}}
137 146
138# }}} 147# }}}
148
149# vim:fdm=marker