X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=lib%2Fmessage.cc;h=01950505900f8d161701883b5b7a5e7dc5e67d26;hp=ea9c8bd96afb1b34ccb8ebb329c5f93ebcaa344b;hb=9439b217c349478b3603d5368f534acb1cd23974;hpb=f93b7218c3e2d11c5b3cdd4c367a42ca7a7ede77 diff --git a/lib/message.cc b/lib/message.cc index ea9c8bd9..01950505 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -42,13 +42,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 @@ -192,7 +185,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,6 +409,18 @@ _notmuch_message_add_filename (notmuch_message_t *message, return NOTMUCH_STATUS_SUCCESS; } +char * +_notmuch_message_talloc_copy_data (notmuch_message_t *message) +{ + return talloc_strdup (message, message->doc.get_data ().c_str ()); +} + +void +_notmuch_message_clear_data (notmuch_message_t *message) +{ + message->doc.set_data (""); +} + const char * notmuch_message_get_filename (notmuch_message_t *message) { @@ -441,7 +446,10 @@ notmuch_message_get_filename (notmuch_message_t *message) { /* A message document created by an old version of notmuch * (prior to rename support) will have the filename in the - * data of the document rather than as a file-direntry term. */ + * data of the document rather than as a file-direntry term. + * + * It would be nice to do the upgrade of the document directly + * here, but the database is likely open in read-only mode. */ const char *data; data = message->doc.get_data ().c_str (); @@ -542,45 +550,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) @@ -631,7 +600,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);