[PATCH 2/3] notmuch-mutt: support for messages that lack Message-ID headers
authorStefano Zacchiroli <zack@upsilon.cc>
Sat, 24 Jan 2015 09:11:40 +0000 (10:11 +0100)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:47:45 +0000 (14:47 -0700)
b0/deff76f8242385ab88d300761cb488576ad726 [new file with mode: 0644]

diff --git a/b0/deff76f8242385ab88d300761cb488576ad726 b/b0/deff76f8242385ab88d300761cb488576ad726
new file mode 100644 (file)
index 0000000..ade8990
--- /dev/null
@@ -0,0 +1,136 @@
+Return-Path: <zack@upsilon.cc>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 46865431FD4\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Jan 2015 01:18:25 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 2.338\r
+X-Spam-Level: **\r
+X-Spam-Status: No, score=2.338 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       DNS_FROM_AHBL_RHSBL=2.438] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id ENn1IhqCx5NZ for <notmuch@notmuchmail.org>;\r
+       Sat, 24 Jan 2015 01:18:22 -0800 (PST)\r
+Received: from upsilon.cc (upsilon.cc [178.32.142.91])\r
+       by olra.theworths.org (Postfix) with ESMTP id C48B6431FCF\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Jan 2015 01:18:20 -0800 (PST)\r
+Received: from timira.takhisis.invalid (unknown [78.194.69.54])\r
+       by upsilon.cc (Postfix) with ESMTPSA id 63AC210DBA;\r
+       Sat, 24 Jan 2015 10:11:51 +0100 (CET)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=upsilon.cc; s=mail;\r
+       t=1422090711; bh=ZLCI7TBYgnypG9MMMG8qqQU7tO2KLxFsXcmij3ogoDU=;\r
+       h=From:To:Cc:Subject:Date:In-Reply-To:References:From;\r
+       b=foVkgTQrC47AZuzMIqd4GynFJWAqPv1XexqtR36wfFsqX15rS/JzqHXt5zQi7NsLL\r
+       QFrPUTWAmQ02lIbQ2ih2S5eG1gh6pdYphqczV6K04SpikKliYSh4eSEgWfhDglBesO\r
+       Fb/HPhnbJi1KXxB0sUYm7E1eJpzXXgMJEG1C5XZM=\r
+Received: by timira.takhisis.invalid (Postfix, from userid 1000)\r
+       id 41121600E1; Sat, 24 Jan 2015 10:11:50 +0100 (CET)\r
+From: Stefano Zacchiroli <zack@upsilon.cc>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/3] notmuch-mutt: support for messages that lack Message-ID\r
+       headers\r
+Date: Sat, 24 Jan 2015 10:11:40 +0100\r
+Message-Id: <1422090701-19385-3-git-send-email-zack@upsilon.cc>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1422090701-19385-1-git-send-email-zack@upsilon.cc>\r
+References: <1422090701-19385-1-git-send-email-zack@upsilon.cc>\r
+Cc: "Jan N. Klug" <jan.n.klug@rub.de>, Stefano Zacchiroli <zack@upsilon.cc>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 24 Jan 2015 09:18:25 -0000\r
+\r
+From: "Jan N. Klug" <jan.n.klug@rub.de>\r
+\r
+For those messages, compute a synthetic Message-ID based on the SHA1\r
+of the whole message, in the same way that notmuch would do. See:\r
+http://git.notmuchmail.org/git/notmuch/blob/HEAD:/lib/sha1.c\r
+\r
+To do the above, rewrite get_message_id() to scan the current message\r
+line by line, incrementally computing a SHA1. As a consequence, drop\r
+the dependency on Mail::Internet.\r
+\r
+Signed-off-by: Stefano Zacchiroli <zack@upsilon.cc>\r
+---\r
+ contrib/notmuch-mutt/README       |  4 ++--\r
+ contrib/notmuch-mutt/notmuch-mutt | 23 ++++++++++++++++++-----\r
+ 2 files changed, 20 insertions(+), 7 deletions(-)\r
+\r
+diff --git a/contrib/notmuch-mutt/README b/contrib/notmuch-mutt/README\r
+index c661447..0013ed0 100644\r
+--- a/contrib/notmuch-mutt/README\r
++++ b/contrib/notmuch-mutt/README\r
+@@ -33,10 +33,10 @@ Requirements\r
\r
+ To *run* notmuch-mutt you will need Perl with the following libraries:\r
\r
++- Digest::SHA <https://metacpan.org/release/Digest-SHA>\r
++  (Debian package: libdigest-sha-perl)\r
+ - Mail::Box <https://metacpan.org/pod/Mail::Box>\r
+   (Debian package: libmail-box-perl)\r
+-- Mail::Internet <https://metacpan.org/pod/Mail::Internet>\r
+-  (Debian package: libmailtools-perl)\r
+ - String::ShellQuote <https://metacpan.org/pod/String::ShellQuote>\r
+   (Debian package: libstring-shellquote-perl)\r
+ - Term::ReadLine::Gnu <https://metacpan.org/pod/Term::ReadLine::Gnu>\r
+diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt\r
+index 4969e4b..4d30b0b 100755\r
+--- a/contrib/notmuch-mutt/notmuch-mutt\r
++++ b/contrib/notmuch-mutt/notmuch-mutt\r
+@@ -13,11 +13,11 @@ use warnings;\r
\r
+ use File::Path;\r
+ use Getopt::Long qw(:config no_getopt_compat);\r
+-use Mail::Internet;\r
+ use Mail::Box::Maildir;\r
+ use Pod::Usage;\r
+ use String::ShellQuote;\r
+ use Term::ReadLine;\r
++use Digest::SHA;\r
\r
\r
+ my $xdg_cache_dir = "$ENV{HOME}/.cache";\r
+@@ -75,10 +75,23 @@ sub prompt($$) {\r
+ }\r
\r
+ sub get_message_id() {\r
+-    my $mail = Mail::Internet->new(\*STDIN);\r
+-    my $mid = $mail->head->get("message-id") or return undef;\r
+-    $mid =~ /^<(.*)>$/;       # get message-id value\r
+-    return $1;\r
++    my $mid = undef;\r
++    my $sha = Digest::SHA->new(1);  # SHA1 hashing\r
++\r
++    while(<STDIN>) {  # scan message line by line, looking for mid\r
++        if ($_ =~ /^Message-ID:\s*<(.*)>$/i) {\r
++          $mid = $1;\r
++          last;  # message-id found, abort scan\r
++        }\r
++      $sha->add($_);  # update hash\r
++    }\r
++\r
++    # Generate message-id from hash if none was found, in the same way\r
++    # that notmuch would do.\r
++    # See: http://git.notmuchmail.org/git/notmuch/blob/HEAD:/lib/sha1.c\r
++    $mid ||= "notmuch-sha1-".$sha->hexdigest;\r
++\r
++    return $mid;\r
+ }\r
\r
+ sub search_action($$$@) {\r
+-- \r
+2.1.4\r
+\r