Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Filehandle with DKIM::Verifier

by nifu (Novice)
on Oct 16, 2017 at 07:48 UTC ( [id://1201426]=note: print w/replies, xml ) Need Help??


in reply to Re: Filehandle with DKIM::Verifier
in thread Filehandle with DKIM::Verifier

Hello everyone and thanks for the answers.

This is the code form my small test script:

#! /usr/bin/perl use strict; use warnings; use Mail::DKIM::Verifier; my $raw_email; my $dkim = Mail::DKIM::Verifier->new(); open (MESSAGE, "< $ARGV[0]") || die "Couldn't open email $ARGV[0]\n"; undef $/; $raw_email = <>; close MESSAGE; print "$ARGV"; open(my $fh, "<", "$ARGV") or die "Can't open < $ARGV: $!"; $dkim->load($fh); my $result = $dkim->result; print "\n$result"; foreach my $signature ($dkim->signatures) { print "signature identity: " . $signature->identity . "\n"; print "verify result: " . $signature->result_detail . "\n"; }

I have tested this script with differed emails. Test files with correct, wrong and missing DKIM signature. The script returns always "none" (my $result = $dkim->result;) and $signature is an empty variable.

It seams that this script canīt find a DKIM signature in the test files.

Replies are listed 'Best First'.
Re^3: Filehandle with DKIM::Verifier
by hippo (Bishop) on Oct 16, 2017 at 08:11 UTC
    open (MESSAGE, "< $ARGV[0]") || die "Couldn't open email $ARGV[0]\n"; undef $/; $raw_email = <>; close MESSAGE;

    Hello, nifu. Could you please explain what this section of code is doing and why?

      I use this to open the file and parse it with the module Email::Simple;.

      This is the code from my "email parse script". I need to extend this script with a DKIM check.

      #! /usr/bin/perl use strict; use warnings; use Email::Simple; use DBI; use File::Copy; use Date::Parse; use DateTime; use Path::Tiny qw(path); [..] open (MESSAGE, "< $ARGV[0]") || die "Couldn't open email $ARGV[0]\n"; undef $/; $raw_email = <>; close MESSAGE; my $mail = Email::Simple->new($raw_email); my $from_header = $mail->header("From"); my $to_header = $mail->header("To"); my $date_header = $mail->header("Date"); my $aol_header = $mail->header("Authentication-Results"); [...]
      $ARGV is the filename form perl script.pl filename and $raw_email contains the text file.
        This is the code from my "email parse script"

        So that section is not relevant to your test script. If we omit it we can end up with a working version such as:

        use strict; use warnings; use Test::More; use Mail::DKIM::Verifier; my @good = qw/good1.txt good2.txt/; my @bad = qw/bad1.txt bad2.txt/; plan tests => @good + @bad; for my $goodfile (@good) { my $dkim = Mail::DKIM::Verifier->new(); open (my $gfh, '<', $goodfile) or die "Error opening $goodfile: $! +"; $dkim->load ($gfh); is ($dkim->result_detail, 'pass', $goodfile); close $gfh; } for my $badfile (@bad) { my $dkim = Mail::DKIM::Verifier->new(); open (my $bfh, '<', $badfile) or die "Error opening $badfile: $!"; $dkim->load ($bfh); isnt ($dkim->result, 'pass', $badfile); close $bfh; }

        Obviously you can change the filenames in the @good and @bad arrays until you have what you want. This script works fine for me testing on good and bad data.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1201426]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-24 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found