From db72db7fd0c10131dfc3c4a49e3e2c77aae96b25 Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 9 Nov 2018 14:41:29 +0000 Subject: move stuff into modules --- bayes | 65 ++++++++++++++++------------------------------------------------- 1 file changed, 16 insertions(+), 49 deletions(-) (limited to 'bayes') diff --git a/bayes b/bayes index 37352ce..c7c81bf 100644 --- a/bayes +++ b/bayes @@ -1,55 +1,22 @@ #!/usr/bin/env perl6 use v6.d.PREVIEW; +use lib 'lib'; +use MaildirIndexer::ScanDir; +use MaildirIndexer::Parser; -grammar Message { - regex TOP { - - - +sub MAIN($maildir) { + my $file-supply = scan-dir($maildir); + my $file-channel = $file-supply.Channel; + for ^10 { + start react { + whenever $file-channel -> $file { + if $file.e && $file.f { + my $email = parse-email($file,:headers-only); + say "{$file} - {$email}"; + } + } + } } - token newline { [\x0d\x0a] | [\x0a\x0d] | \x0a | \x0d } - token separator { - [\x0a\x0d\x0a\x0d] | [\x0d\x0a\x0d\x0a] | \x0a ** 2 | \x0d ** 2 - } - token body { .* } - regex headers { -
+ % - } - regex header { - \: \h* - || - } - token name { - <-[:\s]>+ - } - regex value { - + % [ \h+] - } - token line { \N* } - token junk { \N+ } -} - -class Message-actions { - method TOP($/) { - make %( headers => $/.made, body => $/.Str ); - } - method headers($/) { - make %( |$/
ยป.made ); - } - method header($/) { - make $/ ?? () !! ( $/.Str => $/.made ); - } - method value($/) { - make $/.join(' ') - } -} - -sub MAIN(*@files) { - say "Starting";my $start = now; - my @messages = @files.race(:degree(10) :batch(100)).map({ - my $email = $_.IO.slurp(:enc); - my $match = Message.parse($email,:actions(Message-actions.new)); - }); - say "Took { now - $start } for { +@messages } messages"; + react whenever signal(SIGINT) { exit } } -- cgit v1.2.3