diff options
Diffstat (limited to 'lib/MaildirIndexer/Index')
-rw-r--r-- | lib/MaildirIndexer/Index/ByAddresses.rakumod | 6 | ||||
-rw-r--r-- | lib/MaildirIndexer/Index/ByRef.rakumod | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/lib/MaildirIndexer/Index/ByAddresses.rakumod b/lib/MaildirIndexer/Index/ByAddresses.rakumod index b83a239..ab0d5bb 100644 --- a/lib/MaildirIndexer/Index/ByAddresses.rakumod +++ b/lib/MaildirIndexer/Index/ByAddresses.rakumod @@ -31,6 +31,10 @@ submethod account-for(Str @addresses,Str $mailbox,Int $step) { method add-mail(MaildirIndexer::Email:D $email, Str:D $mailbox --> Nil) { MaildirIndexer::LogTimelineSchema::Index::Add.log: :class('ByAddresses'),:$mailbox, -> { + # ignore adding the same file twice, files in maildirs are + # immutable + return if %!addresses-for-file{ $email.path }:exists; + my Str @addresses = $email.addresses or return; %!addresses-for-file{ $email.path } = @addresses; @@ -42,7 +46,7 @@ method add-mail(MaildirIndexer::Email:D $email, Str:D $mailbox --> Nil) { method del-path(IO:D $file, Str:D $mailbox --> Nil) { MaildirIndexer::LogTimelineSchema::Index::Rm.log: :class('ByAddresses'),:$mailbox, -> { - my Str @addresses = %!addresses-for-file{$file.path} or return; + my Str @addresses = %!addresses-for-file{$file.path}:delete or return; self.account-for(@addresses,$mailbox,-1); diff --git a/lib/MaildirIndexer/Index/ByRef.rakumod b/lib/MaildirIndexer/Index/ByRef.rakumod index d044272..f9fc4f9 100644 --- a/lib/MaildirIndexer/Index/ByRef.rakumod +++ b/lib/MaildirIndexer/Index/ByRef.rakumod @@ -14,6 +14,10 @@ method dump() { method add-mail(MaildirIndexer::Email:D $email, Str:D $mailbox --> Nil) { MaildirIndexer::LogTimelineSchema::Index::Add.log: :class('ByRef'),:$mailbox, -> { + # ignore adding the same file twice, files in maildirs are + # immutable + return if %!id-for-file{ $email.path }:exists; + my $id = $email.message-id or return; %!id-for-file{ $email.path } = $id; %!mailboxes-for-id{ $id }.push($mailbox); @@ -23,12 +27,12 @@ method add-mail(MaildirIndexer::Email:D $email, Str:D $mailbox --> Nil) { method del-path(IO:D $file, Str:D $mailbox --> Nil) { MaildirIndexer::LogTimelineSchema::Index::Rm.log: :class('ByRef'),:$mailbox, -> { - my $id = %!id-for-file{ $file.path }:delete; + my $id = %!id-for-file{ $file.path }:delete or return; with %!mailboxes-for-id{ $id } { with .grep($mailbox):k -> $pos { .splice($pos,1); } - } + } return; } } |