diff options
author | dakkar <dakkar@thenautilus.net> | 2018-11-09 16:18:11 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2018-11-09 16:18:11 +0000 |
commit | 7b5c1abf0bac5147efa468f50a384310b4376a7e (patch) | |
tree | b7a2223f9a389250cec88488125813a6a58717ec | |
parent | fix indent (diff) | |
download | MaildirIndexer-7b5c1abf0bac5147efa468f50a384310b4376a7e.tar.gz MaildirIndexer-7b5c1abf0bac5147efa468f50a384310b4376a7e.tar.bz2 MaildirIndexer-7b5c1abf0bac5147efa468f50a384310b4376a7e.zip |
feature parity!
-rw-r--r-- | bayes | 15 | ||||
-rw-r--r-- | lib/MaildirIndexer/Parser.pm6 | 13 | ||||
-rw-r--r-- | lib/MaildirIndexer/Store.pm6 | 6 |
3 files changed, 34 insertions, 0 deletions
@@ -3,6 +3,7 @@ use v6.d.PREVIEW; use lib 'lib'; use MaildirIndexer::ScanDir; use MaildirIndexer::Store; +use MaildirIndexer::Parser; sub MAIN($maildir) { my $store = MaildirIndexer::Store.new; @@ -23,10 +24,24 @@ sub MAIN($maildir) { } } + my $listener = IO::Socket::Async.listen( + '127.0.0.1', + 9000, + :enc<utf8-c8>, + ); + react { whenever signal(SIGINT) { exit } whenever signal(SIGHUP) { $store.dump(); } + whenever $listener -> $conn { + LEAVE { $conn.close } + with parse-email($conn) -> $email { + with $store.mailbox-for-email($email) -> $mailbox { + await $conn.print("$mailbox\x0d\x0a"); + } + } + } } } 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<utf8-c8>)); } + 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<utf8-c8>) { + $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; |