]> git.cworth.org Git - notmuch/blobdiff - contrib/notmuch-mutt/notmuch-mutt
notmuch-mutt: fix Xapian query construction
[notmuch] / contrib / notmuch-mutt / notmuch-mutt
index d1e2c084b4208f093f97a47e81169da28a65d9ad..b38258f5772a7808889e5f1c1c9cd0ea61c76187 100755 (executable)
@@ -2,7 +2,7 @@
 #
 # notmuch-mutt - notmuch (of a) helper for Mutt
 #
-# Copyright: © 2011-2015 Stefano Zacchiroli <zack@upsilon.cc>
+# Copyright: Â© 2011-2015 Stefano Zacchiroli <zack@upsilon.cc>
 # License: GNU General Public License (GPL), version 3 or above
 #
 # See the bottom of this file for more documentation.
@@ -124,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);
 
@@ -135,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() {