[PATCH 3/3] notmuch-mutt: support for messages that lack Message-ID headers
authorStefano Zacchiroli <zack@upsilon.cc>
Sun, 15 Feb 2015 12:39:08 +0000 (13:39 +0100)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:48:03 +0000 (14:48 -0700)
fd/1d96b8417635fe62c1a0c64de0213818f153fc [new file with mode: 0644]

diff --git a/fd/1d96b8417635fe62c1a0c64de0213818f153fc b/fd/1d96b8417635fe62c1a0c64de0213818f153fc
new file mode 100644 (file)
index 0000000..8c2cea6
--- /dev/null
@@ -0,0 +1,144 @@
+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 B1000429E52\r
+       for <notmuch@notmuchmail.org>; Sun, 15 Feb 2015 04:39:26 -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 xra-Ckl5x7Sk for <notmuch@notmuchmail.org>;\r
+       Sun, 15 Feb 2015 04:39:23 -0800 (PST)\r
+Received: from upsilon.cc (upsilon.cc [178.32.142.91])\r
+       by olra.theworths.org (Postfix) with ESMTP id A7E6B431FDB\r
+       for <notmuch@notmuchmail.org>; Sun, 15 Feb 2015 04:39:22 -0800 (PST)\r
+Received: from timira.takhisis.invalid (unknown [78.194.69.54])\r
+       by upsilon.cc (Postfix) with ESMTPSA id 91C9010E6B;\r
+       Sun, 15 Feb 2015 13:39:20 +0100 (CET)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=upsilon.cc; s=mail;\r
+       t=1424003960; bh=Est5Ya7UcbOQdLIWcVleB3ZNQtr1stGCiE/bwF671ls=;\r
+       h=From:To:Cc:Subject:Date:In-Reply-To:References:From;\r
+       b=a8gwLM+nHi0gx0TZSiLDpB3nKHwRIKxv1mhucrFZ+qIjcFIagfSYxzhFzqxln/O/c\r
+       D3qhOKJs96togZwn3pNoxpXQbtNUHJVTNxh8k3NXTKWgmg3y1yIMDrNkIpaaV6TQaV\r
+       sOx1A+WCDiyybr4ET80oSX7YoBPRM0S3mimwB9l8=\r
+Received: by timira.takhisis.invalid (Postfix, from userid 1000)\r
+       id E5FDF600E0; Sun, 15 Feb 2015 13:39:19 +0100 (CET)\r
+From: Stefano Zacchiroli <zack@upsilon.cc>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/3] notmuch-mutt: support for messages that lack Message-ID\r
+       headers\r
+Date: Sun, 15 Feb 2015 13:39:08 +0100\r
+Message-Id: <1424003948-17642-4-git-send-email-zack@upsilon.cc>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1424003948-17642-1-git-send-email-zack@upsilon.cc>\r
+References: <m2twyvyx41.fsf@guru.guru-group.fi>\r
+       <1424003948-17642-1-git-send-email-zack@upsilon.cc>\r
+Cc: 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: Sun, 15 Feb 2015 12:39:27 -0000\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 accumulate header lines,\r
+parse them to check for Message-ID, and fallback to SHA1 computation\r
+if it is not present.\r
+\r
+Thanks to:\r
+- Jan N. Klug for preliminary versions of this patch\r
+- Tomi Ollila for suggesting an elegant implementation\r
+---\r
+ contrib/notmuch-mutt/README       |  4 +++-\r
+ contrib/notmuch-mutt/notmuch-mutt | 30 +++++++++++++++++++++++++-----\r
+ 2 files changed, 28 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/contrib/notmuch-mutt/README b/contrib/notmuch-mutt/README\r
+index c661447..9c3379e 100644\r
+--- a/contrib/notmuch-mutt/README\r
++++ b/contrib/notmuch-mutt/README\r
+@@ -33,9 +33,11 @@ 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
++- Mail::Header <https://metacpan.org/pod/Mail::Header>\r
+   (Debian package: libmailtools-perl)\r
+ - String::ShellQuote <https://metacpan.org/pod/String::ShellQuote>\r
+   (Debian package: libstring-shellquote-perl)\r
+diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt\r
+index 6d4d60c..126cbf4 100755\r
+--- a/contrib/notmuch-mutt/notmuch-mutt\r
++++ b/contrib/notmuch-mutt/notmuch-mutt\r
+@@ -13,11 +13,12 @@ use warnings;\r
\r
+ use File::Path;\r
+ use Getopt::Long qw(:config no_getopt_compat);\r
+-use Mail::Internet;\r
++use Mail::Header;\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 +76,29 @@ 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 @headers = ();\r
++\r
++    while (<STDIN>) {  # collect header lines in @headers\r
++      push(@headers, $_);\r
++      last if $_ =~ /^$/;\r
++    }\r
++    my $head = Mail::Header->new(\@headers);\r
++    $mid = $head->get("message-id") or undef;\r
++\r
++    if ($mid) {  # Message-ID header found\r
++      $mid =~ /^<(.*)>$/;  # extract message id\r
++      $mid = $1;\r
++    } else {  # Message-ID header not found, synthesize a message id\r
++            # based on SHA1, as notmuch would do.  See:\r
++            # http://git.notmuchmail.org/git/notmuch/blob/HEAD:/lib/sha1.c\r
++      my $sha = Digest::SHA->new(1);\r
++      $sha->add($_) foreach(@headers);\r
++      $sha->addfile(\*STDIN);\r
++      $mid = 'notmuch-sha1-' . $sha->hexdigest;\r
++    }\r
++\r
++    return $mid;\r
+ }\r
\r
+ sub search_action($$$@) {\r
+-- \r
+2.1.4\r
+\r