aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorGravatar Austin Clements <amdragon@mit.edu>2014-08-25 13:26:07 -0400
committerGravatar David Bremner <david@tethera.net>2014-08-30 11:37:33 -0700
commit5dbfed4a73d8c310afa51108af1ca6484506145a (patch)
tree09ac155dd2520d97950875ec5533b104005e62c4 /lib
parent02fec226fcb02a5c784f4322365b979639b37c76 (diff)
lib: Support empty header values in database
Commit 567bcbc2 introduced support for storing various headers in document values. However, doing so in a backwards-compatible way meant that genuinely empty header values could not be distinguished from the old behavior of not storing the headers at all, so these required parsing the original message. Now that we have database features, new databases can declare that all messages have header values, so if we have this feature flag, we can use the stored header value even if it's the empty string. This requires slight cleanup to notmuch_message_get_header, since the code previously couldn't distinguish between empty headers and headers that are never stored in the database (previously this distinction didn't matter).
Diffstat (limited to 'lib')
-rw-r--r--lib/message.cc45
1 files changed, 27 insertions, 18 deletions
diff --git a/lib/message.cc b/lib/message.cc
index 3f934265..ed8c59e9 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -414,26 +414,35 @@ _notmuch_message_ensure_message_file (notmuch_message_t *message)
const char *
notmuch_message_get_header (notmuch_message_t *message, const char *header)
{
- try {
- std::string value;
-
- /* Fetch header from the appropriate xapian value field if
- * available */
- if (strcasecmp (header, "from") == 0)
- value = message->doc.get_value (NOTMUCH_VALUE_FROM);
- else if (strcasecmp (header, "subject") == 0)
- value = message->doc.get_value (NOTMUCH_VALUE_SUBJECT);
- else if (strcasecmp (header, "message-id") == 0)
- value = message->doc.get_value (NOTMUCH_VALUE_MESSAGE_ID);
-
- if (!value.empty())
+ Xapian::valueno slot = Xapian::BAD_VALUENO;
+
+ /* Fetch header from the appropriate xapian value field if
+ * available */
+ if (strcasecmp (header, "from") == 0)
+ slot = NOTMUCH_VALUE_FROM;
+ else if (strcasecmp (header, "subject") == 0)
+ slot = NOTMUCH_VALUE_SUBJECT;
+ else if (strcasecmp (header, "message-id") == 0)
+ 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) {
- fprintf (stderr, "A Xapian exception occurred when reading header: %s\n",
- error.get_msg().c_str());
- message->notmuch->exception_reported = TRUE;
- return NULL;
+ } catch (Xapian::Error &error) {
+ fprintf (stderr, "A Xapian exception occurred when reading header: %s\n",
+ error.get_msg().c_str());
+ message->notmuch->exception_reported = TRUE;
+ return NULL;
+ }
}
/* Otherwise fall back to parsing the file */