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

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?

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