X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=contrib%2Fnotmuch-mutt%2Fnotmuch-mutt;h=0e46a8c1b95e76163eed68694aa5a1a973c8b371;hp=4969e4be64c3f29140e25b97ee137947058cd8ca;hb=6a833a6e83865f6999707cc30768d07e1351c2cb;hpb=f3dc5be6f2c870ca9edf7d60a8c7b80984c37bbf diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt index 4969e4be..0e46a8c1 100755 --- a/contrib/notmuch-mutt/notmuch-mutt +++ b/contrib/notmuch-mutt/notmuch-mutt @@ -1,8 +1,8 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl # # notmuch-mutt - notmuch (of a) helper for Mutt # -# Copyright: © 2011-2012 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. @@ -13,11 +13,12 @@ use warnings; use File::Path; use Getopt::Long qw(:config no_getopt_compat); -use Mail::Internet; +use Mail::Header; use Mail::Box::Maildir; use Pod::Usage; use String::ShellQuote; use Term::ReadLine; +use Digest::SHA; my $xdg_cache_dir = "$ENV{HOME}/.cache"; @@ -49,7 +50,7 @@ sub search($$$) { empty_maildir($maildir); system("notmuch search --output=files $dup_option $query" . " | sed -e 's: :\\\\ :g'" - . " | xargs --no-run-if-empty ln -s -t $maildir/cur/"); + . " | xargs -r -I searchoutput ln -s searchoutput $maildir/cur/"); } sub prompt($$) { @@ -75,10 +76,29 @@ sub prompt($$) { } sub get_message_id() { - my $mail = Mail::Internet->new(\*STDIN); - my $mid = $mail->head->get("message-id") or return undef; - $mid =~ /^<(.*)>$/; # get message-id value - return $1; + my $mid = undef; + my @headers = (); + + while () { # collect header lines in @headers + push(@headers, $_); + last if $_ =~ /^$/; + } + my $head = Mail::Header->new(\@headers); + $mid = $head->get("message-id") or undef; + + if ($mid) { # Message-ID header found + $mid =~ /^<(.*)>$/; # extract message id + $mid = $1; + } else { # Message-ID header not found, synthesize a message id + # based on SHA1, as notmuch would do. See: + # https://git.notmuchmail.org/git/notmuch/blob/HEAD:/lib/sha1.c + my $sha = Digest::SHA->new(1); + $sha->add($_) foreach(@headers); + $sha->addfile(\*STDIN); + $mid = 'notmuch-sha1-' . $sha->hexdigest; + } + + return $mid; } sub search_action($$$@) {