unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Tomi Ollila <tomi.ollila@iki.fi>
To: notmuch@notmuchmail.org
Cc: tomi.ollila@iki.fi
Subject: [PATCH] notmuch-mutt: replace shell pipeline with internal pipe processing
Date: Mon, 27 Jul 2020 22:38:33 +0300	[thread overview]
Message-ID: <20200727193833.4654-1-tomi.ollila@iki.fi> (raw)

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

             reply	other threads:[~2020-07-27 19:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-27 19:38 Tomi Ollila [this message]
2020-08-11 17:36 ` [PATCH] notmuch-mutt: replace shell pipeline with internal pipe processing David Bremner
2020-08-12 23:45 ` 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=20200727193833.4654-1-tomi.ollila@iki.fi \
    --to=tomi.ollila@iki.fi \
    --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).