From 6171cb0d7fe0ac8f6352b8d3b9b87d56c56cf791 Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 26 Dec 2019 20:13:58 +0000 Subject: restructure store, extract server now Store has a set of Index, which actually do the indexing Store also runs the scan-dir (this may not be ideal, but will do for now) Server handles I/O --- lib/MaildirIndexer/Index/ByRef.pm6 | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 lib/MaildirIndexer/Index/ByRef.pm6 (limited to 'lib/MaildirIndexer/Index') diff --git a/lib/MaildirIndexer/Index/ByRef.pm6 b/lib/MaildirIndexer/Index/ByRef.pm6 new file mode 100644 index 0000000..497b5a1 --- /dev/null +++ b/lib/MaildirIndexer/Index/ByRef.pm6 @@ -0,0 +1,36 @@ +use v6.d; +use MaildirIndexer::Index; +unit class MaildirIndexer::Index::ByRef does MaildirIndexer::Index; +use MaildirIndexer::Email; + +has Str %!id-for-file; +has 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 $email, Str: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 $file, Str: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; +} -- cgit v1.2.3