summaryrefslogtreecommitdiff
path: root/lib/MaildirIndexer/Index/ByRef.pm6
diff options
context:
space:
mode:
Diffstat (limited to 'lib/MaildirIndexer/Index/ByRef.pm6')
-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;
+}