Removed the split feature of send.
[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 FROM=
8
9 # compression method (none, gzip or compress)
10 METHOD=none
11 # compression filter
12 COMPRESS=cat
13 # uncompression filter
14 UNCOMPRESS=cat
15 # compression description to append to content-type
16 CONVERSION=
17
18 # default compression method based on installed software
19 # prefer compress over gzip for backward compatibility
20 if command -v compress >/dev/null 2>&1 ; then
21     METHOD=compress
22 elif command -v gzip >/dev/null 2>&1 ; then
23     METHOD=gzip
24 fi
25
26 # handle command-line options to override compression method
27 while [ $# -gt 3 ]; do
28     case "$1" in
29         -gzip)
30             METHOD=gzip
31             shift
32             ;;
33         -compress)
34             METHOD=compress
35             shift
36             ;;
37         -none)
38             METHOD=none
39             shift
40             ;;
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         -verbose $FROM