File: mail-files.in

package info (click to toggle)
sharutils 1:4.2-6
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 1,436 kB
  • ctags: 587
  • sloc: ansic: 6,313; perl: 1,742; makefile: 563; sh: 495; pascal: 293; sed: 93
file content (88 lines) | stat: -rwxr-xr-x 1,760 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
# Mail a list of files, as they are.
# Copyright (C) 1990, 1995 Free Software Foundation, Inc.
# Fran´┐Żois Pinard <pinard@iro.umontreal.ca>, 1991.

package="@PACKAGE@"
version="@VERSION@"

progname=`echo $0 | sed -e 's,.*/,,'`

usage="\
Usage: $progname [OPTION] DESTIN TYPE SUBJECT FILE ...

with OPTION in:
      --help      display this help and exit
      --version   output version information and exit

  -x              trace script"

trytext="Try \`$progname --help' for more information."

SLEEP=2

### Decode the options.

while test $# -gt 0; do
  case $1 in
    -x) trace=-x; set -x; shift ;;
    --v* ) echo "$progname - $package $version"; exit 0 ;;
    --h* ) echo "$usage"; exit 0 ;;
    -) break ;;
    -*) echo "$trytext"; exit 1 ;;
    *) break
  esac
done

if [ $# -lt 4 ]; then
  echo "Too few arguments."
  echo $trytext
  exit 1
fi

destin="$1"; shift
type="$1"; shift
subject="$1"; shift

maxcount=$#
files="$*"

### Mail all files, making a proper subject for each message.

( if [ -f $destin ]; then
    cat $destin
  else
     echo $destin
  fi
) |
( total=0
  while read destin; do
    count=0
    for file in $files; do
      if [ ! -f $file ]; then
	echo "$file not found"
	continue
      fi
      count=`expr $count + 1`
      if [ $maxcount = 1 ]; then
	string="$type"
      else
	string="$type ($count/$maxcount)"
      fi
      echo "Mailing $string to $destin"
      [ $total -ne 0 ] && sleep $SLEEP
      @MAILER@ -s "$string: $subject" $destin < $file
      total=`expr $total + 1`
      [ $count -lt $maxcount ] && sleep $SLEEP
    done
  done
  if [ $total -eq 0 ]; then
    echo 'No message queued'
  elif [ $total -eq 1 ]; then
    echo 'Message queued'
  else
    echo "$count messages queued"
  fi
)

exit 0