X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=database.cc;h=1aef2a966ec3fb431ff3b6f92735f0fdb57f4326;hp=5ee07059cda75569fe7e7bbfd6ffca6b23a4c823;hb=0e914d9e9646349976c16472be9e986ad4b3e29e;hpb=50144fb354dc5bf282c2a2cdc68c926e42ccf3ef diff --git a/database.cc b/database.cc index 5ee07059..1aef2a96 100644 --- a/database.cc +++ b/database.cc @@ -67,15 +67,6 @@ prefix_t BOOLEAN_PREFIX[] = { { "ref", "R" } }; -/* Similarly, these value numbers are also chosen to be sup - * compatible. */ - -typedef enum { - NOTMUCH_VALUE_MESSAGE_ID = 0, - NOTMUCH_VALUE_THREAD = 1, - NOTMUCH_VALUE_DATE = 2 -} notmuch_value_t; - static const char * find_prefix (const char *name) { @@ -314,6 +305,7 @@ static char * parse_message_id (const char *message_id, const char **next) { const char *s, *end; + char *result; if (message_id == NULL) return NULL; @@ -348,10 +340,23 @@ parse_message_id (const char *message_id, const char **next) if (end > s && *end == '>') end--; - if (end > s) - return strndup (s, end - s + 1); - else + if (end <= s) return NULL; + + result = strndup (s, end - s + 1); + + /* Finally, collapse any whitespace that is within the message-id + * itself. */ + { + char *r; + int len; + + for (r = result, len = strlen (r); *r; r++, len--) + if (*r == ' ' || *r == '\t') + memmove (r, r+1, len); + } + + return result; } /* Parse a References header value, putting a copy of each referenced @@ -459,6 +464,9 @@ notmuch_database_open (const char *path) try { notmuch->xapian_db = new Xapian::WritableDatabase (xapian_path, Xapian::DB_CREATE_OR_OPEN); + notmuch->query_parser = new Xapian::QueryParser; + notmuch->query_parser->set_default_op (Xapian::Query::OP_AND); + notmuch->query_parser->set_database (*notmuch->xapian_db); } catch (const Xapian::Error &error) { fprintf (stderr, "A Xapian exception occurred: %s\n", error.get_msg().c_str()); @@ -478,6 +486,7 @@ notmuch_database_open (const char *path) void notmuch_database_close (notmuch_database_t *notmuch) { + delete notmuch->query_parser; delete notmuch->xapian_db; free (notmuch->path); free (notmuch); @@ -520,6 +529,8 @@ notmuch_database_add_message (notmuch_database_t *notmuch, try { doc.set_data (filename); + add_term (doc, "type", "mail"); + parents = g_ptr_array_new (); refs = notmuch_message_file_get_header (message, "references");