X-Git-Url: http://rtime.felk.cvut.cz/gitweb/notmuch.git/blobdiff_plain/a5a6859197fb0b9cea7d75c4ec9377b9fc7d7285..0a416552aee2805937bf81eda5d05c70858016b1:/notmuch-search.c diff --git a/notmuch-search.c b/notmuch-search.c index 5036d8e4..8116cae8 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -43,6 +43,14 @@ typedef enum { NOTMUCH_FORMAT_SEXP } format_sel_t; +typedef enum { + FILTER_BY_NAMEADDR = 0, + FILTER_BY_NAME, + FILTER_BY_ADDR, + FILTER_BY_ADDRFOLD, + FILTER_BY_NAMEADDRFOLD, +} filter_by_t; + typedef struct { notmuch_database_t *notmuch; format_sel_t format_sel; @@ -55,6 +63,7 @@ typedef struct { int limit; int dupe; GHashTable *addresses; + filter_by_t filter_by; } search_context_t; typedef struct { @@ -243,16 +252,44 @@ do_search_threads (search_context_t *ctx) return 0; } -/* Returns TRUE iff name and addr is duplicate. If not, stores the - * name/addr pair in order to detect subsequent duplicates. */ +/* Returns TRUE iff name and/or addr is considered duplicate. If not, + * stores the name/addr pair in order to detect subsequent + * duplicates. */ static notmuch_bool_t is_duplicate (const search_context_t *ctx, const char *name, const char *addr) { notmuch_bool_t duplicate; char *key; + gchar *addrfold = NULL; mailbox_t *mailbox; - key = talloc_asprintf (ctx->format, "%s <%s>", name, addr); + if (ctx->filter_by == FILTER_BY_ADDRFOLD || + ctx->filter_by == FILTER_BY_NAMEADDRFOLD) + addrfold = g_utf8_casefold (addr, -1); + + switch (ctx->filter_by) { + case FILTER_BY_NAMEADDR: + key = talloc_asprintf (ctx->format, "%s <%s>", name, addr); + break; + case FILTER_BY_NAMEADDRFOLD: + key = talloc_asprintf (ctx->format, "%s <%s>", name, addrfold); + break; + case FILTER_BY_NAME: + key = talloc_strdup (ctx->format, name); /* !name results in !key */ + break; + case FILTER_BY_ADDR: + key = talloc_strdup (ctx->format, addr); + break; + case FILTER_BY_ADDRFOLD: + key = talloc_strdup (ctx->format, addrfold); + break; + default: + INTERNAL_ERROR("invalid --filter-by flags"); + } + + if (addrfold) + g_free (addrfold); + if (! key) return FALSE; @@ -727,16 +764,24 @@ notmuch_address_command (notmuch_config_t *config, int argc, char *argv[]) (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE }, { "false", NOTMUCH_EXCLUDE_FALSE }, { 0, 0 } } }, + { NOTMUCH_OPT_KEYWORD, &ctx->filter_by, "filter-by", 'b', + (notmuch_keyword_t []){ { "nameaddr", FILTER_BY_NAMEADDR }, + { "name", FILTER_BY_NAME }, + { "addr", FILTER_BY_ADDR }, + { "addrfold", FILTER_BY_ADDRFOLD }, + { "nameaddrfold", FILTER_BY_NAMEADDRFOLD }, + { 0, 0 } } }, { NOTMUCH_OPT_INHERIT, &common_options, NULL, 0, 0 }, { 0, 0, 0, 0, 0 } }; + ctx->filter_by = FILTER_BY_NAMEADDR, opt_index = parse_arguments (argc, argv, options, 1); if (opt_index < 0) return EXIT_FAILURE; - if (! ctx->output) - ctx->output = OUTPUT_SENDER | OUTPUT_RECIPIENTS; + if (! (ctx->output & (OUTPUT_SENDER | OUTPUT_RECIPIENTS))) + ctx->output |= OUTPUT_SENDER; if (_notmuch_search_prepare (ctx, config, argc - opt_index, argv + opt_index))