From 060a3b2bc58aadf52c35649afa5ef2cc37f95b22 Mon Sep 17 00:00:00 2001 From: Ben castricum Date: Wed, 29 Jan 2025 12:49:37 +0100 Subject: [PATCH 1/3] Turn perl warnings back on --- opendmarc-halonlog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opendmarc-halonlog b/opendmarc-halonlog index adffc21..1d1597a 100755 --- a/opendmarc-halonlog +++ b/opendmarc-halonlog @@ -1,6 +1,6 @@ #!/usr/bin/perl -#use warnings; +use warnings; use strict; my $reporter = $0; From 4dc5439035d6a185cafd05b036d150f9c4701c96 Mon Sep 17 00:00:00 2001 From: Ben castricum Date: Wed, 29 Jan 2025 12:53:45 +0100 Subject: [PATCH 2/3] handle missing sp values Fixes warnings like Use of uninitialized value $result{"sp"} in string eq at ./opendmarc-halonlog line 40 --- opendmarc-halonlog | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/opendmarc-halonlog b/opendmarc-halonlog index 1d1597a..0ff5f7f 100755 --- a/opendmarc-halonlog +++ b/opendmarc-halonlog @@ -37,10 +37,13 @@ while () print '0' if ! defined($result{'p'}); print "\n"; print "sp "; - print ord('n') if $result{'sp'} eq 'none'; - print ord('r') if $result{'sp'} eq 'reject'; - print ord('q') if $result{'sp'} eq 'quarantine'; - print '0' if ! defined($result{'sp'}); + if (defined($result{'sp'})) { + print ord('n') if $result{'sp'} eq 'none'; + print ord('r') if $result{'sp'} eq 'reject'; + print ord('q') if $result{'sp'} eq 'quarantine'; + } else { + print '0'; + } print "\n"; print "spf "; print '0' if $result{'spf'} eq 'pass'; From ada46bf598359bdc639d22f61fff54d6c50b6d64 Mon Sep 17 00:00:00 2001 From: Ben castricum Date: Wed, 29 Jan 2025 13:33:00 +0100 Subject: [PATCH 3/3] Handle invalid spf results The spf result can be "invalid" which results in an empty spf value. OpenDMARC chokes on that with: opendmarc-import: failed to insert message: Incorrect integer value: '' for column 'spf' at row 1 By converting the possible values into a hash and use -1 if the spf result is not in the hash we make OpenDMARC happy. --- opendmarc-halonlog | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/opendmarc-halonlog b/opendmarc-halonlog index 0ff5f7f..08e206a 100755 --- a/opendmarc-halonlog +++ b/opendmarc-halonlog @@ -4,6 +4,13 @@ use warnings; use strict; my $reporter = $0; +my %spf_map = ( + 'pass' => 0, + 'softfail' => 2, + 'neutral' => 3, + 'none' => 6, + 'fail' => 7, +); while () { @@ -45,14 +52,7 @@ while () print '0'; } print "\n"; - print "spf "; - print '0' if $result{'spf'} eq 'pass'; - print '2' if $result{'spf'} eq 'softfail'; - print '3' if $result{'spf'} eq 'neutral'; - print '6' if $result{'spf'} eq 'none'; - print '7' if $result{'spf'} eq 'fail'; - print '-1' if $result{'spf'} eq 'unknown'; - print "\n"; + printf("spf %d\n", exists($spf_map{$result{'spf'}}) ? $spf_map{$result{'spf'}} : -1); foreach my $key (keys %result) { next if $key !~ m/^dkim:(.+)\._domainkey\.(.+)$/s;