summaryrefslogtreecommitdiff
path: root/bayes
blob: e3814fc63d3396f5c125bfd569b01490ad9ac774 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env perl6 
use v6.d.PREVIEW;
use lib 'lib';
use MaildirIndexer::ScanDir;
use MaildirIndexer::Store;
use MaildirIndexer::Parser;
 
sub MAIN($maildir{
    my $store = MaildirIndexer::Store.new;
 
    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 {
                    $store.add-file($file);
                }
                elsif !$file.e {
                    $store.del-file($file);
                }
            }
        }
    }
 
    my $listener = IO::Socket::Async.listen(
        '127.0.0.1',
        9000,
        :enc<utf8-c8>,
    );
 
    react {
        whenever signal(SIGINT{ exit }
        whenever signal(SIGHUP{
            $store.dump();
        }
        whenever $listener -> $conn {
            LEAVE { $conn.close }
            with parse-email($conn-> $email {
                with $store.mailbox-for-email($email-> $mailbox {
                    await $conn.print("$mailbox\x0d\x0a");
                }
            }
        }
    }
}