diff options
| author | Jani Nikula <jani@nikula.org> | 2014-11-01 11:31:06 +0200 |
|---|---|---|
| committer | David Bremner <david@tethera.net> | 2014-11-02 19:42:12 +0100 |
| commit | 4366b9b88c63242a166007d309bdbadd4be5576e (patch) | |
| tree | 8b5da24281eb431862512756e4328de18d506098 /notmuch-search.c | |
| parent | 96988e35c7aa44072fff07224c5e39254aa43e81 (diff) | |
cli: add support for notmuch search --duplicate=N with --output=messages
Print the message IDs of all messages matching the search terms that
have at least N files associated with them.
Diffstat (limited to 'notmuch-search.c')
| -rw-r--r-- | notmuch-search.c | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/notmuch-search.c b/notmuch-search.c index 671fe413..6345fb62 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -311,6 +311,24 @@ process_address_header (const search_options_t *opt, const char *value) } static int +_count_filenames (notmuch_message_t *message) +{ + notmuch_filenames_t *filenames; + int i = 0; + + filenames = notmuch_message_get_filenames (message); + + while (notmuch_filenames_valid (filenames)) { + notmuch_filenames_move_to_next (filenames); + i++; + } + + notmuch_filenames_destroy (filenames); + + return i; +} + +static int do_search_messages (search_options_t *opt) { notmuch_message_t *message; @@ -357,10 +375,13 @@ do_search_messages (search_options_t *opt) notmuch_filenames_destroy( filenames ); } else if (opt->output == OUTPUT_MESSAGES) { - format->set_prefix (format, "id"); - format->string (format, - notmuch_message_get_message_id (message)); - format->separator (format); + /* special case 1 for speed */ + if (opt->dupe <= 1 || opt->dupe <= _count_filenames (message)) { + format->set_prefix (format, "id"); + format->string (format, + notmuch_message_get_message_id (message)); + format->separator (format); + } } else { if (opt->output & OUTPUT_SENDER) { const char *addrs; @@ -503,6 +524,12 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) if (! opt.output) opt.output = OUTPUT_SUMMARY; + if (opt.output != OUTPUT_FILES && opt.output != OUTPUT_MESSAGES && + opt.dupe != -1) { + fprintf (stderr, "Error: --duplicate=N is only supported with --output=files and --output=messages.\n"); + return EXIT_FAILURE; + } + switch (format_sel) { case NOTMUCH_FORMAT_TEXT: opt.format = sprinter_text_create (config, stdout); |
