]>
diplodocus.org Git - nmh/blob - etc/sendfiles
3 # Sends multiple files and/or directories in a MIME message.
4 # Requires tar and any specified compression program.
6 # This code is Copyright (c) 2012, by the authors of nmh. See the
7 # COPYRIGHT file in the root directory of the nmh distribution for
8 # complete copyright information.
10 usage
='Usage: sendfiles [switches] -to recipient -subject subject '"\
13 sendfiles [switches] recipient subject file1 [file2 ...]
15 -compress [bzip2 | compress | gzip | lzma | none]
19 Can use PERSON environment variable instead of -from switch.'
22 #### Find location of a program. Bourne shell just puts the name in
23 #### $0 if it's found from the PATH, so search that if necessary.
29 [ -f "${d:=.}/$1" -a -x "$d/$1" ] && printf %s
"$d" && break
35 printf '%s\n' "$usage"
36 #### Print the nmh intro text.
37 ${nmhbindir}/mhparam
-help | sed -n -e '/^$/,$p'
42 printf '%s\n' "$usage"
47 nmhbindir
=`cd "$bindir" && pwd`
48 nmhlibexecdir
=`$nmhbindir/mhparam libexecdir`
51 #### Process switches.
52 compress= ## compress method
53 compressarg
=0 ## whether currently handling -compress
54 from
= ## From: contents
55 fromarg
=0 ## whether currently handling -from
56 subject
= ## Subject: contents
57 subjectarg
=0 ## whether currently handling -subject
59 toarg
=0 ## whether currently handling -to
62 -c|-co|-com|-comp|-compr|-compre|-compres|-compress) compressarg
=1 ;;
63 -f|-fr|-fro|-from) fromarg
=1 ;;
64 #### Support -gzip for backward compatibility.
65 -gzip) compress=gzip ;;
66 -h|-he|-hel|-help) help ;;
67 #### Support -none for backward compatibility.
68 -none) compress=none
;;
69 -s|-su|-sub|-subj|-subje|-subjec|-subject) subjectarg
=1 ;;
71 -v|-ve|-ver|-vers|-versi|-versio|-version)
72 "$nmhlibexecdir/viamail" -version | sed 's/viamail/sendfiles/'; exit ;;
74 *) if [ $compressarg -eq 1 ]; then
77 elif [ $fromarg -eq 1 ]; then
80 elif [ $subjectarg -eq 1 ]; then
83 elif [ $toarg -eq 1 ]; then
87 #### Argument doesn't apply to a switch, so we're done with switches.
94 #### Check for switch after non-switch argument.
101 #### Check for required arguments (to, subject, file(s)).
102 if [ x
"$to" = x
]; then
103 if [ x
"$subject" = x
]; then
104 if [ $# -ge 3 ]; then
114 [ x
"$subject" = x
-o $# -lt 1 ] && die
117 #### Check for missing mandatory arguments.
119 if [ $compressarg -eq 1 ]; then
120 printf 'sendfiles: missing argument to -compress\n' >&2; exit 1
121 elif [ $fromarg -eq 1 ]; then
122 printf 'sendfiles: missing argument to -from\n' >&2; exit 1
123 elif [ $subjectarg -eq 1 ]; then
124 printf 'sendfiles: missing argument to -subject\n' >&2; exit 1
125 elif [ $toarg -eq 1 ]; then
126 printf 'sendfiles: missing argument to -to\n' >&2; exit 1
134 if [ x
"$from" = x
]; then
135 if [ x
"$PERSON" = x
]; then
136 from
=`"$nmhlibexecdir/ap" -format '%(localmbox)' 0`
143 #### Determine compression method and descriptive info.
144 if [ x
"$compress" = x
]; then
145 for compressor
in gzip bzip2 lzma
compress none
; do
146 if [ x
"`finddir $compressor`" = x
]; then :; else
147 compress="$compressor"
154 bzip2) uncompress=bzcat
; conversion
='; x-conversions=bzip2' ;;
155 compress) compress='compress -c'; uncompress='uncompress -c';
156 conversion
='; x-conversions=compress' ;;
157 gzip) compress='gzip -c'; uncompress='gzip -cd'
158 conversion
='; x-conversions=gzip' ;;
159 lzma
) compress='lzma -c'; uncompress='lzma -cd'
160 conversion
='; x-conversions=lzma' ;;
161 none
) compress=cat uncompress=cat; conversion
= ;;
162 *) printf 'sendfiles: unknown compression method "%s"\n' \
168 #### Send using viamail.
169 tar cvf
- "$@" | $compress | \
170 "$nmhlibexecdir/viamail" -to "$to" -subject "$subject" \
171 -from "$from" -parameters "type=tar$conversion" \
172 -comment "extract with $uncompress | tar xvpf -" \