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