Re: [PATCH 2/3] notmuch-mutt: support for messages that lack Message-ID headers
authorJani Nikula <jani@nikula.org>
Sat, 24 Jan 2015 14:59:16 +0000 (16:59 +0200)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:47:46 +0000 (14:47 -0700)
ce/6317416bd920906d0e0f25644d39f86f0edbe0 [new file with mode: 0644]

diff --git a/ce/6317416bd920906d0e0f25644d39f86f0edbe0 b/ce/6317416bd920906d0e0f25644d39f86f0edbe0
new file mode 100644 (file)
index 0000000..a8574b8
--- /dev/null
@@ -0,0 +1,174 @@
+Return-Path: <jani@nikula.org>\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 308ED431FCB\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Jan 2015 06:59:14 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 1.738\r
+X-Spam-Level: *\r
+X-Spam-Status: No, score=1.738 tagged_above=-999 required=5\r
+       tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_LOW=-0.7]\r
+       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 ugZr0UO0qINb for <notmuch@notmuchmail.org>;\r
+       Sat, 24 Jan 2015 06:59:08 -0800 (PST)\r
+Received: from mail-wg0-f42.google.com (mail-wg0-f42.google.com\r
+ [74.125.82.42])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ 9B5FD431FAE   for <notmuch@notmuchmail.org>; Sat, 24 Jan 2015 06:59:08 -0800\r
+ (PST)\r
+Received: by mail-wg0-f42.google.com with SMTP id x13so2264140wgg.1\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Jan 2015 06:59:05 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=1e100.net; s=20130820;\r
+       h=x-gm-message-state:from:to:cc:subject:in-reply-to:references\r
+       :user-agent:date:message-id:mime-version:content-type;\r
+       bh=b0rU/F6AF8BJxNe2rwNUZyH2GY1Ut/fPsdwt2Wmb73g=;\r
+       b=Y1/UM3cqJ36qJb7w8kBtezjsnnfiMWbYvxmm6FiiHOD4OXn1GZXIO6fEYmN2xhGop6\r
+       iTRUSCIIDs5swT6RyhkPD0Ev1sH52lmkmDR9qnUZq/aYLFW+Ngozqgv7O8dL8qHiPBdl\r
+       oONbkuN+eGGKU0qXb7lbsPelRx6raNp+6/BfY/cO/OBPX0xQZPcUWsBf7cWu16ZA3IcB\r
+       4CEZBk38gqPQtR66D78788j1dIzoTPa28O82oBodbUWLDjzjNAC6fg7oKsKkR08DAUzX\r
+       zq0wMTHvxJ18vS6TUcrz7t7fW8WWPYvOS5Jzi2nDZJAdMH2a/m5L+DtNg3KsOW5b5K1x\r
+       5eYA==\r
+X-Gm-Message-State:\r
+ ALoCoQn0tOqcunzBpigPPu6drAdJ451I+DsCaU5YaNzguKXOJWwR6i5bJ4iT+gGpcpui7omkW0PM\r
+X-Received: by 10.194.19.197 with SMTP id h5mr6107389wje.109.1422111545210;\r
+       Sat, 24 Jan 2015 06:59:05 -0800 (PST)\r
+Received: from localhost (mobile-internet-bcee98-87.dhcp.inet.fi.\r
+       [188.238.152.87]) by mx.google.com with ESMTPSA id\r
+       dz10sm6154906wib.17.2015.01.24.06.59.03\r
+       (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+       Sat, 24 Jan 2015 06:59:04 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Stefano Zacchiroli <zack@upsilon.cc>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 2/3] notmuch-mutt: support for messages that lack\r
+       Message-ID      headers\r
+In-Reply-To: <1422090701-19385-3-git-send-email-zack@upsilon.cc>\r
+References: <1422090701-19385-1-git-send-email-zack@upsilon.cc>\r
+       <1422090701-19385-3-git-send-email-zack@upsilon.cc>\r
+User-Agent: Notmuch/0.19+37~g290dc80 (http://notmuchmail.org) Emacs/24.4.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Sat, 24 Jan 2015 16:59:16 +0200\r
+Message-ID: <871tmkql6j.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\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 14:59:14 -0000\r
+\r
+On Sat, 24 Jan 2015, Stefano Zacchiroli <zack@upsilon.cc> wrote:\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
+As I said on IRC, I think this is a notmuch implementation detail, and\r
+we don't make any promises about always generating missing message-ids\r
+the same way. That said, I don't see any reason why we'd change this\r
+anytime soon, so the solution is probably good enough for now.\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
+I am not so sure this is a good idea however, see below.\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
+\r
+This doesn't take into account header folding or end of headers. There's\r
+probably a bunch of other things to consider in the relevant RFCs. I\r
+think you really should use Mail::Internet for the common case, and only\r
+fallback to generating the message-id when that fails.\r
+\r
+BR,\r
+Jani.\r
+\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
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r