Removed unused local ncomps because gcc complained about it.
[mmh] / etc / sendfiles.in
1 #!/bin/sh
2 #
3 # Send multiples files and/or directories as a tar/compressed
4 # image, in a MIME message.
5 #
6
7 DELAY=0
8 FROM=
9
10 # compression method (none, gzip or compress)
11 METHOD=none
12 # compression filter
13 COMPRESS=cat
14 # uncompression filter
15 UNCOMPRESS=cat
16 # compression description to append to content-type
17 CONVERSION=
18
19 # default compression method based on installed software
20 # prefer compress over gzip for backward compatibility
21 if command -v compress >/dev/null 2>&1 ; then
22     METHOD=compress
23 elif command -v gzip >/dev/null 2>&1 ; then
24     METHOD=gzip
25 fi
26
27 # handle command-line options to override compression method and delay
28 while [ $# -gt 3 ]; do
29     case "$1" in
30         -gzip) METHOD=gzip
31                shift
32                ;;
33         -compress) METHOD=compress
34                    shift
35                    ;;
36         -none) METHOD=none
37                shift
38                ;;
39         -*) DELAY="`echo $1 | sed -e 's%-%%'`"
40             shift
41             ;;
42         *) break
43            ;;
44     esac
45 done
46
47 # set variables based on chosen compression method
48 if [ $METHOD = compress ]; then
49     COMPRESS=compress
50     UNCOMPRESS=uncompress
51     CONVERSION="; x-conversions=compress"
52 elif [ $METHOD = gzip ]; then
53     COMPRESS="gzip -c"
54     UNCOMPRESS="gzip -dc"
55     CONVERSION="; x-conversions=gzip"
56 fi
57
58 if [ ! -z "$PERSON" ]; then
59     FROM="-from $PERSON"
60 fi
61
62 if [ $# -lt 3 ]; then
63     echo 'usage: sendfiles: "mailpath" "subject-string" directory-or-file ...' 1>&2
64     exit 1;
65 fi
66
67 mailpath="$1"
68 echo "mailpath = $mailpath" 1>&2
69 shift
70
71 subject="$1"
72 echo "subject-string = $subject" 1>&2
73 shift
74
75 echo "files = $*" 1>&2
76
77 tar cvf - "$@" | $COMPRESS | \
78     %libdir%/viamail -to "$mailpath" -subject "$subject" \
79         -parameters "type=tar$CONVERSION" \
80         -comment "extract with $UNCOMPRESS | tar xvpf -" \
81         -delay "$DELAY" \
82         -verbose $FROM