[PATCH v3 09/10] cli: address: Add --output=count
Michal Sojka writes: > This output prints how many times was each address encountered during > search. I pushed the first 9 patches, plus a fixup commit to actually build the man pages. Since this actually adds the summary line to the man page, please double check and suggest improvements if needed. d
[PATCH v3 09/10] cli: address: Add --output=count
On Wed, Nov 05 2014, Michal Sojka wrote: > This output prints how many times was each address encountered during > search. > --- > [ nn lines removed] > > ``--sort=``\ (**newest-first**\ \|\ **oldest-first**) > This option can be used to present results in either > chronological order (**oldest-first**) or reverse chronological > @@ -56,6 +63,8 @@ Supported options for **address** include > By default, results will be displayed in reverse chronological > order, (that is, the newest results will be displayed first). > > + This option has no effect when used with --output=count. This is not entirely true -- the order the addresses are gathered will affect how the hash table is built up and it may affect how the addresses are printed (unless the --sort option is ignored when --count is given, which does not seem to be the case). The question is whether the accuracy of this message matters; some nitpickers might complain ;) Anyway, +1 from me to patches 1 - 9 -- these things could still be adjusted when NEWS patch of the feature is prepared. Tomi
[PATCH v3 09/10] cli: address: Add --output=count
This output prints how many times was each address encountered during search. --- completion/notmuch-completion.bash | 2 +- completion/notmuch-completion.zsh | 2 +- doc/man1/notmuch-address.rst | 11 - notmuch-search.c | 49 -- test/T095-address.sh | 49 ++ 5 files changed, 103 insertions(+), 10 deletions(-) diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash index 94ea2d5..db152f3 100644 --- a/completion/notmuch-completion.bash +++ b/completion/notmuch-completion.bash @@ -332,7 +332,7 @@ _notmuch_address() return ;; --output) - COMPREPLY=( $( compgen -W "sender recipients" -- "${cur}" ) ) + COMPREPLY=( $( compgen -W "sender recipients count" -- "${cur}" ) ) return ;; --sort) diff --git a/completion/notmuch-completion.zsh b/completion/notmuch-completion.zsh index c606b75..8968562 100644 --- a/completion/notmuch-completion.zsh +++ b/completion/notmuch-completion.zsh @@ -61,7 +61,7 @@ _notmuch_address() { _arguments -s : \ '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \ -'--output=[select what to output]:output:((sender recipients))' +'--output=[select what to output]:output:((sender recipients count))' } _notmuch() diff --git a/doc/man1/notmuch-address.rst b/doc/man1/notmuch-address.rst index 01eb811..359616e 100644 --- a/doc/man1/notmuch-address.rst +++ b/doc/man1/notmuch-address.rst @@ -29,7 +29,7 @@ Supported options for **address** include intended for programs that invoke **notmuch(1)** internally. If omitted, the latest supported version will be used. -``--output=(sender|recipients)`` +``--output=(sender|recipients|count)`` Controls which information appears in the output. This option can be given multiple times to combine different outputs. @@ -48,6 +48,13 @@ Supported options for **address** include Output all addresses from the *To*, *Cc* and *Bcc* headers. + **count** + Print the count of how many times was the address + encountered during search. + + Note: With this option, addresses are printed only after + the whole search is finished. This may take long time. + ``--sort=``\ (**newest-first**\ \|\ **oldest-first**) This option can be used to present results in either chronological order (**oldest-first**) or reverse chronological @@ -56,6 +63,8 @@ Supported options for **address** include By default, results will be displayed in reverse chronological order, (that is, the newest results will be displayed first). + This option has no effect when used with --output=count. + ``--exclude=(true|false)`` A message is called "excluded" if it matches at least one tag in search.tag\_exclude that does not appear explicitly in the diff --git a/notmuch-search.c b/notmuch-search.c index 86d54ba..5036d8e 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -33,6 +33,7 @@ typedef enum { /* Address command */ OUTPUT_SENDER = 1 << 5, OUTPUT_RECIPIENTS = 1 << 6, +OUTPUT_COUNT = 1 << 7, } output_t; typedef enum { @@ -59,6 +60,7 @@ typedef struct { typedef struct { const char *name; const char *addr; +int count; } mailbox_t; /* Return two stable query strings that identify exactly the matched @@ -248,17 +250,24 @@ is_duplicate (const search_context_t *ctx, const char *name, const char *addr) { notmuch_bool_t duplicate; char *key; +mailbox_t *mailbox; key = talloc_asprintf (ctx->format, "%s <%s>", name, addr); if (! key) return FALSE; -duplicate = g_hash_table_lookup_extended (ctx->addresses, key, NULL, NULL); +duplicate = g_hash_table_lookup_extended (ctx->addresses, key, NULL, (gpointer)); -if (! duplicate) - g_hash_table_insert (ctx->addresses, key, NULL); -else +if (! duplicate) { + mailbox = talloc (ctx->format, mailbox_t); + mailbox->name = talloc_strdup (mailbox, name); + mailbox->addr = talloc_strdup (mailbox, addr); + mailbox->count = 1; + g_hash_table_insert (ctx->addresses, key, mailbox); +} else { + mailbox->count++; talloc_free (key); +} return duplicate; } @@ -268,6 +277,7 @@ print_mailbox (const search_context_t *ctx, const mailbox_t *mailbox) { const char *name = mailbox->name; const char *addr = mailbox->addr; +int count = mailbox->count; sprinter_t *format = ctx->format; InternetAddress *ia = internet_address_mailbox_new (name, addr); char *name_addr; @@ -277,6 +287,10 @@ print_mailbox (const search_context_t *ctx, const mailbox_t *mailbox) name_addr =
Re: [PATCH v3 09/10] cli: address: Add --output=count
On Wed, Nov 05 2014, Michal Sojka sojk...@fel.cvut.cz wrote: This output prints how many times was each address encountered during search. --- [ nn lines removed] ``--sort=``\ (**newest-first**\ \|\ **oldest-first**) This option can be used to present results in either chronological order (**oldest-first**) or reverse chronological @@ -56,6 +63,8 @@ Supported options for **address** include By default, results will be displayed in reverse chronological order, (that is, the newest results will be displayed first). + This option has no effect when used with --output=count. This is not entirely true -- the order the addresses are gathered will affect how the hash table is built up and it may affect how the addresses are printed (unless the --sort option is ignored when --count is given, which does not seem to be the case). The question is whether the accuracy of this message matters; some nitpickers might complain ;) Anyway, +1 from me to patches 1 - 9 -- these things could still be adjusted when NEWS patch of the feature is prepared. Tomi ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
Re: [PATCH v3 09/10] cli: address: Add --output=count
Michal Sojka sojk...@fel.cvut.cz writes: This output prints how many times was each address encountered during search. I pushed the first 9 patches, plus a fixup commit to actually build the man pages. Since this actually adds the summary line to the man page, please double check and suggest improvements if needed. d ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH v3 09/10] cli: address: Add --output=count
This output prints how many times was each address encountered during search. --- completion/notmuch-completion.bash | 2 +- completion/notmuch-completion.zsh | 2 +- doc/man1/notmuch-address.rst | 11 - notmuch-search.c | 49 -- test/T095-address.sh | 49 ++ 5 files changed, 103 insertions(+), 10 deletions(-) diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash index 94ea2d5..db152f3 100644 --- a/completion/notmuch-completion.bash +++ b/completion/notmuch-completion.bash @@ -332,7 +332,7 @@ _notmuch_address() return ;; --output) - COMPREPLY=( $( compgen -W sender recipients -- ${cur} ) ) + COMPREPLY=( $( compgen -W sender recipients count -- ${cur} ) ) return ;; --sort) diff --git a/completion/notmuch-completion.zsh b/completion/notmuch-completion.zsh index c606b75..8968562 100644 --- a/completion/notmuch-completion.zsh +++ b/completion/notmuch-completion.zsh @@ -61,7 +61,7 @@ _notmuch_address() { _arguments -s : \ '--sort=[sort results]:sorting:((newest-first\:reverse chronological order oldest-first\:chronological order))' \ -'--output=[select what to output]:output:((sender recipients))' +'--output=[select what to output]:output:((sender recipients count))' } _notmuch() diff --git a/doc/man1/notmuch-address.rst b/doc/man1/notmuch-address.rst index 01eb811..359616e 100644 --- a/doc/man1/notmuch-address.rst +++ b/doc/man1/notmuch-address.rst @@ -29,7 +29,7 @@ Supported options for **address** include intended for programs that invoke **notmuch(1)** internally. If omitted, the latest supported version will be used. -``--output=(sender|recipients)`` +``--output=(sender|recipients|count)`` Controls which information appears in the output. This option can be given multiple times to combine different outputs. @@ -48,6 +48,13 @@ Supported options for **address** include Output all addresses from the *To*, *Cc* and *Bcc* headers. + **count** + Print the count of how many times was the address + encountered during search. + + Note: With this option, addresses are printed only after + the whole search is finished. This may take long time. + ``--sort=``\ (**newest-first**\ \|\ **oldest-first**) This option can be used to present results in either chronological order (**oldest-first**) or reverse chronological @@ -56,6 +63,8 @@ Supported options for **address** include By default, results will be displayed in reverse chronological order, (that is, the newest results will be displayed first). + This option has no effect when used with --output=count. + ``--exclude=(true|false)`` A message is called excluded if it matches at least one tag in search.tag\_exclude that does not appear explicitly in the diff --git a/notmuch-search.c b/notmuch-search.c index 86d54ba..5036d8e 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -33,6 +33,7 @@ typedef enum { /* Address command */ OUTPUT_SENDER = 1 5, OUTPUT_RECIPIENTS = 1 6, +OUTPUT_COUNT = 1 7, } output_t; typedef enum { @@ -59,6 +60,7 @@ typedef struct { typedef struct { const char *name; const char *addr; +int count; } mailbox_t; /* Return two stable query strings that identify exactly the matched @@ -248,17 +250,24 @@ is_duplicate (const search_context_t *ctx, const char *name, const char *addr) { notmuch_bool_t duplicate; char *key; +mailbox_t *mailbox; key = talloc_asprintf (ctx-format, %s %s, name, addr); if (! key) return FALSE; -duplicate = g_hash_table_lookup_extended (ctx-addresses, key, NULL, NULL); +duplicate = g_hash_table_lookup_extended (ctx-addresses, key, NULL, (gpointer)mailbox); -if (! duplicate) - g_hash_table_insert (ctx-addresses, key, NULL); -else +if (! duplicate) { + mailbox = talloc (ctx-format, mailbox_t); + mailbox-name = talloc_strdup (mailbox, name); + mailbox-addr = talloc_strdup (mailbox, addr); + mailbox-count = 1; + g_hash_table_insert (ctx-addresses, key, mailbox); +} else { + mailbox-count++; talloc_free (key); +} return duplicate; } @@ -268,6 +277,7 @@ print_mailbox (const search_context_t *ctx, const mailbox_t *mailbox) { const char *name = mailbox-name; const char *addr = mailbox-addr; +int count = mailbox-count; sprinter_t *format = ctx-format; InternetAddress *ia = internet_address_mailbox_new (name, addr); char *name_addr; @@ -277,6 +287,10 @@ print_mailbox (const search_context_t *ctx, const mailbox_t *mailbox) name_addr = internet_address_to_string (ia, FALSE);