Skip to content

Instantly share code, notes, and snippets.

@vdubyna
Created August 21, 2014 23:26
Show Gist options
  • Select an option

  • Save vdubyna/512e396fb336340ed80a to your computer and use it in GitHub Desktop.

Select an option

Save vdubyna/512e396fb336340ed80a to your computer and use it in GitHub Desktop.
Verify eml DKIM
<?php
function get_middle($source, $beginning, $ending, $init_pos) {
$beginning_pos = strpos($source, $beginning, $init_pos);
$middle_pos = $beginning_pos + strlen($beginning);
$ending_pos = strpos($source, $ending, $beginning_pos + 1);
$middle = substr($source, $middle_pos, $ending_pos - $middle_pos);
return $middle;
}
$files = scandir('data/');
$byFrom = array();
foreach($files as $k => $file) {
if ($file == '.' || $file == '..') {
continue;
}
$fContent = file_get_contents('data/' . $file);
echo $k . ' => ' . $file. PHP_EOL . "FROM:";
$elements = imap_mime_header_decode(get_middle($fContent, 'From: ', '>', 0));
for ($i=0; $i<count($elements); $i++) {
$from = trim($elements[$i]->text);
if (!empty($from)){
echo " {$from} ";
}
}
exec('/usr/local/share/python/dkimverify.py < data/' . $file, $res);
$res = $res[0];
echo $res . PHP_EOL;
if (isset($byFrom[$from])) {
$byFrom[$from][] = array($from, $file, $res);
} else {
$byFrom[$from] = array(array($from, $file, $res));
}
}
print_r($byFrom);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment