From fa3f0cbcd1af5008e56c77e3c46ab60b5eca3a13 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 9 Feb 2021 07:09:33 -0100 Subject: use MdirReader in -watch and InboxWritable MdirReader now handles files in "$MAILDIR/new" properly and is stricter about what it accepts. eml_from_path is also made robust against FIFOs while eliminating TOCTOU races with between stat(2) and open(2) calls. --- t/mdir_reader.t | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 t/mdir_reader.t (limited to 't') diff --git a/t/mdir_reader.t b/t/mdir_reader.t new file mode 100644 index 00000000..51b38af4 --- /dev/null +++ b/t/mdir_reader.t @@ -0,0 +1,22 @@ +#!perl -w +# Copyright (C) 2021 all contributors +# License: AGPL-3.0+ +use PublicInbox::TestCommon; +require_ok 'PublicInbox::MdirReader'; +*maildir_basename_flags = \&PublicInbox::MdirReader::maildir_basename_flags; +*maildir_path_flags = \&PublicInbox::MdirReader::maildir_path_flags; + +is(maildir_basename_flags('foo'), '', 'new valid name accepted'); +is(maildir_basename_flags('foo:2,'), '', 'cur valid name accepted'); +is(maildir_basename_flags('foo:2,bar'), 'bar', 'flags name accepted'); +is(maildir_basename_flags('.foo:2,bar'), undef, 'no hidden files'); +is(maildir_basename_flags('fo:o:2,bar'), undef, 'no extra colon'); +is(maildir_path_flags('/path/to/foo:2,S'), 'S', 'flag returned for path'); +is(maildir_path_flags('/path/to/.foo:2,S'), undef, 'no hidden paths'); +is(maildir_path_flags('/path/to/foo:2,'), '', 'no flags in path'); + +# not sure if there's a better place for eml_from_path +use_ok 'PublicInbox::InboxWritable', qw(eml_from_path); +is(eml_from_path('.'), undef, 'eml_from_path fails on directory'); + +done_testing; -- cgit v1.2.3-24-ge0c7