[PATCH] Add support for missing Messsage-ID header

Jan N. Klug jan.n.klug at rub.de
Mon Jan 26 03:04:48 PST 2015


---
 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



More information about the notmuch mailing list