diff options
Diffstat (limited to 'lib/MaildirIndexer/Parser.pm6')
-rw-r--r-- | lib/MaildirIndexer/Parser.pm6 | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/MaildirIndexer/Parser.pm6 b/lib/MaildirIndexer/Parser.pm6 index edcbe6d..e6be32f 100644 --- a/lib/MaildirIndexer/Parser.pm6 +++ b/lib/MaildirIndexer/Parser.pm6 @@ -38,10 +38,12 @@ grammar Message { } class Message-actions { + has $.path = IO; method TOP($/) { make MaildirIndexer::Email.new( headers => $/<headers>.made, body => $/<body>.Str, + path => $.path, ); } method headers($/) { @@ -55,21 +57,22 @@ class Message-actions { } } -multi parse-email(IO::Path $p) is export { - return parse-email($p.slurp(:enc<utf8-c8>)); +multi parse-email(IO::Path:D $p --> MaildirIndexer::Email) is export { + return parse-email($p.slurp(:enc<utf8-c8>), path => $p.path); } -multi parse-email(IO::Path $p, :$headers-only!) is export { +multi parse-email(IO::Path:D $p, :$headers-only! --> MaildirIndexer::Email) is export { return parse-email( $p.lines( :enc<utf8-c8>, :nl-in(@separators), :!chomp, )[0], + path => $p.path, ); } -multi parse-email(IO::Socket::Async $s) is export { +multi parse-email(IO::Socket::Async:D $s --> MaildirIndexer::Email) is export { my $string; react { whenever $s.Supply(:enc<utf8-c8>) { @@ -80,8 +83,8 @@ multi parse-email(IO::Socket::Async $s) is export { return parse-email($string); } -multi parse-email(Str $email-str) is export { - with Message.parse($email-str,:actions(Message-actions.new)) { +multi parse-email(Str:D $email-str, :$path = IO --> MaildirIndexer::Email) is export { + with Message.parse($email-str,:actions(Message-actions.new(:$path))) { return .made; } return Nil; |