[PATCH v3 3/3] notmuch-mutt: check that the search cache Maildir is not a real Maildir

2023-05-27 Thread Paul Wise
This prevents data loss when users configure the search cache Maildir to be a
real Maildir containing their real mail data, since the search cache Maildir
is expected to contain only symlinks to the real mail data.

Prevents: 
---
 contrib/notmuch-mutt/notmuch-mutt | 46 +++
 1 file changed, 46 insertions(+)

diff --git a/contrib/notmuch-mutt/notmuch-mutt 
b/contrib/notmuch-mutt/notmuch-mutt
index 875fd032..b81252c8 100755
--- a/contrib/notmuch-mutt/notmuch-mutt
+++ b/contrib/notmuch-mutt/notmuch-mutt
@@ -13,6 +13,7 @@ use warnings;
 
 use File::Path;
 use File::Basename;
+use File::Find;
 use Getopt::Long qw(:config no_getopt_compat);
 use Mail::Header;
 use Mail::Box::Maildir;
@@ -25,6 +26,50 @@ my $xdg_cache_dir = "$ENV{HOME}/.cache";
 $xdg_cache_dir = $ENV{XDG_CACHE_HOME} if $ENV{XDG_CACHE_HOME};
 my $cache_dir = "$xdg_cache_dir/notmuch/mutt";
 
