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 5772D431FC2 for ; Mon, 9 Feb 2015 06:32:28 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 2.438 X-Spam-Level: ** X-Spam-Status: No, score=2.438 tagged_above=-999 required=5 tests=[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 aGDFXdGqY+vX for ; Mon, 9 Feb 2015 06:32:23 -0800 (PST) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by olra.theworths.org (Postfix) with ESMTP id 03BA8431FAF for ; Mon, 9 Feb 2015 06:32:22 -0800 (PST) Received: from guru.guru-group.fi (localhost [IPv6:::1]) by guru.guru-group.fi (Postfix) with ESMTP id 010B2100051; Mon, 9 Feb 2015 16:31:58 +0200 (EET) From: Tomi Ollila To: Stefano Zacchiroli , notmuch@notmuchmail.org Subject: Re: [PATCH 2/2] notmuch-mutt: support for messages that lack Message-ID headers In-Reply-To: <1423474890-16972-3-git-send-email-zack@upsilon.cc> References: <1423474890-16972-1-git-send-email-zack@upsilon.cc> <1423474890-16972-3-git-send-email-zack@upsilon.cc> User-Agent: Notmuch/0.19+53~gb45d2f9 (http://notmuchmail.org) Emacs/24.3.1 (x86_64-unknown-linux-gnu) X-Face: HhBM'cA~ MIME-Version: 1.0 Content-Type: text/plain 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: Mon, 09 Feb 2015 14:32:28 -0000 On Mon, Feb 09 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 > > To do the above, rewrite get_message_id() to scan the current message > line by line, incrementally computing a SHA1. If a Message-ID is found > the SHA1 computation will be aborted; otherwise used for the synthetic > Message-ID. I'd suggest the (something like) following way: First loop through headers, push lines to the array. check for Message-Id (using Mail::Header): if found, return it else message id not found: my $sha = Digest::SHA->new(1); $sha->add($_) foreach(@raw_header); $sha->addfile(\*STDIN); return 'notmuch-sha1-' . $sha->hexdigest; (BTW: the implementation in the patch (below) would check for message-id in @raw_header every time mail has an empty line ?) Tomi > > Signed-off-by: Stefano Zacchiroli > --- > contrib/notmuch-mutt/README | 4 +++- > contrib/notmuch-mutt/notmuch-mutt | 33 ++++++++++++++++++++++++++++----- > 2 files changed, 31 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 4969e4b..84af140 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,32 @@ 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 $in_header = 1; > + my @raw_header = (); > + my $sha = Digest::SHA->new(1); # SHA1 hash of the whole mail > + > + while () { # compute SHA1 as we go > + push(@raw_header, $_) if $in_header; # cache header lines > + if ($_ =~ /^$/) { # end of header, parse it and look for Message-ID > + $in_header = 0; > + my $head = Mail::Header->new(\@raw_header); > + $mid = $head->get("message-id") or undef; > + if ($mid) { > + $mid =~ /^<(.*)>$/; # get message-id value > + $mid = $1; > + last; # stop hashing > + } > + } > + $sha->add($_); # update hash > + } > + > + # If no message-id was found, generate one-id 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