mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-25 04:18:08 +01:00
lib: Internal support for querying and creating ghost messages
This updates the message abstraction to support ghost messages: it adds a message flag that distinguishes regular messages from ghost messages, and an internal function for initializing a newly created (blank) message as a ghost message.
This commit is contained in:
parent
d99491f274
commit
bc9c50602d
3 changed files with 62 additions and 3 deletions
|
@ -39,6 +39,9 @@ struct visible _notmuch_message {
|
||||||
notmuch_message_file_t *message_file;
|
notmuch_message_file_t *message_file;
|
||||||
notmuch_message_list_t *replies;
|
notmuch_message_list_t *replies;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
/* For flags that are initialized on-demand, lazy_flags indicates
|
||||||
|
* if each flag has been initialized. */
|
||||||
|
unsigned long lazy_flags;
|
||||||
|
|
||||||
Xapian::Document doc;
|
Xapian::Document doc;
|
||||||
Xapian::termcount termpos;
|
Xapian::termcount termpos;
|
||||||
|
@ -99,6 +102,7 @@ _notmuch_message_create_for_document (const void *talloc_owner,
|
||||||
|
|
||||||
message->frozen = 0;
|
message->frozen = 0;
|
||||||
message->flags = 0;
|
message->flags = 0;
|
||||||
|
message->lazy_flags = 0;
|
||||||
|
|
||||||
/* Each of these will be lazily created as needed. */
|
/* Each of these will be lazily created as needed. */
|
||||||
message->message_id = NULL;
|
message->message_id = NULL;
|
||||||
|
@ -192,7 +196,7 @@ _notmuch_message_create (const void *talloc_owner,
|
||||||
*
|
*
|
||||||
* There is already a document with message ID 'message_id' in the
|
* There is already a document with message ID 'message_id' in the
|
||||||
* database. The returned message can be used to query/modify the
|
* database. The returned message can be used to query/modify the
|
||||||
* document.
|
* document. The message may be a ghost message.
|
||||||
*
|
*
|
||||||
* NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND:
|
* NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND:
|
||||||
*
|
*
|
||||||
|
@ -305,6 +309,7 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message)
|
||||||
const char *thread_prefix = _find_prefix ("thread"),
|
const char *thread_prefix = _find_prefix ("thread"),
|
||||||
*tag_prefix = _find_prefix ("tag"),
|
*tag_prefix = _find_prefix ("tag"),
|
||||||
*id_prefix = _find_prefix ("id"),
|
*id_prefix = _find_prefix ("id"),
|
||||||
|
*type_prefix = _find_prefix ("type"),
|
||||||
*filename_prefix = _find_prefix ("file-direntry"),
|
*filename_prefix = _find_prefix ("file-direntry"),
|
||||||
*replyto_prefix = _find_prefix ("replyto");
|
*replyto_prefix = _find_prefix ("replyto");
|
||||||
|
|
||||||
|
@ -337,10 +342,25 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message)
|
||||||
message->message_id =
|
message->message_id =
|
||||||
_notmuch_message_get_term (message, i, end, id_prefix);
|
_notmuch_message_get_term (message, i, end, id_prefix);
|
||||||
|
|
||||||
|
/* Get document type */
|
||||||
|
assert (strcmp (id_prefix, type_prefix) < 0);
|
||||||
|
if (! NOTMUCH_TEST_BIT (message->lazy_flags, NOTMUCH_MESSAGE_FLAG_GHOST)) {
|
||||||
|
i.skip_to (type_prefix);
|
||||||
|
/* "T" is the prefix "type" fields. See
|
||||||
|
* BOOLEAN_PREFIX_INTERNAL. */
|
||||||
|
if (*i == "Tmail")
|
||||||
|
NOTMUCH_CLEAR_BIT (&message->flags, NOTMUCH_MESSAGE_FLAG_GHOST);
|
||||||
|
else if (*i == "Tghost")
|
||||||
|
NOTMUCH_SET_BIT (&message->flags, NOTMUCH_MESSAGE_FLAG_GHOST);
|
||||||
|
else
|
||||||
|
INTERNAL_ERROR ("Message without type term");
|
||||||
|
NOTMUCH_SET_BIT (&message->lazy_flags, NOTMUCH_MESSAGE_FLAG_GHOST);
|
||||||
|
}
|
||||||
|
|
||||||
/* Get filename list. Here we get only the terms. We lazily
|
/* Get filename list. Here we get only the terms. We lazily
|
||||||
* expand them to full file names when needed in
|
* expand them to full file names when needed in
|
||||||
* _notmuch_message_ensure_filename_list. */
|
* _notmuch_message_ensure_filename_list. */
|
||||||
assert (strcmp (id_prefix, filename_prefix) < 0);
|
assert (strcmp (type_prefix, filename_prefix) < 0);
|
||||||
if (!message->filename_term_list && !message->filename_list)
|
if (!message->filename_term_list && !message->filename_list)
|
||||||
message->filename_term_list =
|
message->filename_term_list =
|
||||||
_notmuch_database_get_terms_with_prefix (message, i, end,
|
_notmuch_database_get_terms_with_prefix (message, i, end,
|
||||||
|
@ -371,6 +391,11 @@ _notmuch_message_invalidate_metadata (notmuch_message_t *message,
|
||||||
message->tag_list = NULL;
|
message->tag_list = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strcmp ("type", prefix_name) == 0) {
|
||||||
|
NOTMUCH_CLEAR_BIT (&message->flags, NOTMUCH_MESSAGE_FLAG_GHOST);
|
||||||
|
NOTMUCH_CLEAR_BIT (&message->lazy_flags, NOTMUCH_MESSAGE_FLAG_GHOST);
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp ("file-direntry", prefix_name) == 0) {
|
if (strcmp ("file-direntry", prefix_name) == 0) {
|
||||||
talloc_free (message->filename_term_list);
|
talloc_free (message->filename_term_list);
|
||||||
talloc_free (message->filename_list);
|
talloc_free (message->filename_list);
|
||||||
|
@ -869,6 +894,10 @@ notmuch_bool_t
|
||||||
notmuch_message_get_flag (notmuch_message_t *message,
|
notmuch_message_get_flag (notmuch_message_t *message,
|
||||||
notmuch_message_flag_t flag)
|
notmuch_message_flag_t flag)
|
||||||
{
|
{
|
||||||
|
if (flag == NOTMUCH_MESSAGE_FLAG_GHOST &&
|
||||||
|
! NOTMUCH_TEST_BIT (message->lazy_flags, flag))
|
||||||
|
_notmuch_message_ensure_metadata (message);
|
||||||
|
|
||||||
return NOTMUCH_TEST_BIT (message->flags, flag);
|
return NOTMUCH_TEST_BIT (message->flags, flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -880,6 +909,7 @@ notmuch_message_set_flag (notmuch_message_t *message,
|
||||||
NOTMUCH_SET_BIT (&message->flags, flag);
|
NOTMUCH_SET_BIT (&message->flags, flag);
|
||||||
else
|
else
|
||||||
NOTMUCH_CLEAR_BIT (&message->flags, flag);
|
NOTMUCH_CLEAR_BIT (&message->flags, flag);
|
||||||
|
NOTMUCH_SET_BIT (&message->lazy_flags, flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t
|
time_t
|
||||||
|
@ -989,6 +1019,24 @@ _notmuch_message_delete (notmuch_message_t *message)
|
||||||
return NOTMUCH_STATUS_SUCCESS;
|
return NOTMUCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Transform a blank message into a ghost message. The caller must
|
||||||
|
* _notmuch_message_sync the message. */
|
||||||
|
notmuch_private_status_t
|
||||||
|
_notmuch_message_initialize_ghost (notmuch_message_t *message,
|
||||||
|
const char *thread_id)
|
||||||
|
{
|
||||||
|
notmuch_private_status_t status;
|
||||||
|
|
||||||
|
status = _notmuch_message_add_term (message, "type", "ghost");
|
||||||
|
if (status)
|
||||||
|
return status;
|
||||||
|
status = _notmuch_message_add_term (message, "thread", thread_id);
|
||||||
|
if (status)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
return NOTMUCH_PRIVATE_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
/* Ensure that 'message' is not holding any file object open. Future
|
/* Ensure that 'message' is not holding any file object open. Future
|
||||||
* calls to various functions will still automatically open the
|
* calls to various functions will still automatically open the
|
||||||
* message file as needed.
|
* message file as needed.
|
||||||
|
|
|
@ -308,6 +308,10 @@ _notmuch_message_sync (notmuch_message_t *message);
|
||||||
notmuch_status_t
|
notmuch_status_t
|
||||||
_notmuch_message_delete (notmuch_message_t *message);
|
_notmuch_message_delete (notmuch_message_t *message);
|
||||||
|
|
||||||
|
notmuch_private_status_t
|
||||||
|
_notmuch_message_initialize_ghost (notmuch_message_t *message,
|
||||||
|
const char *thread_id);
|
||||||
|
|
||||||
void
|
void
|
||||||
_notmuch_message_close (notmuch_message_t *message);
|
_notmuch_message_close (notmuch_message_t *message);
|
||||||
|
|
||||||
|
|
|
@ -1221,7 +1221,14 @@ notmuch_message_get_filenames (notmuch_message_t *message);
|
||||||
*/
|
*/
|
||||||
typedef enum _notmuch_message_flag {
|
typedef enum _notmuch_message_flag {
|
||||||
NOTMUCH_MESSAGE_FLAG_MATCH,
|
NOTMUCH_MESSAGE_FLAG_MATCH,
|
||||||
NOTMUCH_MESSAGE_FLAG_EXCLUDED
|
NOTMUCH_MESSAGE_FLAG_EXCLUDED,
|
||||||
|
|
||||||
|
/* This message is a "ghost message", meaning it has no filenames
|
||||||
|
* or content, but we know it exists because it was referenced by
|
||||||
|
* some other message. A ghost message has only a message ID and
|
||||||
|
* thread ID.
|
||||||
|
*/
|
||||||
|
NOTMUCH_MESSAGE_FLAG_GHOST,
|
||||||
} notmuch_message_flag_t;
|
} notmuch_message_flag_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue