in reply to Filehandle with DKIM::Verifier

Hello nifu and welcome to the monastery

> $dkim->load(*STDIN); I have tried to load the file with a filehandle like $dkim->load(<fh>); or $dkim->load($filename); .

I think you are confusing filehandle with filename.

You need to open a filehandle to a file (and close it afterwards)

Something like

open(my $fh, "<", "$filename") or die "Can't open < $filename: $!" $dkim->load($fh); ...

should do. (Untested)

HTH :)

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^2: Filehandle with DKIM::Verifier
by nifu (Novice) on Oct 16, 2017 at 07:48 UTC
    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.

      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.