-
Notifications
You must be signed in to change notification settings - Fork 0
/
dkimcheck2.pl
executable file
·54 lines (44 loc) · 1.12 KB
/
dkimcheck2.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl -wT
#
use strict;
use warnings;
use Mail::DKIM::Verifier;
# create a verifier object
my $dkim = Mail::DKIM::Verifier->new();
# read an email from a file handle
#use FileHandle;
#my $fh = FileHandle->new("test.eml", "r");
#if (defined $fh) {
# $dkim->load($fh);
# $fh->close;
#}
#else {
# print "No email-file found!\n";
# exit (1);
#}
# or read an email and pass it into the verifier, incrementally
while (<STDIN>)
{
# remove local line terminators
chomp;
s/\015$//;
# use SMTP line terminators
$dkim->PRINT("$_\015\012");
}
$dkim->CLOSE;
# what is the result of the verify?
my $result = $dkim->result;
my $detail = $dkim->result_detail;
print "Result: " . $result . "\n";
print "Detail: " . $detail . "\n";
# there might be multiple signatures, what is the result per signature?
foreach my $signature ($dkim->signatures)
{
print "signature identity: " . $signature->identity . "\n";
print "verify result: " . $signature->result_detail . "\n";
}
# the alleged author of the email may specify how to handle email
foreach my $policy ($dkim->policies)
{
die "fraudulent message" if ($policy->apply($dkim) eq "reject");
}