summaryrefslogtreecommitdiff
path: root/lib/MaildirIndexer/Index/ByRef.pm6
blob: 5a9b53b265eaed2e1809995ba60d63acf55434cc (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
use v6.d;
use MaildirIndexer::Index;
unit class MaildirIndexer::Index::ByRef does MaildirIndexer::Index;
use MaildirIndexer::Email;
 
has Str %!id-for-file;
has Array[Str%!mailboxes-for-id;
 
method dump() {
    say "{.key} → {.value}" for %!id-for-file;
    say "{.key} ⇒ {.value.perl}" for %!mailboxes-for-id;
}
 
method add-mail(MaildirIndexer::Email:D $emailStr:D $mailbox --> Nil{
    my $id = $email.message-id or return;
    %!id-for-file{ $email.path } = $id;
    %!mailboxes-for-id{ $id }.push($mailbox);
    return;
}
 
method del-path(IO:D $fileStr:D $mailbox --> Nil{
    my $id = %!id-for-file{ $file.path }:delete;
    with %!mailboxes-for-id{ $id } {
        with .grep($mailbox):k -> $pos {
            .splice($pos,1);
        }
    }
    return;
}
 
method mailbox-for-email(MaildirIndexer::Email:D $email --> Str{
    for |$email.refs() -> $ref {
        with %!mailboxes-for-id{$ref} { return .[*-1}
    }
    return Nil;
}