X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=contrib%2Fnotmuch-mutt%2Fnotmuch-mutt;h=126cbf4444da0cf0585b3aceb696075fab57d18e;hp=6d4d60c74cf870dc4797993e21a46200a51a70d9;hb=1722ea2c95865cb20cc2578894eca2cdaddc1d7a;hpb=02b554c89616154cbec153cb3938d43d51aae5ad diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt index 6d4d60c7..126cbf44 100755 --- a/contrib/notmuch-mutt/notmuch-mutt +++ b/contrib/notmuch-mutt/notmuch-mutt @@ -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"; @@ -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: + # http://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($$$@) {