[Raw Msg Headers][Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ZMailer message submission in PERL..



I asked for a PERL-version of the posting, and this I got back.
In commentary letter Janne Edelman said (in finnish) about:

"This reads in from stdin, and sends to all addresses given as
 parameters.  Even though this sends all messages individually,
 it would be trivial to use more envelope 'to '-lines.  Should
 add sometimes.

 The input text must have RFC822 headers in it.

 ... and of course I could have answered directly to the person
 originating the question, but I am a bit tired at this late at
 night..."

I THINK this needs Perl5, though I am not sure.

/Matti Aarnio


#!/usr/bin/perl
#
#  LightPost for ZMailer
#  Version 0.1
#  Copyright (c) 1996 Janne Edelman
#  You may copy and use this piece of software under GPL
#
#####
#
#  Usage: lightpost [-t] email@address [ email@address ... ] < file
#
#  File must contain full headers with From, To, Subject, etc.
#  This script does NOT check the file at any way.
#
#  This script only adds the envelope at the begining of outgoing email
#  and allows mass postings with the same content.
#
#  With -t option the To header is changed to same as given email address
#
#####

if( ! -r '/etc/zmailer.conf') {
  die "Can't open zmailer.conf\n";
}

open(ZMAILER,'</etc/zmailer.conf');
while(<ZMAILER>) {
  chomp;
  split(/=/);
  $ZMAILER{$_[0]}=$_[1];
}
close ZMAILER;

require 'getopts.pl';
Getopts('t');

$part='header';

while(<STDIN>) {
  if($_ eq "\n") { $part='body' }
  push(@$part,$_);
}

foreach $hl ('Message-Id:','X-Mailer:','Cc:','Bcc:') {
  @header=strip_header($hl,@header);
}

if($opt_t) {
  @header=strip_header('To:',@header);
}

$outfile = $ZMAILER{'POSTOFFICE'} . "/public/lightpost.$$";
$time=time;
$hostname=`hostname`; chomp $hostname;
$domainname=`domainname`; chomp $domainname;
foreach $address (@ARGV) {
  $count++;
  open(OUT,">$outfile");
  select(OUT);
  print "to $address\n";
  print "env-end\n"; # added by [mea]
  if($opt_t) {
    print "To: $address\n";
  }
  print @header;
  print "Message-Id: <${time}.${count}.LP\@${hostname}.${domainname}>\n";
  print "X-Mailer: LightPost for Zmailer\n";
  print @body;
  select(STDOUT);
  close OUT;
  $inode=(stat($outfile))[1];
  $newfile=$ZMAILER{'POSTOFFICE'} . "/router/$inode";
  rename($outfile, $newfile);
}
print "$count messages send\n";
exit(0);

sub strip_header {
  return grep(!/^$_[0]/i, @_[1..$#_]);
}


	Janne K Edelman - PGP public key: finger edelman/pgp@tuug.utu.fi