]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiOverview.pm
lei q: support IMAP/IMAPS --output destinations
[public-inbox.git] / lib / PublicInbox / LeiOverview.pm
index f0ac468417cc5ea4666bc3cbb589a310ef83957e..4db1d8c882e17afebbceafaaf3f0b07ba4df5436 100644 (file)
@@ -51,18 +51,24 @@ sub detect_fmt ($$) {
 }
 
 sub new {
-       my ($class, $lei) = @_;
+       my ($class, $lei, $ofmt_key) = @_;
        my $opt = $lei->{opt};
        my $dst = $opt->{output} // '-';
        $dst = '/dev/stdout' if $dst eq '-';
+       $ofmt_key //= 'format';
 
-       my $fmt = $opt->{'format'};
+       my $fmt = $opt->{$ofmt_key};
        $fmt = lc($fmt) if defined $fmt;
-       if ($dst =~ s/\A([a-z0-9]+)://is) { # e.g. Maildir:/home/user/Mail/
+       if ($dst =~ m!\A([a-z0-9\+]+)://!is) {
+               defined($fmt) and return $lei->fail(<<"");
+--$ofmt_key=$fmt invalid with URL $dst
+
+               $fmt = lc $1;
+       } elsif ($dst =~ s/\A([a-z0-9]+)://is) { # e.g. Maildir:/home/user/Mail/
                my $ofmt = lc $1;
                $fmt //= $ofmt;
                return $lei->fail(<<"") if $fmt ne $ofmt;
---format=$fmt and --output=$ofmt conflict
+--$ofmt_key=$fmt and --output=$ofmt conflict
 
        }
        $fmt //= 'json' if $dst eq '/dev/stdout';
@@ -98,7 +104,10 @@ sub new {
                $opt->{'sort'} //= 'docid' if $dst ne '/dev/stdout';
                $lei->{l2m} = eval { PublicInbox::LeiToMail->new($lei) };
                return $lei->fail($@) if $@;
-               $lei->{early_mua} = 1 if $opt->{mua} && $lei->{l2m}->lock_free;
+               if ($opt->{mua} && $lei->{l2m}->lock_free) {
+                       $lei->{early_mua} = 1;
+                       $opt->{alert} //= [ ':WINCH,:bell' ] if -t $lei->{1};
+               }
        }
        $self;
 }