Mail-DMARC-Iterator
view release on metacpan or search on metacpan
t/01-basic.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Mail::DMARC::Iterator;
use Mail::DKIM::Iterator;
use Data::Dumper;
#$Mail::DMARC::Iterator::DEBUG = 1;
plan tests => 27;
{
diag("single DKIM signature - order DKIM+EOF");
my $mail = sign(mail());
my $dmarc = Mail::DMARC::Iterator->new(
ip => '1.1.1.1',
mailfrom => 'me@example.com',
helo => 'mx.example.com'
);
# feed DKIM-Signature into iterator
my ($dksig,$rest) = $mail =~m{\A
(DKIM-Signature:.*(?:\n[ \t].*)*\n)
((?s).*)
}x or die "split mail";
my @t = $dmarc->next($dksig);
check_result(\@t,[
undef,
'D'
]);
# feed rest of mail into iterator
@t = $dmarc->next($rest);
check_result(\@t,[
undef,
'TXT:_dmarc.example.com'
]);
# feed DMARC DNS record into iterator
@t = $dmarc->next(dnslookup($t[1]));
check_result(\@t, [
undef,
'D',
'TXT:s1._domainkey.example.com',
'TXT:example.com'
]);
# feed DKIM DNS record into iterator
@t = $dmarc->next(dnslookup($t[2]));
check_result(\@t, [
undef,
'D',
'TXT:example.com'
]);
# feed EOF into iterator
@t = $dmarc->next('');
check_result(\@t, [
'pass',
'DKIM',
''
]);
}
{
diag("single DKIM signature - order SPF(Fail)+DKIM+EOF");
my $mail = sign(mail());
my $dmarc = Mail::DMARC::Iterator->new(
ip => '1.1.1.1',
mailfrom => 'me@example.com',
helo => 'mx.example.com'
);
# feed mail into iterator
my @t = $dmarc->next($mail);
check_result(\@t,[
undef,
'TXT:_dmarc.example.com'
]);
# feed DMARC DNS record into iterator
@t = $dmarc->next(dnslookup($t[1]));
check_result(\@t, [
undef,
'D',
'TXT:s1._domainkey.example.com',
( run in 0.510 second using v1.01-cache-2.11-cpan-71847e10f99 )