From 7b5c1abf0bac5147efa468f50a384310b4376a7e Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 9 Nov 2018 16:18:11 +0000 Subject: feature parity! --- lib/MaildirIndexer/Parser.pm6 | 13 +++++++++++++ lib/MaildirIndexer/Store.pm6 | 6 ++++++ 2 files changed, 19 insertions(+) (limited to 'lib') diff --git a/lib/MaildirIndexer/Parser.pm6 b/lib/MaildirIndexer/Parser.pm6 index c2425fe..7b80ecf 100644 --- a/lib/MaildirIndexer/Parser.pm6 +++ b/lib/MaildirIndexer/Parser.pm6 @@ -58,6 +58,7 @@ class Message-actions { multi parse-email(IO::Path $p) is export { return parse-email($p.slurp(:enc)); } + multi parse-email(IO::Path $p, :$headers-only!) is export { return parse-email( $p.lines( @@ -67,6 +68,18 @@ multi parse-email(IO::Path $p, :$headers-only!) is export { )[0], ); } + +multi parse-email(IO::Socket::Async $s) is export { + my $string; + react { + whenever $s.Supply(:enc) { + $string ~= $_; + done if $string ~~ /@separators/; + } + } + return parse-email($string); +} + multi parse-email(Str $email-str) is export { with Message.parse($email-str,:actions(Message-actions.new)) { return .made; diff --git a/lib/MaildirIndexer/Store.pm6 b/lib/MaildirIndexer/Store.pm6 index 5bacbe9..7447643 100644 --- a/lib/MaildirIndexer/Store.pm6 +++ b/lib/MaildirIndexer/Store.pm6 @@ -37,6 +37,12 @@ method del-file(IO $file) { return; } +method mailbox-for-email(MaildirIndexer::Email $email) { + my $id = $email.message-id or return Nil; + with %!mailboxes-for-id{$id} { return .[*-1] } + return Nil; +} + sub mailbox-from-path(Str() $path) { $path ~~ m{'/' (<-[/]>+?) '/' [cur|new|tmp] '/'} and return ~$/[0]; return Nil; -- cgit v1.2.3