unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Paul Wise <pabs3@bonedaddy.net>
To: notmuch@notmuchmail.org
Cc: Paul Wise <pabs3@bonedaddy.net>
Subject: [PATCH v2 1/2] notmuch-mutt: fix Xapian query construction
Date: Sun,  9 Apr 2023 12:41:42 +0800	[thread overview]
Message-ID: <20230409044143.4041560-1-pabs3@bonedaddy.net> (raw)
In-Reply-To: <28f564aaeee5bfe4dfd007850920eecbb19daba0.camel@bonedaddy.net>

Spaces need to be stripped when querying the Message-Id,
because notmuch stores them in Xapian with spaces stripped.

All double-quote characters need to be doubled to escape them,
otherwise they will be added as extra query terms outside the id.
---
 contrib/notmuch-mutt/notmuch-mutt | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt
index d1e2c084..1bb95ba6 100755
--- a/contrib/notmuch-mutt/notmuch-mutt
+++ b/contrib/notmuch-mutt/notmuch-mutt
@@ -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() {
-- 
2.39.2

  reply	other threads:[~2023-04-09  4:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-07  0:54 [PATCH] notmuch-mutt: replace extra command with notmuch-native thread search feature Paul Wise
2023-04-08 11:42 ` David Bremner
2023-04-09  4:38   ` Paul Wise
2023-04-09  4:41     ` Paul Wise [this message]
2023-04-09  4:41       ` [PATCH v2 2/2] notmuch-mutt: replace extra command with notmuch " Paul Wise
2023-05-27 17:31         ` David Bremner
2023-04-09 16:00     ` [PATCH] notmuch-mutt: replace extra command with notmuch-native " David Bremner
2023-04-10  0:48       ` Paul Wise
2023-04-10 13:04     ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230409044143.4041560-1-pabs3@bonedaddy.net \
    --to=pabs3@bonedaddy.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).