[PATCH 11/12] lib/message: check message data_map for header
    David Bremner 
    david at tethera.net
       
    Fri Jun 22 18:42:46 PDT 2018
    
    
  
The will allow the indexing process to override the values in the
files. This is potentially useful for encrypted headers, or in
resolving duplicate files for the same message(-id).
---
 lib/message.cc | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/lib/message.cc b/lib/message.cc
index f59f0a5c..c3c71fd4 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -552,11 +552,30 @@ _notmuch_message_get_header_from_xapian (notmuch_message_t *message,
     return NULL;
 }
 
+static const char *
+_notmuch_message_get_header_from_data (notmuch_message_t *message, const char *header) {
+    _notmuch_message_ensure_data_map (message);
+
+    if (! (message->notmuch->features & NOTMUCH_FEATURE_MESSAGE_DATA))
+	return NULL;
+
+    const char *key = talloc_asprintf (message->data_map, "header.%s", header);
+
+    if (! key)
+	return NULL;
+
+    return _notmuch_string_map_get (message->data_map, key);
+}
+
 const char *
 notmuch_message_get_header (notmuch_message_t *message, const char *header)
 {
-    Xapian::valueno slot = Xapian::BAD_VALUENO;
+    /* Have we explicitly chosen / set this header */
+    const char *value = _notmuch_message_get_header_from_data (message, header);
+    if (value)
+	return value;
 
+    Xapian::valueno slot = Xapian::BAD_VALUENO;
     /* Fetch header from the appropriate xapian value field if
      * available */
     if (strcasecmp (header, "from") == 0)
-- 
2.17.1
    
    
More information about the notmuch
mailing list