1#! /bin/sh 2# Mail a list of files, as they are. 3# Copyright (C) 1990, 1995 Free Software Foundation, Inc. 4# Fran�ois Pinard <pinard@iro.umontreal.ca>, 1991. 5 6package="sharutils" 7version="4.2.1" 8 9progname=`echo $0 | sed -e 's,.*/,,'` 10 11usage="\ 12Usage: $progname [OPTION] DESTIN TYPE SUBJECT FILE ... 13 14with OPTION in: 15 --help display this help and exit 16 --version output version information and exit 17 18 -x trace script" 19 20trytext="Try \`$progname --help' for more information." 21 22SLEEP=2 23 24### Decode the options. 25 26while test $# -gt 0; do 27 case $1 in 28 -x) trace=-x; set -x; shift ;; 29 --v* ) echo "$progname - $package $version"; exit 0 ;; 30 --h* ) echo "$usage"; exit 0 ;; 31 -) break ;; 32 -*) echo "$trytext"; exit 1 ;; 33 *) break 34 esac 35done 36 37if [ $# -lt 4 ]; then 38 echo "Too few arguments." 39 echo $trytext 40 exit 1 41fi 42 43destin="$1"; shift 44type="$1"; shift 45subject="$1"; shift 46 47maxcount=$# 48files="$*" 49 50### Mail all files, making a proper subject for each message. 51 52( if [ -f $destin ]; then 53 cat $destin 54 else 55 echo $destin 56 fi 57) | 58( total=0 59 while read destin; do 60 count=0 61 for file in $files; do 62 if [ ! -f $file ]; then 63 echo "$file not found" 64 continue 65 fi 66 count=`expr $count + 1` 67 if [ $maxcount = 1 ]; then 68 string="$type" 69 else 70 string="$type ($count/$maxcount)" 71 fi 72 echo "Mailing $string to $destin" 73 [ $total -ne 0 ] && sleep $SLEEP 74 /bin/mail -s "$string: $subject" $destin < $file 75 total=`expr $total + 1` 76 [ $count -lt $maxcount ] && sleep $SLEEP 77 done 78 done 79 if [ $total -eq 0 ]; then 80 echo 'No message queued' 81 elif [ $total -eq 1 ]; then 82 echo 'Message queued' 83 else 84 echo "$count messages queued" 85 fi 86) 87 88exit 0 89