Thanks. I figured I was piping it incorrectly. When you explained it I can see where I made my mistake. It is still either being interpreted incorrectly or I am really off somewhere as I cannnot get Mail::DKIM::Verifier to provide results as defined in the example. Here is my full code:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Email::Simple;
use Email::Simple::Creator;
use Email::Send;
use IO::Scalar;
use Mail::DKIM::Verifier;
use constant SENDER => 'test@circularbucket.com';
use constant SUBJECT => 'Email Message Report';
## Main
# slurp the email from STDIN
my( $raw );
{ local $/ = undef; local *FILE; open FILE, "-"; $raw = <FILE>; close
+FILE }
defined( $raw )
or die( "Nothing read from STDIN!" );
# Create an IO::Handle for Mail::DKIM::Verifier to read message from
my( $raw_iohandle ) = new IO::Scalar( \$raw );
# Read from the IO::Handle
my( $mail ) = Mail::DKIM::Verifier->new();
$mail->load( $raw_iohandle );
$mail->CLOSE;
# Import message to Email::Simple
my( $incoming ) = Email::Simple->new( \$raw );
######################################################################
+##################################
# Message checks
######################################################################
+##################################
###############
# Are we spam?
my( $XSpamStatus ) = 0;
if ( $incoming->header( 'X-Spam-Status' ) =~ /^Yes.*score=([\S*])\s+/
+) {
# we're spam, save the score
$XSpamStatus = $1;
}
###############
# Check DKIM status
my( $result ) = $mail->result;
###############
# Gather who the message was from so we can send it back
my( $from_header ) = $incoming->header("From");
##############################
# Gather spam stats from the message
my $spam_stats1 = $incoming->header( 'X-Spam-Status' );
##############################
# Get SPF result from headers
my( $SPFStatus ) = 0;
if ( $incoming->header( 'Received-SPF' ) =~ /^pass.*/ ) {
# we have a valid SPF record, so save the status
$SPFStatus = 1;
}
##############################
# What MUA was used to send the message?
my $user_agent = $incoming->header( 'User-Agent' );
######################################################################
+####################################
# Generate the message to be sent back
######################################################################
+####################################
my( $body ) = <<BODY;
This is a test message. The test results will follow below.
-----------------------------------------------------------
BODY
if ( $XSpamStatus ) {
$body .= "Message was scored as spam, with a score of $XSpamStatus
+\n";
}
else {
$body .= "Message was not scored as spam.\n";
}
if ( $result ) {
$body .= "Result1 was: $result\n";
}
else {
$body .= "Result2 was: $result\n";
}
$body .= "Return path was: $from_header\n";
$body .= "Original test request was sent using: $user_agent\n";
if ( $SPFStatus ) {
$body .= "\n\nSPF Record: PASS\n";
}
else {
$body .= "\n\nSPF Record: FAIL\n";
}
foreach my $signature ($mail->signatures)
{
$body .= "signature identity: $signature->identity . \n";
$body .= "verify result: $signature->result_detail . \n";
}
my( $outgoing ) = Email::Simple->create(
header => [
From => SENDER,
To => $from_header,
Subject => SUBJECT,
],
body => $body,
);
$outgoing->header_set( 'X-Processor' => 'email test script' );
######################################################################
+####################################
# Send the message back to the original sender
######################################################################
+####################################
my( $sender ) = Email::Send->new;
$sender->send( $outgoing );
Any nudges in the right direction are appreciated!