From f03a315ab7c2f006481846761009eb43fa217517 Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Sun, 15 Feb 2015 13:39:08 +0100 Subject: [PATCH] [PATCH 3/3] notmuch-mutt: support for messages that lack Message-ID headers --- fd/1d96b8417635fe62c1a0c64de0213818f153fc | 144 ++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 fd/1d96b8417635fe62c1a0c64de0213818f153fc diff --git a/fd/1d96b8417635fe62c1a0c64de0213818f153fc b/fd/1d96b8417635fe62c1a0c64de0213818f153fc new file mode 100644 index 000000000..8c2cea678 --- /dev/null +++ b/fd/1d96b8417635fe62c1a0c64de0213818f153fc @@ -0,0 +1,144 @@ +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 B1000429E52 + for ; Sun, 15 Feb 2015 04:39:26 -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 xra-Ckl5x7Sk for ; + Sun, 15 Feb 2015 04:39:23 -0800 (PST) +Received: from upsilon.cc (upsilon.cc [178.32.142.91]) + by olra.theworths.org (Postfix) with ESMTP id A7E6B431FDB + for ; Sun, 15 Feb 2015 04:39:22 -0800 (PST) +Received: from timira.takhisis.invalid (unknown [78.194.69.54]) + by upsilon.cc (Postfix) with ESMTPSA id 91C9010E6B; + Sun, 15 Feb 2015 13:39:20 +0100 (CET) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=upsilon.cc; s=mail; + t=1424003960; bh=Est5Ya7UcbOQdLIWcVleB3ZNQtr1stGCiE/bwF671ls=; + h=From:To:Cc:Subject:Date:In-Reply-To:References:From; + b=a8gwLM+nHi0gx0TZSiLDpB3nKHwRIKxv1mhucrFZ+qIjcFIagfSYxzhFzqxln/O/c + D3qhOKJs96togZwn3pNoxpXQbtNUHJVTNxh8k3NXTKWgmg3y1yIMDrNkIpaaV6TQaV + sOx1A+WCDiyybr4ET80oSX7YoBPRM0S3mimwB9l8= +Received: by timira.takhisis.invalid (Postfix, from userid 1000) + id E5FDF600E0; Sun, 15 Feb 2015 13:39:19 +0100 (CET) +From: Stefano Zacchiroli +To: notmuch@notmuchmail.org +Subject: [PATCH 3/3] notmuch-mutt: support for messages that lack Message-ID + headers +Date: Sun, 15 Feb 2015 13:39:08 +0100 +Message-Id: <1424003948-17642-4-git-send-email-zack@upsilon.cc> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <1424003948-17642-1-git-send-email-zack@upsilon.cc> +References: + <1424003948-17642-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: Sun, 15 Feb 2015 12:39:27 -0000 + +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 accumulate header lines, +parse them to check for Message-ID, and fallback to SHA1 computation +if it is not present. + +Thanks to: +- Jan N. Klug for preliminary versions of this patch +- Tomi Ollila for suggesting an elegant implementation +--- + contrib/notmuch-mutt/README | 4 +++- + contrib/notmuch-mutt/notmuch-mutt | 30 +++++++++++++++++++++++++----- + 2 files changed, 28 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 6d4d60c..126cbf4 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($$$@) { +-- +2.1.4 + -- 2.26.2