#!/usr/bin/perl # #NAME # Send - send email to recipients # #SYNOPSIS # Send [-options] [file]... [list mlist...] [to recipient...] # #DESCRIPTION # 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 # $HOME/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. # #AUTHOR # Copyright (c) 1993, 1995 by John Chambers # # You are free to use this program as you wish, as long as you give # me credit, and take credit for your changes. If you make any # significant changes, you might send me a copy, and I'll incorporate # them into this public version. $dbg = $ENV{'D_Send'} || 0; $filefl = 1; # Treat names as files initially. $rcptfl = 0; # Don't treat names as recipients. $listfl = 0; # Don't treat names as mailing lists. $mailer = 'sendmail'; 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') { ++$rcptfl; # Treat names as recipients. $listfl = 0; # Don't accept mailing lists. $filefl = 0; # Don't accept file names. next; } if ($a eq 'list') { ++$listfl; # Treat names as mailing lists. $rcptfl = 0; # Don't accept recipient names. $filefl = 0; # Don't accept file names. next; } if ($a eq 'file') { ++$filefl; # Treat names as files. $listfl = 0; # Don't accept mailing lists. $rcptfl = 0; # Don't accept recipient names. next; } if ($listfl) { # Have we seen a "list" keyword? $lists[$#lists+1] = $a; next; } elsif ($rcptfl) { # Have we seen a "to" keyword? $rcpts[$#rcpts+1] = $a; next; } else { $files[$#files+1] = $a; next; } } if (!@opts) { $opts[$#opts+1] = '-v'; # Verbose by default. } if (!@rcpts) { $opts[$#opts+1] = '-t'; # Look for To: lines in files. } if (@lists) { for $l (@lists) { if ( -f "/usr/mail/list/$l" ) { print STDERR "No list \"$l\"\n"; next; } if (open(L,") { $r =~ s/\s+$//; # Trim away white space. next if !$r; # Ignore blank lines. next if ($r =~ /^\s*#/); # Ignore comments. print "Rcpt: \"$r\"\n" if $dbg; for $f (@files) { printf("Mail $f to $r.\n"); system "(echo To: '$r';echo X-List: $l;cat $f)|$mailer -t"; } } } } elsif (@files) { for $f (@files) { print "Reading mail from $f ...\n" if $dbg; system "$mailer @opts @rcpts <$f"; } } else { print "Reading mail from stdin ...\n" if $dbg; system "$mailer @opts @rcpts"; # No files; use stdin. }