*
* Multiple terms of given prefix:
*
- * reference: All message IDs from In-Reply-To and Re ferences
+ * reference: All message IDs from In-Reply-To and References
* headers in the message.
*
* tag: Any tags associated with this message by the user.
* ASCII integer. The initial database version
* was 1, (though a schema existed before that
* were no "version" database value existed at
- * all). Succesive versions are allocated as
+ * all). Successive versions are allocated as
* changes are made to the database (such as by
* indexing new fields).
*
* incremented for each thread ID.
*
* thread_id_* A pre-allocated thread ID for a particular
- * message. This is actually an arbitarily large
+ * message. This is actually an arbitrarily large
* family of metadata name. Any particular name is
* formed by concatenating "thread_id_" with a message
* ID (or the SHA1 sum of a message ID if it is very
}
/* Parse an RFC 822 message-id, discarding whitespace, any RFC 822
- * comments, and the '<' and '>' delimeters.
+ * comments, and the '<' and '>' delimiters.
*
* If not NULL, then *next will be made to point to the first character
* not parsed, (possibly pointing to the final '\0' terminator.
/* Given a legal 'path' for the database, return the relative path.
*
- * The return value will be a pointer to the originl path contents,
+ * The return value will be a pointer to the original path contents,
* and will be either the original string (if 'path' was relative) or
* a portion of the string (if path was absolute and begins with the
* database path).
* In all cases, we assign to the current message the first thread_id
* found (through either parent or child). We will also merge any
* existing, distinct threads where this message belongs to both,
- * (which is not uncommon when mesages are processed out of order).
+ * (which is not uncommon when messages are processed out of order).
*
* Finally, if no thread ID has been found through parent or child, we
* call _notmuch_message_generate_thread_id to generate a new thread
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");
+ int prefix_len = strlen (prefix);
notmuch_string_list_t *list;
- std::string tag;
-
- /* Currently this iteration is written with the assumption that
- * "tag" has a single-character prefix. */
- assert (strlen (prefix) == 1);
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_string_list_append (list, tag.c_str () + 1);
-
- i++;
+ _notmuch_string_list_append (list, (*i).c_str () + prefix_len);
}
- _notmuch_string_list_sort (list);
-
- return _notmuch_tags_create (ctx, list);
+ 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());