aboutsummaryrefslogtreecommitdiffhomepage
path: root/notmuch.c
diff options
context:
space:
mode:
authorGravatar Carl Worth <cworth@cworth.org>2009-10-29 08:51:12 -0700
committerGravatar Carl Worth <cworth@cworth.org>2009-10-29 08:51:12 -0700
commitbf78a89196b251c2465f6cefa8198f22c87ff23d (patch)
tree3728d25ec1ec9317cb4aca314ab7f8fa932f15d4 /notmuch.c
parentb39ebca8c97fb19c52e46a2b9565c2d9fa0707d0 (diff)
notmuch show: Initial implementation (headers only)
We're using a delimiter syntax that Keith is optimistic about being able to easily parse in emacs. Note: We're not escaping any occurrence of the delimiters in the message yet, so we'll need to fix that.
Diffstat (limited to 'notmuch.c')
-rw-r--r--notmuch.c65
1 files changed, 63 insertions, 2 deletions
diff --git a/notmuch.c b/notmuch.c
index 757f09d7..66b615b2 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -800,8 +800,69 @@ search_command (int argc, char *argv[])
static int
show_command (unused (int argc), unused (char *argv[]))
{
- fprintf (stderr, "Error: show is not implemented yet.\n");
- return 1;
+ void *local = talloc_new (NULL);
+ char *query_string;
+ notmuch_database_t *notmuch = NULL;
+ notmuch_query_t *query = NULL;
+ notmuch_message_results_t *messages;
+ notmuch_message_t *message;
+ int ret = 0;
+
+ if (argc != 1) {
+ fprintf (stderr, "Error: \"notmuch show\" requires exactly one thread-ID argument.\n");
+ ret = 1;
+ goto DONE;
+ }
+
+ notmuch = notmuch_database_open (NULL);
+ if (notmuch == NULL) {
+ ret = 1;
+ goto DONE;
+ }
+
+ query_string = talloc_asprintf (local, "thread:%s", argv[0]);
+ if (query_string == NULL) {
+ fprintf (stderr, "Out of memory\n");
+ ret = 1;
+ goto DONE;
+ }
+
+ query = notmuch_query_create (notmuch, query_string);
+ if (query == NULL) {
+ fprintf (stderr, "Out of memory\n");
+ ret = 1;
+ goto DONE;
+ }
+
+ for (messages = notmuch_query_search_messages (query);
+ notmuch_message_results_has_more (messages);
+ notmuch_message_results_advance (messages))
+ {
+ message = notmuch_message_results_get (messages);
+
+ printf ("%%message{\n");
+
+ printf ("%%header{\n");
+
+ printf ("%s", notmuch_message_get_all_headers (message));
+
+ printf ("%%header}\n");
+ printf ("%%message}\n");
+
+ notmuch_message_destroy (message);
+ }
+
+ DONE:
+ if (local)
+ talloc_free (local);
+
+ if (query)
+ notmuch_query_destroy (query);
+
+ if (notmuch)
+ notmuch_database_close (notmuch);
+
+ return ret;
}
static int