Skip to content

Instantly share code, notes, and snippets.

@dracony
Created November 25, 2015 11:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dracony/44f6998b7d8e4fc8aa8a to your computer and use it in GitHub Desktop.
Save dracony/44f6998b7d8e4fc8aa8a to your computer and use it in GitHub Desktop.
$count = array();
$path = __DIR__.'/php-fig/mbox/';
foreach(scandir($path) as $file) {
if(in_array($file, array('.', '..'))) {
continue;
}
$file = file_get_contents($path.$file);
preg_match('#From: "?([^\n\r]*?)"? <#', $file, $m);
if(empty($m)) continue;
$from = $m[1];
$from = imap_mime_header_decode($from);
$from = $from[0]->text;
if($from == "Roman Tsjupa") {
$from = "Dracony";
}
preg_match('#Date: (.*?) [\-\+]#', $file, $m);
$date = date_parse($m[1]);
if($date['year'] != '2015') {
continue;
}
if($date['month'] < 10) {
//continue;
}
if(!array_key_exists($from, $count)) {
$count[$from] = 0;
}
$count[$from]++;
}
$filtered = array();
foreach($count as $key => $val) {
if($val > 3) {
$filtered[$key] = $val;
}
}
arsort($filtered);
echo json_encode($filtered, JSON_UNESCAPED_UNICODE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment