#!/bin/perl # snd [-options] [file]... [list mlist...] [to recipient...] # # This program sends its stdin or a list of files. If the keyword "to" # is present, then a list of recipients will be used; otherwise, the # file(s) will be examined for "To:" lines. Also, if the "list" # keyword is present, the fields after it are looked up in # /usr/mail/list, and if found, they are taken as mailing lists. Each # line is taken as a recipient, and each file is mailed to each # recipient. # # Copyright (c) 1993 by John Chambers # ...!{{harvard,eddie.mit}.edu,ora.com,bcs.org}!minya.uucp!jc # You are free to use this program as you wish, as long as you give me # credit (and take credit for your changes). # $mailcmd = 'sendmail -vt'; $tofl = 0; for $a (@ARGV) { if ($a =~ s/^[-+]//) { if ($a =~ /[DdVv]/) { $opts[$#opts+1] = '-v'; next; } if ($a =~ /[Tt]/) { $opts[$#opts+1] = '-t'; next; } next; } if ($a eq 'to') { ++$tofl; next; } if ($a eq 'list') { ++$listfl; next; } if ($listfl) { # Have we seen a "list" keyword? $lists[$#lists+1] = $a; next; } elsif ($tofl) { # Have we seen a "to" keyword? $rcpts[$#rcpts+1] = $a; next; } else { $files[$#files+1] = $a; next; } } if (!@opts) { $opts[$#opts+1] = '-v'; } if (!@rcpts) { $opts[$#opts+1] = '-t'; } if (@lists) { for $l (@lists) { if ( -f "/usr/mail/list/$l" ) { if (open(L,") { chop $r; print "Rcpt: \"$r\"\n"; for $f (@files) { printf("Mail $f to $r.\n"); system "(echo To: '$r';echo X-List: $l;cat $f)|$mailcmd"; } } } else { print "Can't read \"/usr/mail/list/$l\"\n"; } } else { print "No list \"$l\"\n"; } } } elsif (@files) { for $f (@files) { system "$mailcmd @opts @rcpts <$f"; } } else { system "$mailcmd @opts @rcpts"; }