From 345aa94c517852ac755426e0056fa32e4b5da164 Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Sat, 24 Jan 2015 10:11:40 +0100 Subject: [PATCH] [PATCH 2/3] notmuch-mutt: support for messages that lack Message-ID headers --- b0/deff76f8242385ab88d300761cb488576ad726 | 136 ++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 b0/deff76f8242385ab88d300761cb488576ad726 diff --git a/b0/deff76f8242385ab88d300761cb488576ad726 b/b0/deff76f8242385ab88d300761cb488576ad726 new file mode 100644 index 000000000..ade899061 --- /dev/null +++ b/b0/deff76f8242385ab88d300761cb488576ad726 @@ -0,0 +1,136 @@ +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 46865431FD4 + for ; Sat, 24 Jan 2015 01:18:25 -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 ENn1IhqCx5NZ for ; + Sat, 24 Jan 2015 01:18:22 -0800 (PST) +Received: from upsilon.cc (upsilon.cc [178.32.142.91]) + by olra.theworths.org (Postfix) with ESMTP id C48B6431FCF + for ; Sat, 24 Jan 2015 01:18:20 -0800 (PST) +Received: from timira.takhisis.invalid (unknown [78.194.69.54]) + by upsilon.cc (Postfix) with ESMTPSA id 63AC210DBA; + Sat, 24 Jan 2015 10:11:51 +0100 (CET) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=upsilon.cc; s=mail; + t=1422090711; bh=ZLCI7TBYgnypG9MMMG8qqQU7tO2KLxFsXcmij3ogoDU=; + h=From:To:Cc:Subject:Date:In-Reply-To:References:From; + b=foVkgTQrC47AZuzMIqd4GynFJWAqPv1XexqtR36wfFsqX15rS/JzqHXt5zQi7NsLL + QFrPUTWAmQ02lIbQ2ih2S5eG1gh6pdYphqczV6K04SpikKliYSh4eSEgWfhDglBesO + Fb/HPhnbJi1KXxB0sUYm7E1eJpzXXgMJEG1C5XZM= +Received: by timira.takhisis.invalid (Postfix, from userid 1000) + id 41121600E1; Sat, 24 Jan 2015 10:11:50 +0100 (CET) +From: Stefano Zacchiroli +To: notmuch@notmuchmail.org +Subject: [PATCH 2/3] notmuch-mutt: support for messages that lack Message-ID + headers +Date: Sat, 24 Jan 2015 10:11:40 +0100 +Message-Id: <1422090701-19385-3-git-send-email-zack@upsilon.cc> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <1422090701-19385-1-git-send-email-zack@upsilon.cc> +References: <1422090701-19385-1-git-send-email-zack@upsilon.cc> +Cc: "Jan N. Klug" , Stefano Zacchiroli +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: Sat, 24 Jan 2015 09:18:25 -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. As a consequence, drop +the dependency on Mail::Internet. + +Signed-off-by: Stefano Zacchiroli +--- + contrib/notmuch-mutt/README | 4 ++-- + contrib/notmuch-mutt/notmuch-mutt | 23 ++++++++++++++++++----- + 2 files changed, 20 insertions(+), 7 deletions(-) + +diff --git a/contrib/notmuch-mutt/README b/contrib/notmuch-mutt/README +index c661447..0013ed0 100644 +--- a/contrib/notmuch-mutt/README ++++ b/contrib/notmuch-mutt/README +@@ -33,10 +33,10 @@ 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 +- (Debian package: libmailtools-perl) + - String::ShellQuote + (Debian package: libstring-shellquote-perl) + - Term::ReadLine::Gnu +diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt +index 4969e4b..4d30b0b 100755 +--- a/contrib/notmuch-mutt/notmuch-mutt ++++ b/contrib/notmuch-mutt/notmuch-mutt +@@ -13,11 +13,11 @@ use warnings; + + use File::Path; + use Getopt::Long qw(:config no_getopt_compat); +-use Mail::Internet; + 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 +75,23 @@ 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 $sha = Digest::SHA->new(1); # SHA1 hashing ++ ++ while() { # scan message line by line, looking for mid ++ if ($_ =~ /^Message-ID:\s*<(.*)>$/i) { ++ $mid = $1; ++ last; # message-id found, abort scan ++ } ++ $sha->add($_); # update hash ++ } ++ ++ # Generate message-id from hash if none was found, 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 + -- 2.26.2