mirror of
https://git.notmuchmail.org/git/notmuch
synced 2025-01-03 15:21:41 +01:00
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).
This commit is contained in:
parent
02fec226fc
commit
5dbfed4a73
1 changed files with 25 additions and 16 deletions
|
@ -414,19 +414,27 @@ _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;
|
||||
Xapian::valueno slot = Xapian::BAD_VALUENO;
|
||||
|
||||
/* Fetch header from the appropriate xapian value field if
|
||||
* available */
|
||||
if (strcasecmp (header, "from") == 0)
|
||||
value = message->doc.get_value (NOTMUCH_VALUE_FROM);
|
||||
slot = NOTMUCH_VALUE_FROM;
|
||||
else if (strcasecmp (header, "subject") == 0)
|
||||
value = message->doc.get_value (NOTMUCH_VALUE_SUBJECT);
|
||||
slot = NOTMUCH_VALUE_SUBJECT;
|
||||
else if (strcasecmp (header, "message-id") == 0)
|
||||
value = message->doc.get_value (NOTMUCH_VALUE_MESSAGE_ID);
|
||||
slot = NOTMUCH_VALUE_MESSAGE_ID;
|
||||
|
||||
if (!value.empty())
|
||||
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) {
|
||||
|
@ -435,6 +443,7 @@ notmuch_message_get_header (notmuch_message_t *message, const char *header)
|
|||
message->notmuch->exception_reported = TRUE;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Otherwise fall back to parsing the file */
|
||||
_notmuch_message_ensure_message_file (message);
|
||||
|
|
Loading…
Reference in a new issue