X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=contrib%2Fnotmuch-mutt%2Fnotmuch-mutt;h=b38258f5772a7808889e5f1c1c9cd0ea61c76187;hb=6d383d404982c6e12dd68dcdf94b3490e3de4645;hp=0e46a8c1b95e76163eed68694aa5a1a973c8b371;hpb=c3a683299d4c27d6eadaacf4fb516f73a6c69fc3;p=notmuch diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt index 0e46a8c1..b38258f5 100755 --- a/contrib/notmuch-mutt/notmuch-mutt +++ b/contrib/notmuch-mutt/notmuch-mutt @@ -2,7 +2,7 @@ # # notmuch-mutt - notmuch (of a) helper for Mutt # -# Copyright: © 2011-2015 Stefano Zacchiroli +# Copyright: © 2011-2015 Stefano Zacchiroli # License: GNU General Public License (GPL), version 3 or above # # See the bottom of this file for more documentation. @@ -12,6 +12,7 @@ use strict; use warnings; use File::Path; +use File::Basename; use Getopt::Long qw(:config no_getopt_compat); use Mail::Header; use Mail::Box::Maildir; @@ -41,16 +42,17 @@ sub search($$$) { 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 -r -I searchoutput ln -s searchoutput $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($$) { @@ -122,7 +124,11 @@ sub thread_action($$@) { empty_maildir($results_dir); die "notmuch-mutt: cannot find Message-Id, abort.\n"; } - my $search_cmd = 'notmuch search --output=threads ' . shell_quote("id:$mid"); + + $mid =~ s/ //g; # notmuch strips spaces before storing Message-Id + $mid =~ s/"/""/g; # escape all double quote characters + + my $search_cmd = 'notmuch search --output=threads ' . shell_quote(qq{id:"$mid"}); my $tid = `$search_cmd`; # get thread id chomp($tid); @@ -133,7 +139,10 @@ sub tag_action(@) { my $mid = get_message_id(); defined $mid or die "notmuch-mutt: cannot find Message-Id, abort.\n"; - system("notmuch", "tag", @_, "--", "id:$mid"); + $mid =~ s/ //g; # notmuch strips spaces before storing Message-Id + $mid =~ s/"/""/g; # escape all double quote characters + + system("notmuch", "tag", @_, "--", qq{id:"$mid"}); } sub die_usage() {