[PATCH] Add support for missing Messsage-ID header

2015-01-26 Thread Jan N. Klug
---
 contrib/notmuch-mutt/notmuch-mutt | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/contrib/notmuch-mutt/notmuch-mutt 
b/contrib/notmuch-mutt/notmuch-mutt
index 4969e4b..b9882fd 100755
--- a/contrib/notmuch-mutt/notmuch-mutt
+++ b/contrib/notmuch-mutt/notmuch-mutt
@@ -18,7 +18,7 @@ use Mail::Box::Maildir;
 use Pod::Usage;
 use String::ShellQuote;
 use Term::ReadLine;
-
+use Digest::SHA qw (sha1_hex);

 my $xdg_cache_dir = "$ENV{HOME}/.cache";
 $xdg_cache_dir = $ENV{XDG_CACHE_HOME} if $ENV{XDG_CACHE_HOME};
@@ -75,10 +75,14 @@ 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 $mail = Mail::Internet->new(\*STDIN, Modify => 0);
+my $mid = $mail->head->get("message-id");
+if (defined $mid) { # get message-id value
+  $mid = $1 if ($mid =~ /^<(.*)>$/);   
+} else { # generate synthetic message-id
+  $mid = "notmuch-sha1-".sha1_hex($mail->as_string());
+}
+return $mid;
 }

 sub search_action($$$@) {
-- 
2.1.4



[PATCH] Add support for missing Messsage-ID header

2015-01-26 Thread Jan N. Klug
---
 contrib/notmuch-mutt/notmuch-mutt | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/contrib/notmuch-mutt/notmuch-mutt 
b/contrib/notmuch-mutt/notmuch-mutt
index 4969e4b..b9882fd 100755
--- a/contrib/notmuch-mutt/notmuch-mutt
+++ b/contrib/notmuch-mutt/notmuch-mutt
@@ -18,7 +18,7 @@ use Mail::Box::Maildir;
 use Pod::Usage;
 use String::ShellQuote;
 use Term::ReadLine;
-
+use Digest::SHA qw (sha1_hex);
 
 my $xdg_cache_dir = $ENV{HOME}/.cache;
 $xdg_cache_dir = $ENV{XDG_CACHE_HOME} if $ENV{XDG_CACHE_HOME};
@@ -75,10 +75,14 @@ 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 $mail = Mail::Internet-new(\*STDIN, Modify = 0);
+my $mid = $mail-head-get(message-id);
+if (defined $mid) { # get message-id value
+  $mid = $1 if ($mid =~ /^(.*)$/);   
+} else { # generate synthetic message-id
+  $mid = notmuch-sha1-.sha1_hex($mail-as_string());
+}
+return $mid;
 }
 
 sub search_action($$$@) {
-- 
2.1.4

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


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

2015-01-24 Thread Jan N. Klug
On Sat, Jan 24, 2015 at 04:21:06PM +0100, Stefano Zacchiroli wrote:
> On Sat, Jan 24, 2015 at 04:59:16PM +0200, Jani Nikula wrote:
> > On Sat, 24 Jan 2015, Stefano Zacchiroli  wrote:
> > > 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.
> [...]
> But I didn't think of header folding, and you're absolutely correct in
> saying that might be a problem.

I disagree. I do not think that header folding is a problem here. RFC
5322 and RFC 2822 state that FWS in the message-id are not allowed (as
opposed to In-Reply: and other headers, where FWS may occur between, but
not inside message-ids).

Folded lines that start with "Message-Id:" might occur, the
regex-pattern used in the patch will not match those lines. 

As far as I have looked in the Mail::Internet sources, further checking of the
correctness of the message-id does not occur, so I do not see any
advantage over the proposed solution. 

> Jan: do you agree with using Mail::Header->new and fall back to
> line-by-line hasing only in case Message-ID is not found? If so, having
> an updated patch based on the one I've posted here would be awesome! If
> you cannot do that just let me know and I'll get to it, eventually :).

I can look into that, but I cannot promise to have it ready in the next
days.

Regards,

Jan
--
Jan N. Klug, Gelsenkirchen


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

2015-01-24 Thread Jan N. Klug
On Sat, Jan 24, 2015 at 04:21:06PM +0100, Stefano Zacchiroli wrote:
 On Sat, Jan 24, 2015 at 04:59:16PM +0200, Jani Nikula wrote:
  On Sat, 24 Jan 2015, Stefano Zacchiroli z...@upsilon.cc wrote:
   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.
 [...]
 But I didn't think of header folding, and you're absolutely correct in
 saying that might be a problem.

I disagree. I do not think that header folding is a problem here. RFC
5322 and RFC 2822 state that FWS in the message-id are not allowed (as
opposed to In-Reply: and other headers, where FWS may occur between, but
not inside message-ids).

Folded lines that start with Message-Id: might occur, the
regex-pattern used in the patch will not match those lines. 

As far as I have looked in the Mail::Internet sources, further checking of the
correctness of the message-id does not occur, so I do not see any
advantage over the proposed solution. 

 Jan: do you agree with using Mail::Header-new and fall back to
 line-by-line hasing only in case Message-ID is not found? If so, having
 an updated patch based on the one I've posted here would be awesome! If
 you cannot do that just let me know and I'll get to it, eventually :).

I can look into that, but I cannot promise to have it ready in the next
days.

Regards,

Jan
--
Jan N. Klug, Gelsenkirchen
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch