dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit f9dea675dfef98a981a9e861ac0297e47794f57a
parent 78b32c7c439a7affe05d718735465f78e75427aa
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Thu, 25 Apr 2019 13:10:42 +0200

Improve parsing

Diffstat:
M.mutt/muttprint-groff.sh | 33+++++++++++++++++++--------------
1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/.mutt/muttprint-groff.sh b/.mutt/muttprint-groff.sh @@ -1,8 +1,9 @@ #!/bin/sh -PDIR="$HOME/tmp/mutt_print" +PDIR="$HOME/tmp" mkdir -p "$PDIR" 2>/dev/null +#rm -f "$PDIR"/mutt_* infile="$(mktemp "$PDIR"/mutt_XXXXXXXX.txt)" tmpfile="$(mktemp "$PDIR"/mutt_XXXXXXXX.roff)" @@ -15,13 +16,15 @@ echo "outfile = $outfile" cat "${1:--}" > "$infile" # join lines starting with space with previous line -sed -i '$!N;s/\n //;P;D' "$infile" +#sed -i '$!N;s/\n / /;P;D' "$infile" +sed -i '$!N;s/\n / /;P;D' "$infile" +sed -i '$!N;s/\n / /;P;D' "$infile" echo "formatting $infile to groff format in $tmpfile" mail_date="$(grep '^Date: ' "$infile")" mail_from="$(grep '^From: ' "$infile")" -mail_to="$(grep '^To: ' "$infile")" -mail_cc="$(grep '^Cc: ' "$infile")" +mail_to="$(grep '^To: ' "$infile" | tr ',' '\n')" +mail_cc="$(grep '^Cc: ' "$infile" | tr ',' '\n')" mail_subject="$(grep '^Subject: ' "$infile")" { @@ -31,20 +34,22 @@ mail_subject="$(grep '^Subject: ' "$infile")" printf ".AU\n%s\n" "$mail_cc"; printf ".AI\n%s\n" "$mail_date"; printf ".LP\n"; - grep -v "^Date:\|^From:\|^To:\|^Subject:\|^Cc:\|^X-Mailer:\|^User-Agent:" "$infile" | \ - sed 's/^>*//;s/^ //' | \ - sed 's/\(Fra\|Dato\|Til\|Emne\): /\n\1: /g' | \ - sed 's/\(From\|Date\|To\|Cc\|Subject\): /\n\1: /g' | \ - sed 's/^\[\([0-9]\)\] /\n[\1]: /g' | \ - sed '/^Links:$/Q' | \ - sed 's/\([-]*\)/\1\n/' | \ + grep -v "^Date:\|^From:\|^To:\|^Subject:\|^Cc:\|^X-Mailer:\|^User-Agent:" "$infile" |\ + sed 's/^>\s*$//' |\ + sed 's/ *\(---*\)/\1\n/' |\ + awk -v RS= -v ORS='\n\n' '{$1=$1}1' |\ + sed 's/^> *\(.*\)$/.I "\1"/' |\ + sed 's/ > / /g' |\ + sed 's/\(Fra\|Dato\|Til\|Emne\): /\n\1: /g' |\ + sed 's/\(From\|Date\|To\|Cc\|Subject\): /\n\1: /g' |\ + sed 's/\(Links:\)/\n\1\n/g' |\ + sed 's/\(References:\)/\n\1\n/g' |\ cat --squeeze-blank; - } \ - > "$tmpfile" + } > "$tmpfile" echo "running groff $tmpfile $outfile" preconv "$tmpfile" | groff -ms -T pdf > "$outfile" xdg-open "$outfile" & sleep 1 -#rm "$infile" "$tmpfile" "$outfile" +rm "$infile" "$tmpfile" "$outfile"