mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-12-22 17:34:54 +01:00
Add a preliminary "notmuch search" command.
This isn't behaving at all like it's documented yet, (for example, it's returning message IDs not thread IDs[*]). In fact, the output code is just a copy of the body of "notmuch dump", so all you get for now is message ID and tags. But this should at least be enough to start exercising the query functionality, (which is currently very buggy). [*] I'll want to convert the databse to store thread documents before fixing that.
This commit is contained in:
parent
0e72d6a9ec
commit
144b2cbc55
1 changed files with 67 additions and 2 deletions
69
notmuch.c
69
notmuch.c
|
@ -577,8 +577,73 @@ new_command (int argc, char *argv[])
|
|||
int
|
||||
search_command (int argc, char *argv[])
|
||||
{
|
||||
fprintf (stderr, "Error: search is not implemented yet.\n");
|
||||
return 1;
|
||||
void *local = talloc_new (NULL);
|
||||
notmuch_database_t *notmuch = NULL;
|
||||
notmuch_query_t *query;
|
||||
notmuch_results_t *results;
|
||||
notmuch_message_t *message;
|
||||
notmuch_tags_t *tags;
|
||||
char *query_str;
|
||||
int i;
|
||||
notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
|
||||
|
||||
notmuch = notmuch_database_open (NULL);
|
||||
if (notmuch == NULL) {
|
||||
ret = 1;
|
||||
goto DONE;
|
||||
}
|
||||
|
||||
/* XXX: Should add xtalloc wrappers here and use them. */
|
||||
query_str = talloc_strdup (local, "");
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
if (i != 0)
|
||||
query_str = talloc_asprintf_append (query_str, " ");
|
||||
|
||||
query_str = talloc_asprintf_append (query_str, "%s", argv[i]);
|
||||
}
|
||||
|
||||
query = notmuch_query_create (notmuch, query_str);
|
||||
if (query == NULL) {
|
||||
fprintf (stderr, "Out of memory\n");
|
||||
ret = 1;
|
||||
goto DONE;
|
||||
}
|
||||
|
||||
for (results = notmuch_query_search (query);
|
||||
notmuch_results_has_more (results);
|
||||
notmuch_results_advance (results))
|
||||
{
|
||||
int first = 1;
|
||||
message = notmuch_results_get (results);
|
||||
|
||||
printf ("%s (", notmuch_message_get_message_id (message));
|
||||
|
||||
for (tags = notmuch_message_get_tags (message);
|
||||
notmuch_tags_has_more (tags);
|
||||
notmuch_tags_advance (tags))
|
||||
{
|
||||
if (! first)
|
||||
printf (" ");
|
||||
|
||||
printf ("%s", notmuch_tags_get (tags));
|
||||
|
||||
first = 0;
|
||||
}
|
||||
|
||||
printf (")\n");
|
||||
|
||||
notmuch_message_destroy (message);
|
||||
}
|
||||
|
||||
notmuch_query_destroy (query);
|
||||
|
||||
DONE:
|
||||
if (notmuch)
|
||||
notmuch_database_close (notmuch);
|
||||
talloc_free (local);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
Loading…
Reference in a new issue