unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] notmuch-mutt: replace gnu sed and xargs with perl
@ 2012-04-12  0:29 Taylor Carpenter
  2012-04-12  7:07 ` Tomi Ollila
  0 siblings, 1 reply; 4+ messages in thread
From: Taylor Carpenter @ 2012-04-12  0:29 UTC (permalink / raw)
  To: notmuch

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.
---
 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

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

* Re: [PATCH] notmuch-mutt: replace gnu sed and xargs with perl
  2012-04-12  0:29 [PATCH] notmuch-mutt: replace gnu sed and xargs with perl Taylor Carpenter
@ 2012-04-12  7:07 ` Tomi Ollila
  2012-04-12 18:29   ` Taylor Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Tomi Ollila @ 2012-04-12  7:07 UTC (permalink / raw)
  To: Taylor Carpenter, notmuch

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@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@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

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

* Re: [PATCH] notmuch-mutt: replace gnu sed and xargs with perl
  2012-04-12  7:07 ` Tomi Ollila
@ 2012-04-12 18:29   ` Taylor Carpenter
  2012-04-12 18:49     ` Tomi Ollila
  0 siblings, 1 reply; 4+ messages in thread
From: Taylor Carpenter @ 2012-04-12 18:29 UTC (permalink / raw)
  To: Tomi Ollila; +Cc: notmuch

On Thu, Apr 12, 2012 at 02:07, Tomi Ollila <tomi.ollila@iki.fi> wrote:
> 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.
>> ---
> It is not too hard to read the filelist from pipe; Check the example
> I sent in id:"m2hawr4klm.fsf@guru.guru-group.fi"

Understood.


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

FYI, the current xargs version does not handle collisions either.

> 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...

How about pre-pending some unique text to the colliding file?

Regards,

Taylor

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

* Re: [PATCH] notmuch-mutt: replace gnu sed and xargs with perl
  2012-04-12 18:29   ` Taylor Carpenter
@ 2012-04-12 18:49     ` Tomi Ollila
  0 siblings, 0 replies; 4+ messages in thread
From: Tomi Ollila @ 2012-04-12 18:49 UTC (permalink / raw)
  To: Taylor Carpenter; +Cc: notmuch

On Thu, Apr 12 2012, Taylor Carpenter <taylor@codecafe.com> wrote:

> On Thu, Apr 12, 2012 at 02:07, Tomi Ollila <tomi.ollila@iki.fi> wrote:
>
>> Btw: what if there are same filenames in different directories that
>> match. With basename there will be collision.
>
> FYI, the current xargs version does not handle collisions either.

True -- so that is not strictly a requirement ;)

>> 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...
>
> How about pre-pending some unique text to the colliding file?

Anything goes -- the target filename could also be generated ...
like this:

    my $counter = 0;
    foreach(...) {
        chomp;
        my $target = sprintf("$maildir/cur/%08d", $counter++);
        symlink($_, $target);
    }    

i.e. target filename is just counter value.

> Regards,
>
> Taylor

Tomi

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

end of thread, other threads:[~2012-04-12 18:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-12  0:29 [PATCH] notmuch-mutt: replace gnu sed and xargs with perl Taylor Carpenter
2012-04-12  7:07 ` Tomi Ollila
2012-04-12 18:29   ` Taylor Carpenter
2012-04-12 18:49     ` Tomi Ollila

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).