Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 184C3431FC9 for ; Mon, 9 Feb 2015 01:41:47 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 2.338 X-Spam-Level: ** X-Spam-Status: No, score=2.338 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DNS_FROM_AHBL_RHSBL=2.438] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KdBz1qqFDXv1 for ; Mon, 9 Feb 2015 01:41:43 -0800 (PST) Received: from upsilon.cc (upsilon.cc [178.32.142.91]) by olra.theworths.org (Postfix) with ESMTP id 01A98431FCF for ; Mon, 9 Feb 2015 01:41:42 -0800 (PST) Received: from timira.takhisis.invalid (maths.r-prg.net.univ-paris7.fr [81.194.27.158]) by upsilon.cc (Postfix) with ESMTPSA id 3027710E51; Mon, 9 Feb 2015 10:41:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=upsilon.cc; s=mail; t=1423474902; bh=RgHHPbGpmwrC43KVLpMI0KL6u7qnoOE81WWVapPJEks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hD9Mm3RoW2N9HRoSUxzajfz4DA1odJMp4dkx37MqniN0N6CdL36P0NfcFAthJ7By8 hU7pttveu4lZK7/jcyKt8wURYBuWUcY7xtamJhEAFxO4tZtdsytsgsgOlTx74HxEDX pmEhk3TntLM6ymfDLRSIykSZy6JoXWHOq8Qv9/iQ= Received: by timira.takhisis.invalid (Postfix, from userid 1000) id BA0A9600E1; Mon, 9 Feb 2015 10:41:41 +0100 (CET) From: Stefano Zacchiroli To: notmuch@notmuchmail.org Subject: [PATCH 2/2] notmuch-mutt: support for messages that lack Message-ID headers Date: Mon, 9 Feb 2015 10:41:30 +0100 Message-Id: <1423474890-16972-3-git-send-email-zack@upsilon.cc> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1423474890-16972-1-git-send-email-zack@upsilon.cc> References: <1423474890-16972-1-git-send-email-zack@upsilon.cc> Cc: zack@upsilon.cc X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Feb 2015 09:41:47 -0000 From: "Jan N. Klug" For those messages, compute a synthetic Message-ID based on the SHA1 of the whole message, in the same way that notmuch would do. See: http://git.notmuchmail.org/git/notmuch/blob/HEAD:/lib/sha1.c To do the above, rewrite get_message_id() to scan the current message line by line, incrementally computing a SHA1. If a Message-ID is found the SHA1 computation will be aborted; otherwise used for the synthetic Message-ID. Signed-off-by: Stefano Zacchiroli --- contrib/notmuch-mutt/README | 4 +++- contrib/notmuch-mutt/notmuch-mutt | 33 ++++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/contrib/notmuch-mutt/README b/contrib/notmuch-mutt/README index c661447..9c3379e 100644 --- a/contrib/notmuch-mutt/README +++ b/contrib/notmuch-mutt/README @@ -33,9 +33,11 @@ Requirements To *run* notmuch-mutt you will need Perl with the following libraries: +- Digest::SHA + (Debian package: libdigest-sha-perl) - Mail::Box (Debian package: libmail-box-perl) -- Mail::Internet +- Mail::Header (Debian package: libmailtools-perl) - String::ShellQuote (Debian package: libstring-shellquote-perl) diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt index 4969e4b..84af140 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,32 @@ 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 $in_header = 1; + my @raw_header = (); + my $sha = Digest::SHA->new(1); # SHA1 hash of the whole mail + + while () { # compute SHA1 as we go + push(@raw_header, $_) if $in_header; # cache header lines + if ($_ =~ /^$/) { # end of header, parse it and look for Message-ID + $in_header = 0; + my $head = Mail::Header->new(\@raw_header); + $mid = $head->get("message-id") or undef; + if ($mid) { + $mid =~ /^<(.*)>$/; # get message-id value + $mid = $1; + last; # stop hashing + } + } + $sha->add($_); # update hash + } + + # If no message-id was found, generate one-id in the same way that + # notmuch would do. + # See: http://git.notmuchmail.org/git/notmuch/blob/HEAD:/lib/sha1.c + $mid ||= "notmuch-sha1-".$sha->hexdigest; + + return $mid; } sub search_action($$$@) { -- 2.1.4