-#!/usr/bin/perl -w
+#!/usr/bin/env perl
#
# notmuch-mutt - notmuch (of a) helper for Mutt
#
use warnings;
use File::Path;
+use File::Basename;
use Getopt::Long qw(:config no_getopt_compat);
use Mail::Header;
use Mail::Box::Maildir;
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;
empty_maildir($maildir);
- system("notmuch search --output=files $dup_option $query"
- . " | sed -e 's: :\\\\ :g'"
- . " | xargs --no-run-if-empty ln -s -t $maildir/cur/");
+ 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";
+ }
}
sub prompt($$) {
$mid = $1;
} else { # Message-ID header not found, synthesize a message id
# based on SHA1, as notmuch would do. See:
- # http://git.notmuchmail.org/git/notmuch/blob/HEAD:/lib/sha1.c
+ # https://git.notmuchmail.org/git/notmuch/blob/HEAD:/lib/sha1.c
my $sha = Digest::SHA->new(1);
$sha->add($_) foreach(@headers);
$sha->addfile(\*STDIN);