In a later commit, we will introduce another layer of data structure
for headers. To keep the resulting function size down, factor out the
database access.
---
 lib/message.cc | 41 ++++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 17 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index bf597bc5..f59f0a5c 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -529,6 +529,29 @@ _notmuch_message_ensure_message_file (notmuch_message_t 
*message)
        notmuch_message_get_database (message), message, filename);
 }
 
+static const char *
+_notmuch_message_get_header_from_xapian (notmuch_message_t *message,
+                                Xapian::valueno slot)
+{
+    try {
+       std::string value = message->doc.get_value (slot);
+
+       /* If we have NOTMUCH_FEATURE_FROM_SUBJECT_ID_VALUES, then
+        * empty values indicate empty headers.  If we don't, then
+        * it could just mean we didn't record the header. */
+       if ((message->notmuch->features &
+            NOTMUCH_FEATURE_FROM_SUBJECT_ID_VALUES) ||
+           ! value.empty())
+           return talloc_strdup (message, value.c_str ());
+
+    } catch (Xapian::Error &error) {
+       _notmuch_database_log(notmuch_message_get_database (message), "A Xapian 
exception occurred when reading header: %s\n",
+                             error.get_msg().c_str());
+       message->notmuch->exception_reported = true;
+    }
+    return NULL;
+}
+
 const char *
 notmuch_message_get_header (notmuch_message_t *message, const char *header)
 {
@@ -544,23 +567,7 @@ notmuch_message_get_header (notmuch_message_t *message, 
const char *header)
        slot = NOTMUCH_VALUE_MESSAGE_ID;
 
     if (slot != Xapian::BAD_VALUENO) {
-       try {
-           std::string value = message->doc.get_value (slot);
-
-           /* If we have NOTMUCH_FEATURE_FROM_SUBJECT_ID_VALUES, then
-            * empty values indicate empty headers.  If we don't, then
-            * it could just mean we didn't record the header. */
-           if ((message->notmuch->features &
-                NOTMUCH_FEATURE_FROM_SUBJECT_ID_VALUES) ||
-               ! value.empty())
-               return talloc_strdup (message, value.c_str ());
-
-       } catch (Xapian::Error &error) {
-           _notmuch_database_log(notmuch_message_get_database (message), "A 
Xapian exception occurred when reading header: %s\n",
-                    error.get_msg().c_str());
-           message->notmuch->exception_reported = true;
-           return NULL;
-       }
+       return _notmuch_message_get_header_from_xapian (message, slot);
     }
 
     /* Otherwise fall back to parsing the file */
-- 
2.17.1

_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch

Reply via email to