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