diff --git a/lib/database.cc b/lib/database.cc index 7f8a830..d30c1b0 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -1698,7 +1698,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch, goto DONE; date = notmuch_message_file_get_header (message_file, "date"); - _notmuch_message_set_date (message, date); + _notmuch_message_set_header_values (message, date, from, subject); _notmuch_message_index_file (message, filename); } else { diff --git a/lib/message.cc b/lib/message.cc index e8cf8d9..2a76dc1 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -414,6 +414,27 @@ _notmuch_message_ensure_message_file (notmuch_message_t *message) const char * notmuch_message_get_header (notmuch_message_t *message, const char *header) { + std::string value; + + // fetch header from the appropriate xapian value field if available + if (strcmp(header,"from") == 0) + value=message->doc.get_value(NOTMUCH_VALUE_FROM); + else if (strcmp(header,"subject") == 0) + value=message->doc.get_value (NOTMUCH_VALUE_SUBJECT); + else if (strcmp(header,"message-id") == 0) + value=message->doc.get_value (NOTMUCH_VALUE_MESSAGE_ID); + + if (!value.empty()) { + // empty headers are encoded as a single space because xapian + // doesn't seem to differentiat between unset and empty value + // fields + if (value == " ") + return ""; + else + return talloc_strdup (message, value.c_str ()); + } + + // otherwise fall back to parsing the file _notmuch_message_ensure_message_file (message); if (message->message_file == NULL) return NULL; @@ -771,8 +792,10 @@ notmuch_message_set_author (notmuch_message_t *message, } void -_notmuch_message_set_date (notmuch_message_t *message, - const char *date) +_notmuch_message_set_header_values (notmuch_message_t *message, + const char *date, + const char *from, + const char *subject) { time_t time_value; @@ -785,6 +808,9 @@ _notmuch_message_set_date (notmuch_message_t *message, message->doc.add_value (NOTMUCH_VALUE_TIMESTAMP, Xapian::sortable_serialise (time_value)); + message->doc.add_value (NOTMUCH_VALUE_FROM, from); + // empty subject is encoded as a single space + message->doc.add_value (NOTMUCH_VALUE_SUBJECT, (*subject==0) ? " " : subject); } /* Synchronize changes made to message->doc out into the database. */ diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index 0856751..ed3d32d 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -105,7 +105,9 @@ _internal_error (const char *format, ...) PRINTF_ATTRIBUTE (1, 2); typedef enum { NOTMUCH_VALUE_TIMESTAMP = 0, - NOTMUCH_VALUE_MESSAGE_ID + NOTMUCH_VALUE_MESSAGE_ID, + NOTMUCH_VALUE_FROM, + NOTMUCH_VALUE_SUBJECT } notmuch_value_t; /* Xapian (with flint backend) complains if we provide a term longer @@ -281,9 +283,10 @@ void _notmuch_message_ensure_thread_id (notmuch_message_t *message); void -_notmuch_message_set_date (notmuch_message_t *message, - const char *date); - +_notmuch_message_set_header_values (notmuch_message_t *message, + const char *date, + const char *from, + const char *subject); void _notmuch_message_sync (notmuch_message_t *message);