use Mail::Address;
use Getopt::Long;
use MOJO::Config; # configuration variables
use MOJO::Mail::Send; # use the MOJO::Mail::Send module
+to send e-mails with
use MOJO::App::Guts; # use MOJO::Guts for misc subroutin
+es
use MOJO::MailingList::Subscribers;
use strict;
# get header, footer
my $header;
my $body;
{
local $/ = "";
$header = <STDIN>;
undef $/;
$body = <STDIN>;
}
my $test = 0;
GetOptions("test" => \$test);
#create a MOJO::Mail::Send object
my $mh = MOJO::Mail::Send->new();
#get headers in name=>value pair
my %mail_headers = $mh->return_headers($header);
# 'normalize' the headers
%mail_headers = $mh->clean_headers(%mail_headers);
# extract 'To:' addresses
my @To_addresses = Mail::Address->parse($mail_headers{To});
# extract anything in the CC: header
my @Cc_addresses = Mail::Address->parse($mail_headers{Cc});
# plop them together
@To_addresses = (@To_addresses, @Cc_addresses);
# extract the 'From:' address
my $From_address = (Mail::Address->parse($mail_headers{From}))[0];
my $from_to_check = 0;
foreach my $this_address(@To_addresses){
my $from_test = $From_address->address;
if($this_address->address =~ /$from_test/i){
$from_to_check = 1;
last;
}
}
if($from_to_check == 1){
warn("$PROGRAM_NAME $VER ERROR, quitting script to stop possible i
+nfinite loop!");
exit;
}
# at this point is where I need the vars to post. Make sense? Obviousl
+y, we would not need to use all of the above modules/libraries
# the mojo script goes on and on to process emails as it would, but we
+ wish to avoid that so here we would execute the lines mentioned by R
+oger.
# build variables to pass to PHP via post
my %vars = (
var1 => $var1, # the email vars would be here I believe?
var2 => $var2,
# ...
);
# then we would do the post thing
# send the POST to php
my $url = "http://domain.com/test.php";
my $req = new HTTP::Request;
my $res = $us->post($url, \%vars);
The current set up is that the command line email alias forwards the message test@domain.com to this script. This script is then usually used to operate a perl mailing list discussion pacakge called mojo mail. I wish to simply use it to parse the email and move the vars on to php.
Thanks, Nathan