+sub die_dir($$) {
+my ($maildir, $error) = @_;
+die "notmuch-mutt: search cache maildir $maildir $error\n".
+"Please ensure that the notmuch-mutt search cache Maildir\n".
+"contains no subfolders or real mail data, only symlinks to mail\n";
+}
+
+sub die_subdir($$$) {
+my ($maildir, $subdir, $error) = @_;
+die_dir($maildir, "subdir $subdir $error");
+}
+
+# check that the search cache maildir is that and not a real maildir
+# otherwise there could be data loss when the search cache is emptied
+sub check_search_cache_maildir($) {
+my ($maildir) = (@_);
+
+return unless -e $maildir;
+
+-d $maildir or die_dir($maildir, 'is not a directory');
+
+opendir(my $mdh, $maildir) or die_dir($maildir, "cannot be opened: $!");
+my @contents = grep { !/^\.\.?$/ } readdir $mdh;
+closedir $mdh;
+
+my @required = ('cur', 'new', 'tmp');
+foreach my $d (@required) {
+-l "$maildir/$d" and die_dir($maildir, "contains symlink $d");
+-e "$maildir/$d" or die_subdir($maildir, $d, 'is missing');
+-d "$maildir/$d" or die_subdir($maildir, $d, 'is not a directory');
+find(sub {
+$_ eq '.' and return;
+$_ eq '..' and return;
+-l $_ or die_subdir($maildir, $d, "contains non-symlink $_");
+}, "$maildir/$d");
+}
+
+my %required = map { $_ => 1 } @required;
+foreach my $d (@contents) {
+-l "$maildir/$d" and die_dir( $maildir, "contains symlink $d");
+-d "$maildir/$d" or die_dir( $maildir, "contains non-directory $d");
+exists($required{$d}) or die_dir( $maildir, "contains directory $d");
+}
+}
 
 # create an empty search cache maildir (if missing) or empty existing one
 sub empty_search_cache_maildir($) {
@@ -45,6 +90,7 @@ sub search($$$) {
 push @args, "--duplicate=1" if $remove_dups;
 push @args, $query;
 
+check_search_cache_maildir($maildir);
 empty_search_cache_maildir($maildir);
 open my $pipe, '-|', @args or die "Running @args failed: $!\n";
 while (<$pipe>) {
-- 
2.40.1

___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH v2 3/3] notmuch-mutt: check that the search cache Maildir is not a real Maildir

2023-05-27 Thread Paul Wise
This prevents data loss when users configure the search cache Maildir to be a
real Maildir containing their real mail data, since the search cache Maildir
is expected to contain only symlinks to the real mail data.

Prevents: 
---
 contrib/notmuch-mutt/notmuch-mutt | 46 +++
 1 file changed, 46 insertions(+)

diff --git a/contrib/notmuch-mutt/notmuch-mutt 
b/contrib/notmuch-mutt/notmuch-mutt
index 875fd032..1ac68065 100755
--- a/contrib/notmuch-mutt/notmuch-mutt
+++ b/contrib/notmuch-mutt/notmuch-mutt
@@ -13,6 +13,7 @@ use warnings;
 
 use File::Path;
 use File::Basename;
+use File::Find;
 use Getopt::Long qw(:config no_getopt_compat);
 use Mail::Header;
 use Mail::Box::Maildir;
@@ -25,6 +26,50 @@ my $xdg_cache_dir = "$ENV{HOME}/.cache";
 $xdg_cache_dir = $ENV{XDG_CACHE_HOME} if $ENV{XDG_CACHE_HOME};
 my $cache_dir = "$xdg_cache_dir/notmuch/mutt";
 
+sub die_dir($$) {
+my ($maildir, $error) = @_;
+die "notmuch-mutt: search cache maildir $maildir $error\n".
+"Please ensure that the notmuch-mutt search cache Maildir\n".
+"contains no subfolders or real mail data, only symlinks to mail\n";
+}
+
+sub die_subdir($$$) {
+my ($maildir, $subdir, $error) = @_;
+die_dir($maildir, "subdir $subdir $error");
+}
+
+# check that the search cache maildir is that and not a real maildir
+# otherwise there could be data loss when the search cache is emptied
+sub check_search_cache_maildir($) {
+my ($maildir) = (@_);
+
+return unless -e $maildir;
+
+-d $maildir or die_dir($maildir, 'is not a directory');
+
+opendir(my $mdh, $maildir) or die_dir($maildir, "cannot be opened: $!");
+my @contents = grep { !/^\.\.?$/ } readdir $mdh;
+closedir $mdh;
+
+my @required = ('cur', 'new', 'tmp');
+foreach my $d (@required) {
+-l "$maildir/$d" and die_dir($maildir, "contains symlink $d");
+-e "$maildir/$d" or die_subdir($maildir, $d, 'is missing');
+-d "$maildir/$d" or die_subdir($maildir, $d, 'is not a directory');
+find(sub {
+$_ eq '.' and return;
+$_ eq '..' and return;
+-l $_ or die_subdir($maildir, $d, "contains non-symlink $_");
+}, "$maildir/$d");
+}
+
+my %required = map { $_ => 1 } @required;
+foreach my $d (@contents) {
+-l "$maildir/$d" and die_dir( $maildir, "contains symlink $d");
+-d "$maildir/$d" or die_dir( $maildir, "contains non-directory $d");
+exists($required[$d]) or die_dir( $maildir, "contains directory $d");
+}
+}
 
 # create an empty search cache maildir (if missing) or empty existing one
 sub empty_search_cache_maildir($) {
@@ -45,6 +90,7 @@ sub search($$$) {
 push @args, "--duplicate=1" if $remove_dups;
 push @args, $query;
 
+check_search_cache_maildir($maildir);
 empty_search_cache_maildir($maildir);
 open my $pipe, '-|', @args or die "Running @args failed: $!\n";
 while (<$pipe>) {
-- 
2.40.1

___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH v2 1/3] notmuch-mutt: clarify the empty Maildir function operates on search caches

2023-05-27 Thread Paul Wise
Rename the function and adjust the documentation comment.
---
 contrib/notmuch-mutt/notmuch-mutt | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/contrib/notmuch-mutt/notmuch-mutt 
b/contrib/notmuch-mutt/notmuch-mutt
index 01db6908..0f7379ac 100755
--- a/contrib/notmuch-mutt/notmuch-mutt
+++ b/contrib/notmuch-mutt/notmuch-mutt
@@ -26,8 +26,8 @@ $xdg_cache_dir = $ENV{XDG_CACHE_HOME} if $ENV{XDG_CACHE_HOME};
 my $cache_dir = "$xdg_cache_dir/notmuch/mutt";
 
 
-# create an empty maildir (if missing) or empty an existing maildir"
-sub empty_maildir($) {
+# create an empty search cache maildir (if missing) or empty existing one
+sub empty_search_cache_maildir($) {
 my ($maildir) = (@_);
 rmtree($maildir) if (-d $maildir);
 my $folder = new Mail::Box::Maildir(folder => $maildir,
@@ -45,7 +45,7 @@ sub search($$$) {
 push @args, "--duplicate=1" if $remove_dups;
 push @args, $query;
 
-empty_maildir($maildir);
+empty_search_cache_maildir($maildir);
 open my $pipe, '-|', @args or die "Running @args failed: $!\n";
 while (<$pipe>) {
chomp;
@@ -120,7 +120,7 @@ sub thread_action($$@) {
 
 my $mid = get_message_id();
 if (! defined $mid) {
-   empty_maildir($results_dir);
+   empty_search_cache_maildir($results_dir);
die "notmuch-mutt: cannot find Message-Id, abort.\n";
 }
 
-- 
2.40.1

___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH v2 2/3] notmuch-mutt: do not clear search cache Maildir when nothing is found

2023-05-27 Thread Paul Wise
The previous results might be useful to the user but
an empty directory definitely isn't useful.
---
 contrib/notmuch-mutt/notmuch-mutt | 1 -
 1 file changed, 1 deletion(-)

diff --git a/contrib/notmuch-mutt/notmuch-mutt 
b/contrib/notmuch-mutt/notmuch-mutt
index 0f7379ac..875fd032 100755
--- a/contrib/notmuch-mutt/notmuch-mutt
+++ b/contrib/notmuch-mutt/notmuch-mutt
@@ -120,7 +120,6 @@ sub thread_action($$@) {
 
 my $mid = get_message_id();
 if (! defined $mid) {
-   empty_search_cache_maildir($results_dir);
die "notmuch-mutt: cannot find Message-Id, abort.\n";
 }
 
-- 
2.40.1

___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] notmuch-mutt: check that the search cache Maildir is not a real Maildir WAS: Re: Data loss

2023-05-27 Thread Paul Wise
On Sat, 2023-05-27 at 21:10 -0300, David Bremner wrote:

> If possible, please use git-send-email for future series. 

Will do, I forgot about the --cover-letter option.

> This seems to have introduced a warning, and I think there's a bug.
> 
> % notmuch mutt search tag:inbox 
> Argument "new" isn't numeric in array or hash lookup at /usr/bin/notmuch-mutt 
> line 70.
> Argument "cur" isn't numeric in array or hash lookup at /usr/bin/notmuch-mutt 
> line 70.
> Argument "tmp" isn't numeric in array or hash lookup at /usr/bin/notmuch-mutt 
> line 70.
> 
> If I remember correctly you need to use {} for hash references in Perl.

Woops! Thanks, fixed in the v2 patch series.

> It might clearer to use the return value from (a possibly renamed
> check_search_cache (then the -d can be eliminated / folded into the new
> function).

When the checks fail, the Maildir creation and Maildir symlink
additions shouldn't happen either, otherwise Maildirs with real data
may get mail files overwritten with symlinks back to themselves. So
there needs to be a die() or return before the creation and the search
anyway and so checks may as well just die() when the first check fails.

I experimented with returning anyway and it makes things more complex:

File::Find cannot abort the search except via die() and so the calling
code would need to use eval in order to catch the die() and return it.

Threading return values all the way back up to search_action adds lots
of error checks to every function along the way.

The search_action interactive mode doesn't do more than one search
anyway so it would still just need to die() when there is an error.

If the code were to grow a multi-command interactive prompt, that could
use eval to catch and print the die() errors. Such a prompt would need
to do that anyway, because the non-search actions call die() already.

So I think that throwing exceptions via die() is the simpler method.

Since checking that the Maildir is suitable is really a separate action
to clearing the previous search results, I've moved the check function
from the empty function to the search function in the v2 patch series.

-- 
bye,
pabs

https://bonedaddy.net/pabs3/


signature.asc
Description: This is a digitally signed message part
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH] notmuch-mutt: check that the search cache Maildir is not a real Maildir WAS: Re: Data loss

2023-05-23 Thread Paul Wise
David Bremner wrote:

> Carl Worth  writes:
> 
> > What it could also do is create some placeholder file like
> > .NOTMUCH-MUTT-OUTPUT-DIR when it writes its output. And then it could
> > check for that file's existence before removing a directory.
> 
> Sounds reasonable to me. Would someone like to make a patch for
> notmuch-mutt?

This has the problem that the migration from existing search cache
Maildirs to the new setup needs users to do manual work and that they
or something else could later modify the migrated Maildir by adding
real mail data or subfolders containing real data.

I think a better option is to detect if the search cache Maildir is
actually a Maildir and doesn't contain any data that could be lost.

I have attached three patches I created to improve notmuch-mutt safety.

-- 
bye,
pabs

https://bonedaddy.net/pabs3/
From 22dad230dc368ff09cef2fd1eddd10ba89d41d16 Mon Sep 17 00:00:00 2001
From: Paul Wise 
Date: Wed, 24 May 2023 08:26:38 +0800
Subject: [PATCH 1/3] notmuch-mutt: clarify the empty Maildir function operates
 on search caches

Rename the function and adjust the documentation comment.
---
 contrib/notmuch-mutt/notmuch-mutt | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt
index d1e2c084..eef1dea5 100755
--- a/contrib/notmuch-mutt/notmuch-mutt
+++ b/contrib/notmuch-mutt/notmuch-mutt
@@ -27,8 +27,8 @@ $xdg_cache_dir = $ENV{XDG_CACHE_HOME} if $ENV{XDG_CACHE_HOME};
 my $cache_dir = "$xdg_cache_dir/notmuch/mutt";
 
 
-# create an empty maildir (if missing) or empty an existing maildir"
-sub empty_maildir($) {
+# create an empty search cache maildir (if missing) or empty existing one
+sub empty_search_cache_maildir($) {
 my ($maildir) = (@_);
 rmtree($maildir) if (-d $maildir);
 my $folder = new Mail::Box::Maildir(folder => $maildir,
@@ -46,7 +46,7 @@ sub search($$$) {
 push @args, "--duplicate=1" if $remove_dups;
 push @args, $query;
 
-empty_maildir($maildir);
+empty_search_cache_maildir($maildir);
 open my $pipe, '-|', @args or die "Running @args failed: $!\n";
 while (<$pipe>) {
 	chomp;
@@ -121,7 +121,7 @@ sub thread_action($$@) {
 
 my $mid = get_message_id();
 if (! defined $mid) {
-	empty_maildir($results_dir);
+	empty_search_cache_maildir($results_dir);
 	die "notmuch-mutt: cannot find Message-Id, abort.\n";
 }
 my $search_cmd = 'notmuch search --output=threads ' . shell_quote("id:$mid");
-- 
2.40.1

From 4cb6a83e634b4c2dbbaa1099811cf84d65627029 Mon Sep 17 00:00:00 2001
From: Paul Wise 
Date: Wed, 24 May 2023 08:24:02 +0800
Subject: [PATCH 2/3] notmuch-mutt: do not clear search cache Maildir when
 nothing is found

The previous results might be useful to the user but
an empty directory definitely isn't useful.
---
 contrib/notmuch-mutt/notmuch-mutt | 1 -
 1 file changed, 1 deletion(-)

diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt
index eef1dea5..9badc59c 100755
--- a/contrib/notmuch-mutt/notmuch-mutt
+++ b/contrib/notmuch-mutt/notmuch-mutt
@@ -121,7 +121,6 @@ sub thread_action($$@) {
 
 my $mid = get_message_id();
 if (! defined $mid) {
-	empty_search_cache_maildir($results_dir);
 	die "notmuch-mutt: cannot find Message-Id, abort.\n";
 }
 my $search_cmd = 'notmuch search --output=threads ' . shell_quote("id:$mid");
-- 
2.40.1

From 46036801970d43c4aee684a46ff0b0e0649e7cfd Mon Sep 17 00:00:00 2001
From: Paul Wise 
Date: Wed, 24 May 2023 06:22:01 +0800
Subject: [PATCH 3/3] notmuch-mutt: check that the search cache Maildir is not
 a real Maildir

This prevents data loss when users configure the search cache Maildir to be a
real Maildir containing their real mail data, since the search cache Maildir
is expected to contain only symlinks to the real mail data.

Prevents: 
---
 contrib/notmuch-mutt/notmuch-mutt | 46 +++
 1 file changed, 46 insertions(+)

diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt
index 9badc59c..2569d055 100755
--- a/contrib/notmuch-mutt/notmuch-mutt
+++ b/contrib/notmuch-mutt/notmuch-mutt
@@ -13,6 +13,7 @@ use warnings;
 
 use File::Path;
 use File::Basename;
+use File::Find;
 use Getopt::Long qw(:config no_getopt_compat);
 use Mail::Header;
 use Mail::Box::Maildir;
@@ -26,10 +27,55 @@ my $xdg_cache_dir = "$ENV{HOME}/.cache";
 $xdg_cache_dir = $ENV{XDG_CACHE_HOME} if $ENV{XDG_CACHE_HOME};
 my $cache_dir = "$xdg_cache_dir/notmuch/mutt";
 
+sub die_dir($$) {
+my ($maildir, $error) = @_;
+die "notmuch-mutt: search cache maildir $maildir $error\n".
+"Please ensure that the notmuch-mutt search cache Maildir\n".
+"contains no subfolders or real mail data, only symlinks to mail\n";
+}
+
+sub die_subdir($$$) {
+my ($m

[PATCH] notmuch-mutt: convert ISO-8859-15 copyright statement to UTF-8

2023-05-23 Thread Paul Wise

Suggested-by: isutf8 & check-all-the-things
---
 contrib/notmuch-mutt/notmuch-mutt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt
index d1e2c084..1e12038c 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.
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] notmuch-mutt: replace extra command with notmuch-native thread search feature

2023-04-09 Thread Paul Wise
On Sun, 2023-04-09 at 13:00 -0300, David Bremner wrote:

> You might be interested in the s-expression query parser. Part of the
> goal is to be less dwim/quirky than the native Xapian query parser, and
> to make it easier / safer to construct notmuch queries via programs.

That does seem saner to manually construct queries in, but it would
still be better to have a query construction library, otherwise
programs are going to get it wrong all the time, even within notmuch.

> It doesn't do the message-id munging you mention (yet?),

This is a big part of the query construction headache, re-implementing
the space stripping is easy, the user part removal is harder and I
can't find any docs on what else is required here.

PS: I don't intend to work on switching notmuch-mutt to sexp.

-- 
bye,
pabs

https://bonedaddy.net/pabs3/


signature.asc
Description: This is a digitally signed message part
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] notmuch-mutt: replace extra command with notmuch-native thread search feature

2023-04-08 Thread Paul Wise
On Sat, 2023-04-08 at 08:42 -0300, David Bremner wrote:

> did you test this with a message-id with spaces in it?
> the quoting is a delicate.

You are correct that the quoting for this was wrong, as it was also
wrong in the code before my patch and I just copied that, however...

I noticed that when notmuch stores the Message-ID in the Xapian
database, it strips the spaces, so messages with spaces in the
Message-ID are not found unless the id: search has no spaces also.

After switching from testing using id: to subject: and reading the
manual page I was able to find the correct quoting for spaces in $mid,
but I also added the space removals for the thread query.

Then I figured I should test with double quote characters and that blew
up in my face too, so I added double quote doubling to workaround that.

Then I noticed that you can put parentheses inside a quoted query and
that changes the meaning of the query but I couldn't find any way to
prevent an arbitrary Message-Id from inserting parentheses into the
query. Also notmuch converts Message-Id (test)@hostname to just
@hostname in the Xapian database. I think that right now I am not sure
that re-implementing all the idiosyncrasies of notmuch queries and
Message-Id munging within notmuch-mutt is the way to go, especially
since Message-Id fields that intersect with notmuch features are rare.

So I think that it would be good if there were a library for notmuch
query construction that would take care of all the different quoting
levels, Message-Id munging etc. This could then get language bindings
so that notmuch based tools and MUAs could use them for interactive
graphical query construction. Also maybe Xapian needs or has a way to
construct queries without serialising them to a text string and the
notmuch query construction library I propose could base itself on that.

Anyway, will send an updated patch series including space/quote fixing.

-- 
bye,
pabs

https://bonedaddy.net/pabs3/


signature.asc
Description: This is a digitally signed message part
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH v2 1/2] notmuch-mutt: fix Xapian query construction

2023-04-08 Thread Paul Wise
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

___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH v2 2/2] notmuch-mutt: replace extra command with notmuch thread search feature

2023-04-08 Thread Paul Wise
This should be be slightly faster since it avoids forking a shell
and is less code in and less dependencies for the script.

Since String::ShellQuote isn't used elsewhere, drop mention of it.
---
 contrib/notmuch-mutt/README   | 2 --
 contrib/notmuch-mutt/notmuch-mutt | 9 ++---
 debian/control| 1 -
 3 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/contrib/notmuch-mutt/README b/contrib/notmuch-mutt/README
index 26996c4a..c7520228 100644
--- a/contrib/notmuch-mutt/README
+++ b/contrib/notmuch-mutt/README
@@ -39,8 +39,6 @@ To *run* notmuch-mutt you will need Perl with the following 
libraries:
   (Debian package: libmail-box-perl)
 - Mail::Header 
   (Debian package: libmailtools-perl)
-- String::ShellQuote 
-  (Debian package: libstring-shellquote-perl)
 - Term::ReadLine::Gnu 
   (Debian package: libterm-readline-gnu-perl)
 
diff --git a/contrib/notmuch-mutt/notmuch-mutt 
b/contrib/notmuch-mutt/notmuch-mutt
index 1bb95ba6..48cb5594 100755
--- a/contrib/notmuch-mutt/notmuch-mutt
+++ b/contrib/notmuch-mutt/notmuch-mutt
@@ -17,7 +17,6 @@ use Getopt::Long qw(:config no_getopt_compat);
 use Mail::Header;
 use Mail::Box::Maildir;
 use Pod::Usage;
-use String::ShellQuote;
 use Term::ReadLine;
 use Digest::SHA;
 
@@ -126,13 +125,9 @@ sub thread_action($$@) {
 }
 
 $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);
+$mid =~ s/"//g; # escape all double quote characters twice
 
-search($results_dir, $remove_dups, $tid);
+search($results_dir, $remove_dups, qq{thread:"{id:""$mid""}"});
 }
 
 sub tag_action(@) {
diff --git a/debian/control b/debian/control
index 2dcb8cc7..135eb7ce 100644
--- a/debian/control
+++ b/debian/control
@@ -227,7 +227,6 @@ Architecture: all
 Depends:
  libmail-box-perl,
  libmailtools-perl,
- libstring-shellquote-perl,
  libterm-readline-gnu-perl,
  notmuch (>= 0.4),
  ${misc:Depends},
-- 
2.39.2

___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH] notmuch-mutt: replace extra command with notmuch-native thread search feature

2023-04-07 Thread Paul Wise
This should be be slightly faster since it avoids forking a shell
and is less code in and less dependencies for the script.

Since String::ShellQuote isn't used elsewhere, drop mention of it.
---
 contrib/notmuch-mutt/README   | 2 --
 contrib/notmuch-mutt/notmuch-mutt | 6 +-
 debian/control| 1 -
 3 files changed, 1 insertion(+), 8 deletions(-)

PS: I am not subscribed, please CC me in response.

diff --git a/contrib/notmuch-mutt/README b/contrib/notmuch-mutt/README
index 26996c4a..c7520228 100644
--- a/contrib/notmuch-mutt/README
+++ b/contrib/notmuch-mutt/README
@@ -39,8 +39,6 @@ To *run* notmuch-mutt you will need Perl with the following 
libraries:
   (Debian package: libmail-box-perl)
 - Mail::Header 
   (Debian package: libmailtools-perl)
-- String::ShellQuote 
-  (Debian package: libstring-shellquote-perl)
 - Term::ReadLine::Gnu 
   (Debian package: libterm-readline-gnu-perl)
 
diff --git a/contrib/notmuch-mutt/notmuch-mutt 
b/contrib/notmuch-mutt/notmuch-mutt
index d1e2c084..e0b2aceb 100755
--- a/contrib/notmuch-mutt/notmuch-mutt
+++ b/contrib/notmuch-mutt/notmuch-mutt
@@ -17,7 +17,6 @@ use Getopt::Long qw(:config no_getopt_compat);
 use Mail::Header;
 use Mail::Box::Maildir;
 use Pod::Usage;
-use String::ShellQuote;
 use Term::ReadLine;
 use Digest::SHA;
 
@@ -124,11 +123,8 @@ 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");
-my $tid = `$search_cmd`;   # get thread id
-chomp($tid);
 
-search($results_dir, $remove_dups, $tid);
+search($results_dir, $remove_dups, qq{thread:"{id:$mid}"});
 }
 
 sub tag_action(@) {
diff --git a/debian/control b/debian/control
index 2dcb8cc7..135eb7ce 100644
--- a/debian/control
+++ b/debian/control
@@ -227,7 +227,6 @@ Architecture: all
 Depends:
  libmail-box-perl,
  libmailtools-perl,
- libstring-shellquote-perl,
  libterm-readline-gnu-perl,
  notmuch (>= 0.4),
  ${misc:Depends},
-- 
2.39.2

___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] cli: consider files vanishing during notmuch new non-fatal

2016-11-05 Thread Paul Wise
On Sat, 2016-11-05 at 14:57 +0200, Jani Nikula wrote:

> Add a new exit code for when files vanished, so the caller has a
> chance to detect the race and re-run notmuch new to recover.

I don't think this is the right approach for two reasons:

The exit code you have chosen is still a failure so I will still get
notified for a minor issue. I use chronic to detect fail scenarios.

This is a pretty normal scenario when you have a mail program open and
are auto-running `notmuch new` on a scheduled basis or when new mail
arrives. notmuch should just ignore the error and continue as normal.

-- 
bye,
pabs

https://wiki.debian.org/PaulWise


signature.asc
Description: This is a digitally signed message part
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [Paul Wise] Bug#843127: notmuch: race condition in `notmuch new`?

2016-11-05 Thread Paul Wise
On Fri, 2016-11-04 at 20:47 +0200, Jani Nikula wrote:

> Do you have some other software modifying your mail store while
> you're running notmuch new?

The folder in question has my laptop's exim4 service writing to it when
my cron jobs generate email.

On Fri, 2016-11-04 at 13:26 -0300, David Bremner wrote:

> inotify sounds a bit overcomplicated and perhaps non-portable?

There are similar APIs on non-Linux OSes but there is indeed no common
API or library to abstract away this sort of feature AFAIK.

> It should probably just tolerate disappearing files better, consider
> that a warning.

That sounds like the correct solution indeed. Probably if the code
notices that a file disappeared, it should also rescan the nearby
folders to see if the file was moved instead of deleted.

> As a workaround, if you can replace background use of notmuch-new
> with notmuch-insert (and I understand this doesn't work for
> everyone), you will eliminate this kind of race condition.

Hmm, I don't think that will work for me.

-- 
bye,
pabs

https://wiki.debian.org/PaulWise


signature.asc
Description: This is a digitally signed message part
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch