]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-search.c
notmuch search: Fix to display authors in date order.
[notmuch] / notmuch-search.c
index 93724dd2994422cfd0365eff0ebe7d9fe70bbe4d..c628b369b66fadd975821261b4169e91c78ac3ca 100644 (file)
@@ -24,6 +24,7 @@ typedef enum {
     OUTPUT_SUMMARY,
     OUTPUT_THREADS,
     OUTPUT_MESSAGES,
+    OUTPUT_FILES,
     OUTPUT_TAGS
 } output_t;
 
@@ -188,7 +189,9 @@ do_search_threads (const void *ctx,
     {
        int first_tag = 1;
 
-       if (! first_thread)
+       if (first_thread)
+           fputs (format->results_start, stdout);
+       else
            fputs (format->item_sep, stdout);
 
        thread = notmuch_threads_get (threads);
@@ -234,13 +237,17 @@ do_search_threads (const void *ctx,
        notmuch_thread_destroy (thread);
     }
 
+    if (! first_thread)
+       fputs (format->results_end, stdout);
+
     return 0;
 }
 
 static int
 do_search_messages (const void *ctx,
                    const search_format_t *format,
-                   notmuch_query_t *query)
+                   notmuch_query_t *query,
+                   output_t output)
 {
     notmuch_message_t *message;
     notmuch_messages_t *messages;
@@ -256,10 +263,18 @@ do_search_messages (const void *ctx,
     {
        message = notmuch_messages_get (messages);
 
-       if (! first_message)
+       if (first_message)
+           fputs (format->results_start, stdout);
+       else
            fputs (format->item_sep, stdout);
 
-       format->item_id (ctx, "id:", notmuch_message_get_message_id (message));
+       if (output == OUTPUT_FILES) {
+           format->item_id (ctx, "",
+                            notmuch_message_get_filename (message));
+       } else { /* output == OUTPUT_MESSAGES */
+           format->item_id (ctx, "id:",
+                            notmuch_message_get_message_id (message));
+       }
 
        first_message = 0;
 
@@ -268,6 +283,9 @@ do_search_messages (const void *ctx,
 
     notmuch_messages_destroy (messages);
 
+    if (! first_message)
+       fputs (format->results_end, stdout);
+
     return 0;
 }
 
@@ -301,7 +319,9 @@ do_search_tags (const void *ctx,
     {
        tag = notmuch_tags_get (tags);
 
-       if (! first_tag)
+       if (first_tag)
+           fputs (format->results_start, stdout);
+       else
            fputs (format->item_sep, stdout);
 
        format->item_id (ctx, "", tag);
@@ -314,6 +334,9 @@ do_search_tags (const void *ctx,
     if (messages)
        notmuch_messages_destroy (messages);
 
+    if (! first_tag)
+       fputs (format->results_end, stdout);
+
     return 0;
 }
 
@@ -363,6 +386,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
                output = OUTPUT_THREADS;
            } else if (strcmp (opt, "messages") == 0) {
                output = OUTPUT_MESSAGES;
+           } else if (strcmp (opt, "files") == 0) {
+               output = OUTPUT_FILES;
            } else if (strcmp (opt, "tags") == 0) {
                output = OUTPUT_TAGS;
            } else {
@@ -405,8 +430,6 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
 
     notmuch_query_set_sort (query, sort);
 
-    fputs (format->results_start, stdout);
-
     switch (output) {
     default:
     case OUTPUT_SUMMARY:
@@ -414,15 +437,14 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
        ret = do_search_threads (ctx, format, query, sort, output);
        break;
     case OUTPUT_MESSAGES:
-       ret = do_search_messages (ctx, format, query);
+    case OUTPUT_FILES:
+       ret = do_search_messages (ctx, format, query, output);
        break;
     case OUTPUT_TAGS:
        ret = do_search_tags (ctx, notmuch, format, query);
        break;
     }
 
-    fputs (format->results_end, stdout);
-
     notmuch_query_destroy (query);
     notmuch_database_close (notmuch);