Skip to content

Instantly share code, notes, and snippets.

@waffle2k
Created June 29, 2010 14:29
Show Gist options
  • Save waffle2k/457274 to your computer and use it in GitHub Desktop.
Save waffle2k/457274 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
#
# Parse some file or text, looking for what would appear to be a valid
# RFC-821 style email header. Attempt to pull out the DKIM-Signature
# portion of that file and print it.
#
# Author: pete (at) killallhumans (dot) ca
use strict;
my $text = do { local $/; <>; };
$text =~ s/\r//g;
my $dkim = undef;
if ( $text =~ /(DKIM-Signature:.*?)(?=^\s*$)/gsm ){
$dkim = $1;
}
elsif ( $text =~ /(DKIM-Signature:.*?)(?=^\S)/gsm ){
$dkim = $1;
}
else {
$dkim = $1 if ( $text =~ /(DKIM-Signature:.*)/gsm );
}
die( "Could not parse DKIM-Signature\n" )
unless $dkim;
print $dkim;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment