summaryrefslogtreecommitdiff
path: root/lib/MaildirIndexer/Parser.rakumod
diff options
context:
space:
mode:
Diffstat (limited to 'lib/MaildirIndexer/Parser.rakumod')
-rw-r--r--lib/MaildirIndexer/Parser.rakumod35
1 files changed, 18 insertions, 17 deletions
diff --git a/lib/MaildirIndexer/Parser.rakumod b/lib/MaildirIndexer/Parser.rakumod
index 7623d17..d30ca86 100644
--- a/lib/MaildirIndexer/Parser.rakumod
+++ b/lib/MaildirIndexer/Parser.rakumod
@@ -61,32 +61,34 @@ my class Message-actions {
}
multi parse-email(IO::Path:D $p --> MaildirIndexer::Email) is export {
- MaildirIndexer::LogTimelineSchema::Parse::Email::File.log: :file($p.path), {
+ my MaildirIndexer::Email $result;
+ MaildirIndexer::LogTimelineSchema::Parse::Email::File.log: :file($p.path), -> {
# as of 2019,11, `slurp` replaces all \r\n with \n ??
- return parse-email($p.slurp(:enc<utf8-c8>), path => $p);
+ $result = parse-email($p.slurp(:enc<utf8-c8>), path => $p);
}
+ return $result;
}
multi parse-email(IO::Path:D $p, :$headers-only! --> MaildirIndexer::Email) is export {
- # due to a bug, we can't put that LEAVE inside the inner block;
- # see https://github.com/rakudo/rakudo/issues/2380
- my IO::Handle $h; LEAVE { .close with $h };
- MaildirIndexer::LogTimelineSchema::Parse::Email::File.log: :file($p.path), {
- $h = $p.open(
+ my MaildirIndexer::Email $result;
+ MaildirIndexer::LogTimelineSchema::Parse::Email::File.log: :file($p.path), -> {
+ my IO::Handle $h = $p.open(
:enc<utf8-c8>,
:nl-in(@separators),
:!chomp,
);
- return parse-email(
+ $result = parse-email(
$h.lines()[0],
path => $p,
);
+ $h.close();
}
+ return $result;
}
multi parse-email(IO::Socket::Async:D $s --> MaildirIndexer::Email) is export {
- MaildirIndexer::LogTimelineSchema::Parse::Email::Socket.log: {
- my MaildirIndexer::Email $result;
+ my MaildirIndexer::Email $result;
+ MaildirIndexer::LogTimelineSchema::Parse::Email::Socket.log: -> {
my $string;
react {
whenever $s.Supply(:enc<utf8-c8>) {
@@ -98,18 +100,17 @@ multi parse-email(IO::Socket::Async:D $s --> MaildirIndexer::Email) is export {
QUIT { done };
}
}
- return $result;
}
+ return $result;
}
multi parse-email(Str:D $email-str, :$path = IO --> MaildirIndexer::Email) is export {
- MaildirIndexer::LogTimelineSchema::Parse::Email::Str.log: {
- CATCH { return .fail };
+ my MaildirIndexer::Email $result;
+ MaildirIndexer::LogTimelineSchema::Parse::Email::Str.log: -> {
+ CATCH { warn $_; return Nil };
with Message.parse($email-str,:actions(Message-actions.new(:$path))) {
- return .made;
- }
- else {
- return Nil;
+ $result = .made;
}
}
+ return $result;
}