unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / Atom feed
* [PATCH] notmuch-mutt: replace shell pipeline with internal pipe processing
@ 2020-07-27 19:38 Tomi Ollila
  2020-08-11 17:36 ` David Bremner
  2020-08-12 23:45 ` David Bremner
  0 siblings, 2 replies; 3+ messages in thread
From: Tomi Ollila @ 2020-07-27 19:38 UTC (permalink / raw)
  To: notmuch; +Cc: tomi.ollila

The shell pipeline used to symlink files based in search results
to "cache" directory for mutt(1) to use was prone to portability
problems (due to /bin/sh differences).

The replacement executes `notmuch search` without intermediate shell
(so shell_quote was removed in this case), reads the filenames from
piped output and symlinks files internally.
---

Now also tested a bit by me (remoteusage provides stale symlinks ;)

 contrib/notmuch-mutt/notmuch-mutt | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt
index d33223bd..d1e2c084 100755
--- a/contrib/notmuch-mutt/notmuch-mutt
+++ b/contrib/notmuch-mutt/notmuch-mutt
@@ -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'"
-	   . " | while IFS= read -r searchoutput; do ln -s \$searchoutput $maildir/cur/; done");
+    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($$) {
-- 
2.25.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] notmuch-mutt: replace shell pipeline with internal pipe processing
  2020-07-27 19:38 [PATCH] notmuch-mutt: replace shell pipeline with internal pipe processing Tomi Ollila
@ 2020-08-11 17:36 ` David Bremner
  2020-08-12 23:45 ` David Bremner
  1 sibling, 0 replies; 3+ messages in thread
From: David Bremner @ 2020-08-11 17:36 UTC (permalink / raw)
  To: Tomi Ollila, notmuch; +Cc: tomi.ollila

Tomi Ollila <tomi.ollila@iki.fi> writes:

> The shell pipeline used to symlink files based in search results
> to "cache" directory for mutt(1) to use was prone to portability
> problems (due to /bin/sh differences).
>
> The replacement executes `notmuch search` without intermediate shell
> (so shell_quote was removed in this case), reads the filenames from
> piped output and symlinks files internally.
> ---
>
> Now also tested a bit by me (remoteusage provides stale symlinks ;)

tested by the original bug reporter

       https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=966100#22

seems to work.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] notmuch-mutt: replace shell pipeline with internal pipe processing
  2020-07-27 19:38 [PATCH] notmuch-mutt: replace shell pipeline with internal pipe processing Tomi Ollila
  2020-08-11 17:36 ` David Bremner
@ 2020-08-12 23:45 ` David Bremner
  1 sibling, 0 replies; 3+ messages in thread
From: David Bremner @ 2020-08-12 23:45 UTC (permalink / raw)
  To: Tomi Ollila, notmuch; +Cc: tomi.ollila

Tomi Ollila <tomi.ollila@iki.fi> writes:

> The shell pipeline used to symlink files based in search results
> to "cache" directory for mutt(1) to use was prone to portability
> problems (due to /bin/sh differences).
>
> The replacement executes `notmuch search` without intermediate shell
> (so shell_quote was removed in this case), reads the filenames from
> piped output and symlinks files internally.

applied to master.

d

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-08-12 23:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-27 19:38 [PATCH] notmuch-mutt: replace shell pipeline with internal pipe processing Tomi Ollila
2020-08-11 17:36 ` David Bremner
2020-08-12 23:45 ` David Bremner

unofficial mirror of notmuch@notmuchmail.org

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/notmuch/0 notmuch/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 notmuch notmuch/ https://yhetil.org/notmuch \
		notmuch@notmuchmail.org
	public-inbox-index notmuch

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.mail.notmuch.general
	nntp://news.gmane.io/gmane.mail.notmuch.general


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git