#include #include #ifndef DB_PATH # define DB_PATH "/home/luc/mail" #endif #define print_error(success) \ if (success != NOTMUCH_STATUS_SUCCESS) \ printf("Notmuch error: %s\n", notmuch_status_to_string(success)) int main(int argc, char** argv) { notmuch_database_t* database = NULL; notmuch_query_t* query = NULL; unsigned int count = 0; notmuch_status_t success = NOTMUCH_STATUS_SUCCESS; char* query_string = "is:inbox or is:spam"; char* exclude_string = "spam"; if (argc > 1) { query_string = argv[1]; } if (argc > 2) { exclude_string = argv[2]; } success = notmuch_database_open(DB_PATH, NOTMUCH_DATABASE_MODE_READ_WRITE, &database); print_error(success); query = notmuch_query_create(database, query_string); success = notmuch_query_count_messages_st(query, &count); print_error(success); printf("1. run of notmuch_query_count_messages_st yields %d\n", count); success = notmuch_query_count_messages_st(query, &count); print_error(success); printf("2. run of notmuch_query_count_messages_st yields %d\n", count); printf("Excluding '%s'\n", exclude_string); notmuch_query_add_tag_exclude(query, exclude_string); success = notmuch_query_count_messages_st(query, &count); print_error(success); printf("3. run of notmuch_query_count_messages_st yields %d\n", count); success = notmuch_query_count_messages_st(query, &count); print_error(success); printf("4. run of notmuch_query_count_messages_st yields %d\n", count); return 0; }