[PATCH] notmuch-mutt: replace gnu sed and xargs with perl

Tomi Ollila tomi.ollila at iki.fi
Thu Apr 12 00:07:54 PDT 2012


On Thu, Apr 12 2012, Taylor Carpenter wrote:

> External software dependencies removed: sed and xargs.
>
> Sed shell escaping is handled automatically with perl symlink function.
>
> The xargs usage is specific to gnu xargs (fails on bsd xargs, etc).
>
> NOTE: The current query pulls the list of files into an array all at
> once.  The larger the list the more memory used.
> ---

-1

It is not too hard to read the filelist from pipe; Check the example
I sent in id:"m2hawr4klm.fsf at guru.guru-group.fi"


Btw: what if there are same filenames in different directories that
match. With basename there will be collision. Alternatives:

* instead of basename convert '/':s to '_':s
* take md5 or sha1 sum of the filename
* take md5 or sha1 sum of dirname of the filename and concatenate...

Tomi

>  contrib/notmuch-mutt/notmuch-mutt |    9 ++++++---
>  1 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt
> index 424f9a3..c995022 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::Internet;
>  use Mail::Box::Maildir;
> @@ -41,9 +42,11 @@ sub search($$) {
>      $query = shell_quote($query);
>  
>      empty_maildir($maildir);
> -    system("notmuch search --output=files $query"
> -	   . " | sed -e 's: :\\\\ :g'"
> -	   . " | xargs --no-run-if-empty ln -s -t $maildir/cur/");
> +    my @filelist = `notmuch search --output=files $query`;
> +    foreach(@filelist) {
> +        chomp;
> +        symlink($_, "$maildir/cur/" . basename($_));
> +    }
>  }
>  
>  sub prompt($$) {
> -- 
> 1.7.7.4
>
> _______________________________________________
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch


More information about the notmuch mailing list