#!/usr/pkg/bin/wsbasic

if $# != 4
begin
  print "USAGE: " + $1 + " <mail list file> <mail content file>"
  break
end

mail_list    = $2
mail_subject = run( "head -n 1 " + $3 )
lines        = run( "wc -l " + $3 )*1-1
mail_content = run( "tail -n " + lines + " " + $3 )

print "mail_list="+mail_list
print "mail_subject="+mail_subject
print "mail_content="+mail_content


#####################################
# loop that calls 'mail' program  

foreach email in run( "cat " + mail_list )
begin
  print "mailing '", email ,"'...";
  
  #uncomment below to actually mail it!
  #
  #ok=run( "echo \"" + mail_content + "\" | mail -s \"" + mail_subject+"\" " + email )
  #if( ok == "" ) print "done."
  #else print "failed!"

  print ""
end

