From 235d11e11eeafb14bb4ed4fe7d5d501b37657dfd Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Sat, 6 Sep 2014 14:35:08 +0100 Subject: [PATCH] Re: [PATCH 2/3] cli: add --output=address-{from, to, all} to notmuch search --- fc/cc9f21025a348d99ed3139f916c4d4dabdfb1d | 292 ++++++++++++++++++++++ 1 file changed, 292 insertions(+) create mode 100644 fc/cc9f21025a348d99ed3139f916c4d4dabdfb1d diff --git a/fc/cc9f21025a348d99ed3139f916c4d4dabdfb1d b/fc/cc9f21025a348d99ed3139f916c4d4dabdfb1d new file mode 100644 index 000000000..ad6ac2f29 --- /dev/null +++ b/fc/cc9f21025a348d99ed3139f916c4d4dabdfb1d @@ -0,0 +1,292 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 0A2A2431FBC + for ; Sat, 6 Sep 2014 06:35:41 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0.502 +X-Spam-Level: +X-Spam-Status: No, score=0.502 tagged_above=-999 required=5 + tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, + NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 2vkJ5eYmkch4 for ; + Sat, 6 Sep 2014 06:35:32 -0700 (PDT) +Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 90464431FB6 + for ; Sat, 6 Sep 2014 06:35:32 -0700 (PDT) +Received: from smtp.qmul.ac.uk ([138.37.6.40]) + by mail2.qmul.ac.uk with esmtp (Exim 4.71) + (envelope-from ) + id 1XQG90-000444-30; Sat, 06 Sep 2014 14:35:30 +0100 +Received: from 5751dfa2.skybroadband.com ([87.81.223.162] helo=localhost) + by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71) + (envelope-from ) + id 1XQG8z-000296-NT; Sat, 06 Sep 2014 14:35:09 +0100 +From: Mark Walters +To: Jani Nikula , notmuch@notmuchmail.org +Subject: Re: [PATCH 2/3] cli: add --output=address-{from, to, + all} to notmuch search +In-Reply-To: <1410008010-3770-2-git-send-email-jani@nikula.org> +References: <1410008010-3770-1-git-send-email-jani@nikula.org> + <1410008010-3770-2-git-send-email-jani@nikula.org> +User-Agent: Notmuch/0.18.1+86~gef5e66a (http://notmuchmail.org) Emacs/23.4.1 + (x86_64-pc-linux-gnu) +Date: Sat, 06 Sep 2014 14:35:08 +0100 +Message-ID: <871troub1v.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Sender-Host-Address: 87.81.223.162 +X-QM-Geographic: According to ripencc, + this message was delivered by a machine in Britain (UK) (GB). +X-QM-SPAM-Info: Sender has good ham record. :) +X-QM-Body-MD5: fe3629b9ec387ce245e5d00924c2010d (of first 20000 bytes) +X-SpamAssassin-Score: -0.1 +X-SpamAssassin-SpamBar: / +X-SpamAssassin-Report: The QM spam filters have analysed this message to + determine if it is + spam. We require at least 5.0 points to mark a message as spam. + This message scored -0.1 points. + Summary of the scoring: + * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail + provider * (markwalters1009[at]gmail.com) + * -0.1 AWL AWL: From: address is in the auto white-list +X-QM-Scan-Virus: ClamAV says the message is clean +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sat, 06 Sep 2014 13:35:41 -0000 + +On Sat, 06 Sep 2014, Jani Nikula wrote: +> address-from prints reply-to or from, address-to prints to, cc, and +> bcc, and address-all prints all of them. + +Hi + +I like these: thanks a lot for doing this. + +Just one quick comment before I do an actual review: + +> --- +> notmuch-search.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++----- +> 1 file changed, 104 insertions(+), 9 deletions(-) +> +> diff --git a/notmuch-search.c b/notmuch-search.c +> index bc9be4593ecc..c84ecc31262c 100644 +> --- a/notmuch-search.c +> +++ b/notmuch-search.c +> @@ -23,11 +23,14 @@ +> #include "string-util.h" +> +> typedef enum { +> - OUTPUT_SUMMARY, +> - OUTPUT_THREADS, +> - OUTPUT_MESSAGES, +> - OUTPUT_FILES, +> - OUTPUT_TAGS +> + OUTPUT_SUMMARY = 1 << 0, +> + OUTPUT_THREADS = 1 << 1, +> + OUTPUT_MESSAGES = 1 << 2, +> + OUTPUT_FILES = 1 << 3, +> + OUTPUT_TAGS = 1 << 4, +> + OUTPUT_ADDRESS_FROM = 1 << 5, +> + OUTPUT_ADDRESS_TO = 1 << 6, +> + OUTPUT_ADDRESS_ALL = OUTPUT_ADDRESS_FROM | OUTPUT_ADDRESS_TO, +> } output_t; +> +> /* Return two stable query strings that identify exactly the matched +> @@ -214,6 +217,66 @@ do_search_threads (sprinter_t *format, +> return 0; +> } +> +> +static void +> +print_address_list (sprinter_t *format, InternetAddressList *list) +> +{ +> + InternetAddress *address; +> + int i; +> + +> + for (i = 0; i < internet_address_list_length (list); i++) { +> + address = internet_address_list_get_address (list, i); +> + if (INTERNET_ADDRESS_IS_GROUP (address)) { +> + InternetAddressGroup *group; +> + InternetAddressList *group_list; +> + +> + group = INTERNET_ADDRESS_GROUP (address); +> + group_list = internet_address_group_get_members (group); +> + if (group_list == NULL) +> + continue; +> + +> + print_address_list (format, group_list); +> + } else { +> + InternetAddressMailbox *mailbox; +> + const char *name; +> + const char *addr; +> + char *full_address; +> + +> + mailbox = INTERNET_ADDRESS_MAILBOX (address); +> + +> + name = internet_address_get_name (address); +> + addr = internet_address_mailbox_get_addr (mailbox); +> + +> + if (name && *name) +> + full_address = talloc_asprintf (NULL, "%s <%s>", name, addr); +> + else +> + full_address = talloc_asprintf (NULL, "<%s>", addr); +> + +> + if (!full_address) +> + break; +> + +> + format->string (format, full_address); +> + format->separator (format); +> + +> + talloc_free (full_address); +> + } +> + } +> +} +> + +> +static void +> +print_address_string (sprinter_t *format, const char *recipients) +> +{ +> + InternetAddressList *list; +> + +> + if (recipients == NULL) +> + return; +> + +> + list = internet_address_list_parse_string (recipients); +> + if (list == NULL) +> + return; +> + +> + print_address_list (format, list); +> +} +> + +> static int +> do_search_messages (sprinter_t *format, +> notmuch_query_t *query, +> @@ -264,11 +327,33 @@ do_search_messages (sprinter_t *format, +> +> notmuch_filenames_destroy( filenames ); +> +> - } else { /* output == OUTPUT_MESSAGES */ +> + } else if (output == OUTPUT_MESSAGES) { +> format->set_prefix (format, "id"); +> format->string (format, +> notmuch_message_get_message_id (message)); +> format->separator (format); +> + } else { +> + if (output & OUTPUT_ADDRESS_FROM) { +> + const char *addrs; +> + +> + addrs = notmuch_message_get_header (message, "reply-to"); +> + +> + if (addrs == NULL || *addrs == '\0') +> + addrs = notmuch_message_get_header (message, "from"); + +I would suggest adding a separate address-reply-to option. The main +reason is that we store from in the database so if you do from without +the reply-to it is *very* fast whereas with the reply-to notmuch has to +read every message to get the reply-to header. Even on a fully hot cache +this means that from alone is a factor of 10 faster than reply-to/from. + +(If anyone wants to test this themselves just comment out the reply-to +and if lines above) + +Best wishes + +Mark + +> + +> + print_address_string (format, addrs); +> + } +> + +> + if (output & OUTPUT_ADDRESS_TO) { +> + const char *hdrs[] = { "to", "cc", "bcc" }; +> + const char *addrs; +> + size_t j; +> + +> + for (j = 0; j < ARRAY_SIZE (hdrs); j++) { +> + addrs = notmuch_message_get_header (message, hdrs[j]); +> + print_address_string (format, addrs); +> + } +> + } +> } +> +> notmuch_message_destroy (message); +> @@ -338,7 +423,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) +> notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST; +> sprinter_t *format = NULL; +> int opt_index, ret; +> - output_t output = OUTPUT_SUMMARY; +> + output_t output = 0; +> int offset = 0; +> int limit = -1; /* unlimited */ +> notmuch_exclude_t exclude = NOTMUCH_EXCLUDE_TRUE; +> @@ -364,10 +449,12 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) +> { "text0", NOTMUCH_FORMAT_TEXT0 }, +> { 0, 0 } } }, +> { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 }, +> - { NOTMUCH_OPT_KEYWORD, &output, "output", 'o', +> + { NOTMUCH_OPT_KEYWORD_FLAGS, &output, "output", 'o', +> (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY }, +> { "threads", OUTPUT_THREADS }, +> { "messages", OUTPUT_MESSAGES }, +> + { "address-from", OUTPUT_ADDRESS_FROM }, +> + { "address-to", OUTPUT_ADDRESS_TO }, +> { "files", OUTPUT_FILES }, +> { "tags", OUTPUT_TAGS }, +> { 0, 0 } } }, +> @@ -387,6 +474,9 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) +> if (opt_index < 0) +> return EXIT_FAILURE; +> +> + if (! output) +> + output = OUTPUT_SUMMARY; +> + +> switch (format_sel) { +> case NOTMUCH_FORMAT_TEXT: +> format = sprinter_text_create (config, stdout); +> @@ -453,18 +543,23 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) +> } +> +> switch (output) { +> - default: +> case OUTPUT_SUMMARY: +> case OUTPUT_THREADS: +> ret = do_search_threads (format, query, sort, output, offset, limit); +> break; +> case OUTPUT_MESSAGES: +> + case OUTPUT_ADDRESS_FROM: +> + case OUTPUT_ADDRESS_TO: +> + case OUTPUT_ADDRESS_ALL: +> case OUTPUT_FILES: +> ret = do_search_messages (format, query, output, offset, limit, dupe); +> break; +> case OUTPUT_TAGS: +> ret = do_search_tags (notmuch, format, query); +> break; +> + default: +> + fprintf (stderr, "Error: the combination of outputs is not supported.\n"); +> + ret = 1; +> } +> +> notmuch_query_destroy (query); +> -- +> 2.1.0 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2