Austin Clements <[email protected]> writes:
> I wonder if a better approach would be to use
> notmuch_message_get_header everywhere, rather than introducing
> _notmuch_message_get_header_value, and have it simply recognize
> headers that can be retrieved directly from the database. Then
> library callers could take advantage of this optimization and it could
> be trivially extended to other headers in the future.
That's a good idea, updated patch below. This version also has fallback
handling for database entries that don't have the new header value
fields.
I couldn't find a way to have the Xapian API differentiate between
undefined and blank value fields so empty subject lines are encoded as a
single space.
Also, the address completion discussion made me think that maybe a value
field containing To/Cc/Bcc could be added too to avoid message file
parsing for the address search case but I haven't tried implementing
that yet.
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);
--
Istvan
_______________________________________________
notmuch mailing list
[email protected]
http://notmuchmail.org/mailman/listinfo/notmuch