#!/bin/bash # (re)quote input lines email using $QUOTE to appropriate level. # It's intended use is for cleaning up mails or reformatting comments etc. # # License: LGPLv2 # # Note fmt has the --prefix option that does the appropriate thing # for C comments for e.g. so the main use of this script is for # badly formatted email. setglobal QUOTE = '"> '" setglobal MIN_TEXT_LEN = '8' if test $Argc == 3 { setglobal QUOTE = $1 shift } if test $Argc != 2 { echo "Usage: $0 [quote_string(> )] response_level(starting at 0) line_width" >&2 exit 1 } setglobal RESPONSE_LEVEL = $1 setglobal TEXT_WIDTH = $[expr $2 - $1 '*' $(#QUOTE)] if test $TEXT_WIDTH -lt $MIN_TEXT_LEN { echo "Aborting as line length will be less than $MIN_TEXT_LEN" >&2 exit 1 } for i in [$[seq 1 $RESPONSE_LEVEL]] { setglobal RESPONSE_DELIM = ""$RESPONSE_DELIM$QUOTE"" } setglobal RESPONSE_DELIM = $[echo $RESPONSE_DELIM | sed 's/[ ]*$//] #remove tailing spaces setglobal QUOTE_DEL = $[echo $QUOTE | tr -d ' ] tr -ds "$QUOTE_DEL\\n" ' ' | fmt -w$TEXT_WIDTH | sed -e "s/^[ ]*\(.*\)/$RESPONSE_DELIM \1/"