#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <notmuch.h>

const char *query = "tag:unread to:linux-mm@kvack.org -(tag:unread (shutemov or tag:followed))";
//const char *query = "tag:unread to:linux-mm@kvack.org -(shutemov or tag:followed)";

int main(int argc, char **argv)
{
    notmuch_database_t *db;
    notmuch_query_t *q;
    notmuch_threads_t *threads;
    int count1 = 0, count2 = 0;

    notmuch_database_open(DB_PATH, 0, &db);
    q = notmuch_query_create(db, query);

    for (notmuch_query_search_threads_st(q, &threads);
	    notmuch_threads_valid(threads);
	    notmuch_threads_move_to_next(threads)) {
	count1++;
    }

    notmuch_threads_destroy(threads);
    notmuch_query_destroy(q);
    notmuch_database_close(db);

    notmuch_database_open(DB_PATH, 0, &db);
    q = notmuch_query_create(db, query);

    for (notmuch_query_search_threads_st(q, &threads);
	    notmuch_threads_valid(threads);
	    notmuch_threads_move_to_next(threads)) {
	count2++;
    }

    notmuch_threads_destroy(threads);
    notmuch_query_destroy(q);
    notmuch_database_close(db);

    printf("count1: %d, count2: %d\n", count1, count2);
    if (count1 != count2)
	printf("WTF?\n");
    return 0;
}
