about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiOverview.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-01-19 09:34:35 +0000
committerEric Wong <e@80x24.org>2021-01-21 03:29:14 +0000
commitb0b13249a538fc6f9a4c109d15d51170e3dd8bdd (patch)
treeb0e88d4ae37c971f5967cdc82b5f657bc3d98c90 /lib/PublicInbox/LeiOverview.pm
parent934b7431d93e6e49920e407c02653edad06987d6 (diff)
downloadpublic-inbox-b0b13249a538fc6f9a4c109d15d51170e3dd8bdd.tar.gz
We'll need it for IMAP support, at least.  Proper mbox family
detection will be expensive, so deal with it later.
Diffstat (limited to 'lib/PublicInbox/LeiOverview.pm')
-rw-r--r--lib/PublicInbox/LeiOverview.pm17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/PublicInbox/LeiOverview.pm b/lib/PublicInbox/LeiOverview.pm
index a7021b03..dcc3088b 100644
--- a/lib/PublicInbox/LeiOverview.pm
+++ b/lib/PublicInbox/LeiOverview.pm
@@ -38,6 +38,21 @@ sub ovv_out_lk_cancel ($) {
                 unlink(delete($self->{lock_path}));
 }
 
+sub detect_fmt ($$) {
+        my ($lei, $dst) = @_;
+        if ($dst =~ m!\A([:/]+://)!) {
+                $lei->fail("$1 support not implemented, yet\n");
+        } elsif (!-e $dst) {
+                'maildir'; # the default
+        } elsif (-f _ || -p _) {
+                $lei->fail("unable to determine mbox family of $dst\n");
+        } elsif (-d _) { # TODO: MH?
+                'maildir';
+        } else {
+                $lei->fail("unable to determine format of $dst\n");
+        }
+}
+
 sub new {
         my ($class, $lei) = @_;
         my $opt = $lei->{opt};
@@ -54,7 +69,7 @@ sub new {
 
         }
         $fmt //= 'json' if $dst eq '/dev/stdout';
-        $fmt //= 'maildir';
+        $fmt //= detect_fmt($lei, $dst) or return;
 
         if (index($dst, '://') < 0) { # not a URL, so assume path
                  $dst = File::Spec->canonpath($dst);