[PATCH 2/3] notmuch-mutt: support for messages that lack Message-ID headers

Jani Nikula jani at nikula.org
Sat Jan 24 06:59:16 PST 2015


On Sat, 24 Jan 2015, Stefano Zacchiroli <zack at upsilon.cc> wrote:
> From: "Jan N. Klug" <jan.n.klug at rub.de>
>
> 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 <zack at upsilon.cc>
> ---
>  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 <https://metacpan.org/release/Digest-SHA>
> +  (Debian package: libdigest-sha-perl)
>  - Mail::Box <https://metacpan.org/pod/Mail::Box>
>    (Debian package: libmail-box-perl)
> -- Mail::Internet <https://metacpan.org/pod/Mail::Internet>
> -  (Debian package: libmailtools-perl)
>  - String::ShellQuote <https://metacpan.org/pod/String::ShellQuote>
>    (Debian package: libstring-shellquote-perl)
>  - Term::ReadLine::Gnu <https://metacpan.org/pod/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(<STDIN>) {  # 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 at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch


More information about the notmuch mailing list