#include <sys/time.h>
#include <signal.h>
-#include <xapian.h>
#include <glib.h> /* g_free, GPtrArray, GHashTable */
*
* In addition, terms from the content of the message are added with
* "from", "to", "attachment", and "subject" prefixes for use by the
- * user in searching. But the database doesn't really care itself
- * about any of these.
+ * user in searching. Similarly, terms from the path of the mail
+ * message are added with a "folder" prefix. But the database doesn't
+ * really care itself about any of these.
*
* The data portion of a mail document is empty.
*
* nearly universal to all mail messages).
*/
-prefix_t BOOLEAN_PREFIX_INTERNAL[] = {
+static prefix_t BOOLEAN_PREFIX_INTERNAL[] = {
{ "type", "T" },
{ "reference", "XREFERENCE" },
{ "replyto", "XREPLYTO" },
{ "directory-direntry", "XDDIRENTRY" },
};
-prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {
+static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {
{ "thread", "G" },
{ "tag", "K" },
{ "is", "K" },
{ "id", "Q" }
};
-prefix_t PROBABILISTIC_PREFIX[]= {
+static prefix_t PROBABILISTIC_PREFIX[]= {
{ "from", "XFROM" },
{ "to", "XTO" },
{ "attachment", "XATTACHMENT" },
- { "subject", "XSUBJECT"}
+ { "subject", "XSUBJECT"},
+ { "folder", "XFOLDER"}
};
int
talloc_free (metadata_key);
- return thread_id;
+ return talloc_strdup (ctx, thread_id);
}
static notmuch_status_t
DONE:
if (message) {
- if (ret == NOTMUCH_STATUS_SUCCESS && message_ret)
+ if ((ret == NOTMUCH_STATUS_SUCCESS ||
+ ret == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) && message_ret)
*message_ret = message;
else
notmuch_message_destroy (message);
if (status)
return status;
- term = talloc_asprintf (notmuch, "%s%s", prefix, direntry);
+ term = talloc_asprintf (local, "%s%s", prefix, direntry);
find_doc_ids_for_term (notmuch, term, &i, &end);
for ( ; i != end; i++) {
Xapian::TermIterator j;
+ notmuch_message_t *message;
+ notmuch_private_status_t private_status;
- document = find_document_for_doc_id (notmuch, *i);
+ message = _notmuch_message_create (local, notmuch,
+ *i, &private_status);
+ if (message == NULL)
+ return COERCE_STATUS (private_status,
+ "Inconsistent document ID in datbase.");
- document.remove_term (term);
+ _notmuch_message_remove_filename (message, filename);
+ _notmuch_message_sync (message);
+ /* Take care to find document after sync'ing filename removal. */
+ document = find_document_for_doc_id (notmuch, *i);
j = document.termlist_begin ();
j.skip_to (prefix);
db->delete_document (document.get_docid ());
status = NOTMUCH_STATUS_SUCCESS;
} else {
- db->replace_document (document.get_docid (), document);
status = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
}
}
return status;
}
-notmuch_tags_t *
-_notmuch_convert_tags (void *ctx, Xapian::TermIterator &i,
- Xapian::TermIterator &end)
+notmuch_string_list_t *
+_notmuch_database_get_terms_with_prefix (void *ctx, Xapian::TermIterator &i,
+ Xapian::TermIterator &end,
+ const char *prefix)
{
- const char *prefix = _find_prefix ("tag");
- notmuch_tags_t *tags;
- std::string tag;
-
- /* Currently this iteration is written with the assumption that
- * "tag" has a single-character prefix. */
- assert (strlen (prefix) == 1);
+ int prefix_len = strlen (prefix);
+ notmuch_string_list_t *list;
- tags = _notmuch_tags_create (ctx);
- if (unlikely (tags == NULL))
+ list = _notmuch_string_list_create (ctx);
+ if (unlikely (list == NULL))
return NULL;
- i.skip_to (prefix);
-
- while (i != end) {
- tag = *i;
-
- if (tag.empty () || tag[0] != *prefix)
+ for (i.skip_to (prefix); i != end; i++) {
+ /* Terminate loop at first term without desired prefix. */
+ if (strncmp ((*i).c_str (), prefix, prefix_len))
break;
- _notmuch_tags_add_tag (tags, tag.c_str () + 1);
-
- i++;
+ _notmuch_string_list_append (list, (*i).c_str () + prefix_len);
}
- _notmuch_tags_prepare_iterator (tags);
-
- return tags;
+ return list;
}
notmuch_tags_t *
notmuch_database_get_all_tags (notmuch_database_t *db)
{
Xapian::TermIterator i, end;
+ notmuch_string_list_t *tags;
try {
i = db->xapian_db->allterms_begin();
end = db->xapian_db->allterms_end();
- return _notmuch_convert_tags(db, i, end);
+ tags = _notmuch_database_get_terms_with_prefix (db, i, end,
+ _find_prefix ("tag"));
+ _notmuch_string_list_sort (tags);
+ return _notmuch_tags_create (db, tags);
} catch (const Xapian::Error &error) {
fprintf (stderr, "A Xapian exception occurred getting tags: %s.\n",
error.get_msg().c_str());