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 8364b4bd868dcc5bd0299d88be90a72d5b260dc1
parent e5126a66082ce7f72cdad8088414a260530f64b7
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Thu, 25 Apr 2019 13:54:56 +0200

Do not reserve space if header fields are empty

Diffstat:
M.mutt/muttprint-groff.sh | 23+++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/.mutt/muttprint-groff.sh b/.mutt/muttprint-groff.sh @@ -3,7 +3,7 @@ PDIR="$HOME/tmp" mkdir -p "$PDIR" 2>/dev/null -#rm -f "$PDIR"/mutt_* +rm -f "$PDIR"/mutt_* infile="$(mktemp "$PDIR"/mutt_XXXXXXXX.txt)" tmpfile="$(mktemp "$PDIR"/mutt_XXXXXXXX.roff)" @@ -19,29 +19,32 @@ cat "${1:--}" > "$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" +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" | tr ',' '\n')" -mail_cc="$(grep '^Cc: ' "$infile" | tr ',' '\n')" +mail_cc="$(grep '^C[Cc]: ' "$infile" | tr ',' '\n')" mail_subject="$(grep '^Subject: ' "$infile")" { - printf ".TL\n%s\n" "$mail_subject" | sed 's/^Subject: //'; - printf ".AU\n%s\n" "$mail_from"; - printf ".AU\n%s\n" "$mail_to"; - printf ".AU\n%s\n" "$mail_cc"; - printf ".AI\n%s\n" "$mail_date"; + [ -n "$mail_subject" ] && printf ".TL\n%s\n" "$mail_subject" | sed 's/^Subject: //'; + [ -n "$mail_from" ] && printf ".AU\n%s\n" "$mail_from"; + [ -n "$mail_to" ] && printf ".AU\n%s\n" "$mail_to"; + [ -n "$mail_cc" ] && printf ".AU\n%s\n" "$mail_cc"; + [ -n "$mail_date" ] && printf ".AI\n%s\n" "$mail_date"; printf ".LP\n"; - grep -v "^Date:\|^From:\|^To:\|^Subject:\|^Cc:\|^X-Mailer:\|^User-Agent:" "$infile" |\ + grep -v "^Date:\|^From:\|^To:\|^Subject:\|^C[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/\(From\|Date\|To\|C[Cc]\|Subject\): /\n\1: /g' |\ sed 's/\(Links:\)/\n\1\n/g' |\ sed 's/\(References:\)/\n\1\n/g' |\ cat --squeeze-blank; @@ -52,4 +55,4 @@ preconv "$tmpfile" | groff -ms -T pdf > "$outfile" xdg-open "$outfile" & sleep 1 -rm "$infile" "$tmpfile" "$outfile" +#rm "$infile" "$tmpfile" "$outfile"