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