Debian Codegraph @

mail-format.sh

raw symbols SCIP
1 #!/bin/bash
2 # mail-format.sh (ver. 1.1): Format e-mail messages.
3
4 # Gets rid of carets, tabs, and also folds excessively long lines.
5
6 # =================================================================
7 # Standard Check for Script Argument(s)
8 ARGS=1
9 E_BADARGS=85
10 E_NOFILE=86
11
12 if [ $# -ne $ARGS ] # Correct number of arguments passed to script?
13 then
14 echo "Usage: `basename $0` filename"
15 exit $E_BADARGS
16 fi
17
18 if [ -f "$1" ] # Check if file exists.
19 then
20 file_name=$1
21 else
22 echo "File \"$1\" does not exist."
23 exit $E_NOFILE
24 fi
25 # -----------------------------------------------------------------
26
27 MAXWIDTH=70 # Width to fold excessively long lines to.
28
29 # =================================
30 # A variable can hold a sed script.
31 # It's a useful technique.
32 sedscript='s/^>//
33 s/^ *>//
34 s/^ *//
35 s/ *//'
36 # =================================
37
38 # Delete carets and tabs at beginning of lines,
39 #+ then fold lines to $MAXWIDTH characters.
40 sed "$sedscript" $1 | fold -s --width=$MAXWIDTH
41 # -s option to "fold"
42 #+ breaks lines at whitespace, if possible.
43
44
45 # This script was inspired by an article in a well-known trade journal
46 #+ extolling a 164K MS Windows utility with similar functionality.
47 #
48 # An nice set of text processing utilities and an efficient
49 #+ scripting language provide an alternative to the bloated executables
50 #+ of a clunky operating system.
51
52 exit $?