a3545d19ba8df6e690fd4a295361d635c643dca1
[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)
31             METHOD=gzip
32             shift
33             ;;
34         -compress)
35             METHOD=compress
36             shift
37             ;;
38         -none)
39             METHOD=none
40             shift
41             ;;
42         -*)
43             DELAY="`echo $1 | sed -e 's%-%%'`"
44             shift
45             ;;
46         *)
47             break
48             ;;
49     esac
50 done
51
52 # set variables based on chosen compression method
53 if [ $METHOD = compress ]; then
54     COMPRESS=compress
55     UNCOMPRESS=uncompress
56     CONVERSION="; x-conversions=compress"
57 elif [ $METHOD = gzip ]; then
58     COMPRESS="gzip -c"
59     UNCOMPRESS="gzip -dc"
60     CONVERSION="; x-conversions=gzip"
61 fi
62
63 if [ ! -z "$PERSON" ]; then
64     FROM="-from $PERSON"
65 fi
66
67 if [ $# -lt 3 ]; then
68     echo 'usage: sendfiles: "mailpath" "subject-string" directory-or-file ...' 1>&2
69     exit 1;
70 fi
71
72 mailpath="$1"
73 echo "mailpath = $mailpath" 1>&2
74 shift
75
76 subject="$1"
77 echo "subject-string = $subject" 1>&2
78 shift
79
80 echo "files = $*" 1>&2
81
82 tar cvf - "$@" | $COMPRESS | \
83     %libdir%/viamail -to "$mailpath" -subject "$subject" \
84         -parameters "type=tar$CONVERSION" \
85         -comment "extract with $UNCOMPRESS | tar xvpf -" \
86         -delay "$DELAY" \
87         -verbose $FROM