X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=lib%2Fmessage.cc;h=4b2f98fd4f3426df992e2b845595cbf0ff937bfb;hb=417274d698b6718621b9f5dec744ab169499f4e3;hp=baeaa46972867d10a1cc5cde801fac03c0817df1;hpb=909f52bd8c4bdfa11cd3e75e3d0959e0293689bd;p=notmuch diff --git a/lib/message.cc b/lib/message.cc index baeaa469..4b2f98fd 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -35,6 +35,7 @@ struct _notmuch_message { char *thread_id; char *in_reply_to; char *filename; + char *author; notmuch_message_file_t *message_file; notmuch_message_list_t *replies; unsigned long flags; @@ -42,13 +43,6 @@ struct _notmuch_message { Xapian::Document doc; }; -/* "128 bits of thread-id ought to be enough for anybody" */ -#define NOTMUCH_THREAD_ID_BITS 128 -#define NOTMUCH_THREAD_ID_DIGITS (NOTMUCH_THREAD_ID_BITS / 4) -typedef struct _thread_id { - char str[NOTMUCH_THREAD_ID_DIGITS + 1]; -} thread_id_t; - /* We end up having to call the destructor explicitly because we had * to use "placement new" in order to initialize C++ objects within a * block that we allocated with talloc. So C++ is making talloc @@ -117,6 +111,7 @@ _notmuch_message_create (const void *talloc_owner, message->in_reply_to = NULL; message->filename = NULL; message->message_file = NULL; + message->author = NULL; message->replies = _notmuch_message_list_create (message); if (unlikely (message->replies == NULL)) { @@ -192,7 +187,7 @@ _notmuch_message_create_for_message_id (notmuch_database_t *notmuch, db = static_cast (notmuch->xapian_db); try { - doc.add_term (term); + doc.add_term (term, 0); talloc_free (term); doc.add_value (NOTMUCH_VALUE_MESSAGE_ID, message_id); @@ -416,22 +411,16 @@ _notmuch_message_add_filename (notmuch_message_t *message, return NOTMUCH_STATUS_SUCCESS; } -/* Move the filename from the data field (as it was in database format - * version 0) to a file-direntry term instead (as in database format - * version 1). - */ -void -_notmuch_message_upgrade_filename_storage (notmuch_message_t *message) +char * +_notmuch_message_talloc_copy_data (notmuch_message_t *message) { - char *filename; + return talloc_strdup (message, message->doc.get_data ().c_str ()); +} - filename = talloc_strdup (message, message->doc.get_data ().c_str ()); - if (filename && *filename != '\0') { - _notmuch_message_add_filename (message, filename); - message->doc.set_data (""); - _notmuch_message_sync (message); - } - talloc_free (filename); +void +_notmuch_message_clear_data (notmuch_message_t *message) +{ + message->doc.set_data (""); } const char * @@ -440,7 +429,7 @@ notmuch_message_get_filename (notmuch_message_t *message) const char *prefix = _find_prefix ("file-direntry"); int prefix_len = strlen (prefix); Xapian::TermIterator i; - char *direntry, *colon; + char *colon, *direntry = NULL; const char *db_path, *directory, *basename; unsigned int directory_id; void *local = talloc_new (message); @@ -546,6 +535,22 @@ notmuch_message_get_tags (notmuch_message_t *message) return _notmuch_convert_tags(message, i, end); } +const char * +notmuch_message_get_author (notmuch_message_t *message) +{ + return message->author; +} + +void +notmuch_message_set_author (notmuch_message_t *message, + const char *author) +{ + if (message->author) + talloc_free(message->author); + message->author = talloc_strdup(message, author); + return; +} + void _notmuch_message_set_date (notmuch_message_t *message, const char *date) @@ -563,45 +568,6 @@ _notmuch_message_set_date (notmuch_message_t *message, Xapian::sortable_serialise (time_value)); } -static void -thread_id_generate (thread_id_t *thread_id) -{ - static int seeded = 0; - FILE *dev_random; - uint32_t value; - char *s; - int i; - - if (! seeded) { - dev_random = fopen ("/dev/random", "r"); - if (dev_random == NULL) { - srand (time (NULL)); - } else { - fread ((void *) &value, sizeof (value), 1, dev_random); - srand (value); - fclose (dev_random); - } - seeded = 1; - } - - s = thread_id->str; - for (i = 0; i < NOTMUCH_THREAD_ID_DIGITS; i += 8) { - value = rand (); - sprintf (s, "%08x", value); - s += 8; - } -} - -void -_notmuch_message_ensure_thread_id (notmuch_message_t *message) -{ - /* If not part of any existing thread, generate a new thread_id. */ - thread_id_t thread_id; - - thread_id_generate (&thread_id); - _notmuch_message_add_term (message, "thread", thread_id.str); -} - /* Synchronize changes made to message->doc out into the database. */ void _notmuch_message_sync (notmuch_message_t *message) @@ -652,7 +618,7 @@ _notmuch_message_add_term (notmuch_message_t *message, if (strlen (term) > NOTMUCH_TERM_MAX) return NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG; - message->doc.add_term (term); + message->doc.add_term (term, 0); talloc_free (term); @@ -791,8 +757,8 @@ notmuch_message_remove_all_tags (notmuch_message_t *message) return status; for (tags = notmuch_message_get_tags (message); - notmuch_tags_has_more (tags); - notmuch_tags_advance (tags)) + notmuch_tags_valid (tags); + notmuch_tags_move_to_next (tags)) { tag = notmuch_tags_get (tags);