notmuch-mutt: replace shell pipeline with internal pipe processing

The shell pipeline used to symlink files based in search results
to "cache" directory for mutt(1) to use was prone to portability
problems (due to /bin/sh differences).

The replacement executes `notmuch search` without intermediate shell
(so shell_quote was removed in this case), reads the filenames from
piped output and symlinks files internally.
This commit is contained in:
Tomi Ollila 2020-07-27 22:38:33 +03:00 committed by David Bremner
parent 00dc5dd824
commit 0d4a3c7185

View file

@ -12,6 +12,7 @@ use strict;
use warnings; use warnings;
use File::Path; use File::Path;
use File::Basename;
use Getopt::Long qw(:config no_getopt_compat); use Getopt::Long qw(:config no_getopt_compat);
use Mail::Header; use Mail::Header;
use Mail::Box::Maildir; use Mail::Box::Maildir;
@ -41,16 +42,17 @@ sub search($$$) {
my ($maildir, $remove_dups, $query) = @_; my ($maildir, $remove_dups, $query) = @_;
my $dup_option = ""; my $dup_option = "";
$query = shell_quote($query); my @args = qw/notmuch search --output=files/;
push @args, "--duplicate=1" if $remove_dups;
if ($remove_dups) { push @args, $query;
$dup_option = "--duplicate=1";
}
empty_maildir($maildir); empty_maildir($maildir);
system("notmuch search --output=files $dup_option $query" open my $pipe, '-|', @args or die "Running @args failed: $!\n";
. " | sed -e 's: :\\\\ :g'" while (<$pipe>) {
. " | while IFS= read -r searchoutput; do ln -s \$searchoutput $maildir/cur/; done"); chomp;
my $ln = "$maildir/cur/" . basename $_;
symlink $_, "$ln" or warn "Failed to symlink '$_', '$ln': $!\n";
}
} }
sub prompt($$) { sub prompt($$) {