Hi
OK, complete newbie to perl. I am busy playing around/learning and I
wanted to create a simple perl script that I can pipe an email too and
then grab the To header and output that and then pipe the unmodified
email to sendmail with a different recipient...
similar to
cat /var/mail/mailfile | sendmail t...@test.com
This is what I have so far, I can print the To address fine but for some
reason I am just receiving a blank email as if STDIN isnt outputting
anything? There are a couple of hashed out variations I have tried
already....
#!/usr/bin/perl
use strict;
use warnings;
use MIME::Parser;
my $parser = new MIME::Parser;
my $to; #contains the message to header
my $sendmail = "/usr/sbin/sendmail";
$parser->ignore_errors(1);
$parser->output_to_core(1);
my $entity = $parser->parse(\*STDIN);
my $error = ($@ || $parser->last_error);
#get email headers
my $header = $entity->head;
$to = $header->get('To');
chomp($to);
print "To $to\n";
my $vacation_forward = "myem...@mydomain.com";
print "vacation_forward $vacation_forward\n";
#while (<STDIN>) {
# chomp;
# system( "$_ | $sendmail $vacation_forward" );
#}
#my $msgbody = <STDIN>;
#`echo "$msgbody" | $sendmail $vacation_forward`;
#open MAIL, "|/usr/sbin/sendmail $sendmail $vacation_forward";
#print MAIL "$msgbody";
#close(MAIL);
#open OUT, "|$sendmail $sendmail $vacation_forward";
#open(OUT, "|/usr/sbin/sendmail $vacation_forward") or die ("Can't
sendmail - $!");
#open OUT, "|-", $sendmail, $vacation_forward;
#print OUT while <STDIN>;
#close OUT;
#open(OUT, "|/usr/sbin/sendmail $vacation_forward") or die ("Can't
sendmail - $!");
#while(\*STDIN) {
# print OUT;
# }
#close (OUT);
#while (<STDIN>) { print "taco\n";};
#while (\*STDIN) { print "taco\n";};
my ($header, $body);
{ local $/ = "";
$header = <STDIN>;
undef $/;
$body = <STDIN>;
}
open(MAIL,"|$sendmail $vacation_forward");
print MAIL "header: $header\n";
print MAIL "body: $body\n\n";
close (MAIL);
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/