user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 6/8] lei inspect: support reading eml from --stdin
  2021-09-03  8:54  7% [PATCH 0/8] lei: fix IMAP R/W; L/kw false positives Eric Wong
@ 2021-09-03  8:54  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-09-03  8:54 UTC (permalink / raw)
  To: meta

This can be useful inside mutt since I was diagnosing why
a label ("L:$FOO") search was giving me a false-positive
search result...
---
 lib/PublicInbox/LEI.pm        |  4 ++--
 lib/PublicInbox/LeiInspect.pm | 40 ++++++++++++++++++++++++++++++-----
 2 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 8b6c1d36..098a45ba 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -279,8 +279,8 @@ our %CMD = ( # sorted in order of importance/use:
 		'git-config(1) wrapper for '._config_path($_[0]);
 	}, qw(config-file|system|global|file|f=s), # for conflict detection
 	 qw(c=s@ C=s@), pass_through('git config') ],
-'inspect' => [ 'ITEMS...', 'inspect lei/store and/or local external',
-	qw(pretty ascii dir=s), @c_opt ],
+'inspect' => [ 'ITEMS...|--stdin', 'inspect lei/store and/or local external',
+	qw(stdin| pretty ascii dir=s), @c_opt ],
 
 'init' => [ '[DIRNAME]', sub {
 	"initialize storage, default: ".store_path($_[0]);
diff --git a/lib/PublicInbox/LeiInspect.pm b/lib/PublicInbox/LeiInspect.pm
index 2ade17af..25bd47e7 100644
--- a/lib/PublicInbox/LeiInspect.pm
+++ b/lib/PublicInbox/LeiInspect.pm
@@ -9,6 +9,7 @@ package PublicInbox::LeiInspect;
 use strict;
 use v5.10.1;
 use PublicInbox::Config;
+use PublicInbox::MID qw(mids);
 
 sub inspect_blob ($$) {
 	my ($lei, $oidhex) = @_;
@@ -184,6 +185,32 @@ sub inspect1 ($$$) {
 	1;
 }
 
+sub _inspect_argv ($$) {
+	my ($lei, $argv) = @_;
+	my $multi = scalar(@$argv) > 1;
+	$lei->out('[') if $multi;
+	while (defined(my $x = shift @$argv)) {
+		inspect1($lei, $x, scalar(@$argv)) or return;
+	}
+	$lei->out(']') if $multi;
+}
+
+sub ins_add { # InputPipe->consume callback
+	my ($lei) = @_; # $_[1] = $rbuf
+	if (defined $_[1]) {
+		$_[1] eq '' and return eval {
+			my $str = delete $lei->{istr};
+			$str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s;
+			my $eml = PublicInbox::Eml->new(\$str);
+			_inspect_argv($lei, [ 'blob:'.$lei->git_blob_id($eml),
+				map { "mid:$_" } @{mids($eml)} ]);
+		};
+		$lei->{istr} .= $_[1];
+	} else {
+		$lei->fail("error reading stdin: $!");
+	}
+}
+
 sub lei_inspect {
 	my ($lei, @argv) = @_;
 	$lei->{json} = ref(PublicInbox::Config::json())->new->utf8->canonical;
@@ -196,12 +223,15 @@ sub lei_inspect {
 	}
 	$lei->start_pager if -t $lei->{1};
 	$lei->{1}->autoflush(0);
-	my $multi = scalar(@argv) > 1;
-	$lei->out('[') if $multi;
-	while (defined(my $x = shift @argv)) {
-		inspect1($lei, $x, scalar(@argv)) or return;
+	if ($lei->{opt}->{stdin}) {
+		return $lei->fail(<<'') if @argv;
+no args allowed on command-line with --stdin
+
+		require PublicInbox::InputPipe;
+		PublicInbox::InputPipe::consume($lei->{0}, \&ins_add, $lei);
+		return;
 	}
-	$lei->out(']') if $multi;
+	_inspect_argv($lei, \@argv);
 }
 
 sub _complete_inspect {

^ permalink raw reply related	[relevance 7%]

* [PATCH 0/8] lei: fix IMAP R/W; L/kw false positives
@ 2021-09-03  8:54  7% Eric Wong
  2021-09-03  8:54  7% ` [PATCH 6/8] lei inspect: support reading eml from --stdin Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-09-03  8:54 UTC (permalink / raw)
  To: meta

Back to using syslog more for errors, since it's still less
instrusive.  IMAP R/W is fixed (ugh, lack of automatic tests
since we only have a read-only IMAP server for testing).
Some error/warning fixes, and false-positives on L: and kw:
searches on local (but not remote) externals are avoided.

"lei inspect --stdin" was somewhat useful for figuring out why
L: was false-positiving an external result on me.

Eric Wong (8):
  lei: dump errors to syslog, and not to CLI
  lei/store: quiet down link(2) warnings
  lei: ->child_error less error-prone
  lei: use lei->lms in place of lse->lms in a few places
  lei up --all: avoid double-close on shared STDOUT
  lei inspect: support reading eml from --stdin
  lei_xsearch: avoid false-positives on externals w/ L: and kw:
  lei: fix read/write IMAP access

 MANIFEST                            |  1 +
 lib/PublicInbox/LEI.pm              | 27 ++++++++++--------
 lib/PublicInbox/LeiBlob.pm          |  2 +-
 lib/PublicInbox/LeiIndex.pm         |  2 +-
 lib/PublicInbox/LeiInput.pm         |  4 +--
 lib/PublicInbox/LeiInspect.pm       | 43 ++++++++++++++++++++++++-----
 lib/PublicInbox/LeiLcat.pm          |  2 +-
 lib/PublicInbox/LeiPruneMailSync.pm | 26 ++++++++---------
 lib/PublicInbox/LeiRediff.pm        |  2 +-
 lib/PublicInbox/LeiStore.pm         | 10 ++-----
 lib/PublicInbox/LeiStoreErr.pm      |  4 +--
 lib/PublicInbox/LeiToMail.pm        |  2 +-
 lib/PublicInbox/LeiUp.pm            |  6 +++-
 lib/PublicInbox/LeiXSearch.pm       |  1 +
 lib/PublicInbox/NetReader.pm        |  5 +++-
 lib/PublicInbox/NetWriter.pm        |  2 ++
 lib/PublicInbox/Watch.pm            |  2 ++
 t/lei-daemon.t                      |  5 ----
 t/lei-up.t                          | 39 ++++++++++++++++++++++++++
 19 files changed, 130 insertions(+), 55 deletions(-)
 create mode 100644 t/lei-up.t


^ permalink raw reply	[relevance 7%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-09-03  8:54  7% [PATCH 0/8] lei: fix IMAP R/W; L/kw false positives Eric Wong
2021-09-03  8:54  7% ` [PATCH 6/8] lei inspect: support reading eml from --stdin Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).