summaryrefslogtreecommitdiff
path: root/lib/MaildirIndexer/Index
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2019-12-26 20:13:58 +0000
committerdakkar <dakkar@thenautilus.net>2019-12-26 20:13:58 +0000
commit6171cb0d7fe0ac8f6352b8d3b9b87d56c56cf791 (patch)
tree98b6f42a0ab9939f78134b27f780261211845968 /lib/MaildirIndexer/Index
parenttest email (diff)
downloadMaildirIndexer-6171cb0d7fe0ac8f6352b8d3b9b87d56c56cf791.tar.gz
MaildirIndexer-6171cb0d7fe0ac8f6352b8d3b9b87d56c56cf791.tar.bz2
MaildirIndexer-6171cb0d7fe0ac8f6352b8d3b9b87d56c56cf791.zip
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
Diffstat (limited to 'lib/MaildirIndexer/Index')
-rw-r--r--lib/MaildirIndexer/Index/ByRef.pm636
1 files changed, 36 insertions, 0 deletions
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;
+}