From 8b0087b0be97a4ffb41973d45f18c5b4f945a7b9 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Sat, 6 Sep 2014 19:47:36 +0300 Subject: [PATCH] Re: [PATCH] cli: add --output=address-{from, to, all} to notmuch search --- df/179d1677580d73200c49877d74536b21ae38c6 | 279 ++++++++++++++++++++++ 1 file changed, 279 insertions(+) create mode 100644 df/179d1677580d73200c49877d74536b21ae38c6 diff --git a/df/179d1677580d73200c49877d74536b21ae38c6 b/df/179d1677580d73200c49877d74536b21ae38c6 new file mode 100644 index 000000000..fa5aec962 --- /dev/null +++ b/df/179d1677580d73200c49877d74536b21ae38c6 @@ -0,0 +1,279 @@ +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 1209E431FB6 + for ; Sat, 6 Sep 2014 09:47:48 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[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 0F6Ririxd--E for ; + Sat, 6 Sep 2014 09:47:40 -0700 (PDT) +Received: from mail-wg0-f51.google.com (mail-wg0-f51.google.com + [74.125.82.51]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client + certificate requested) by olra.theworths.org (Postfix) with ESMTPS id + 190EA431FAE for ; Sat, 6 Sep 2014 09:47:39 -0700 + (PDT) +Received: by mail-wg0-f51.google.com with SMTP id l18so12841023wgh.34 + for ; Sat, 06 Sep 2014 09:47:38 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:subject:in-reply-to:references + :user-agent:date:message-id:mime-version:content-type; + bh=6cFxVmVfVaxKfehvTfSkBc7oNdUMKCj9dVmcFahuLjI=; + b=aK1ZxxykiG2sV804zrEd8mDIZDXLY/Jj8GnS5vzAa50M021D1qEyAOybcQ+oz2JuFw + xloCBdMlrRc6Wi2HWcCAtGIHxRM/ugLL/dwCRSz0/Ka6eNuufX/FIpF7/lUB25VT8B7f + OYJR/U1wRAN3bL9RycudzK5Ml+4B5lJFFHWajDy+5T/DZeRdg6u9MLQbOEwqh5CjWZuJ + lsfPXtevVlxt0ylX9TxAZtPlJ4GV9EHNEKBePUAcJ9hL5ucoxW3oMP8xa9O/UKDYuWST + MWiPj+X6B6n9zk0Q8Gj7/UH3C2dLtBnYoRaNRBvkl7Ch6soS+K7H7xKbvTuU01sW+B6X + LXeg== +X-Gm-Message-State: + ALoCoQnt59mUA6+6WHmLa3E8EXmQDnGq60rKPO6C1u4dEAbZAfazseCddW4BYUuZZPFVXsdEemmG +X-Received: by 10.195.13.34 with SMTP id ev2mr21723821wjd.55.1410022057770; + Sat, 06 Sep 2014 09:47:37 -0700 (PDT) +Received: from localhost (dsl-hkibrasgw2-58c374-75.dhcp.inet.fi. + [88.195.116.75]) + by mx.google.com with ESMTPSA id pn5sm5065005wjc.4.2014.09.06.09.47.36 + for + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Sat, 06 Sep 2014 09:47:37 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: Re: [PATCH] cli: add --output=address-{from, to, + all} to notmuch search +In-Reply-To: <1410021689-15901-1-git-send-email-jani@nikula.org> +References: <871troub1v.fsf@qmul.ac.uk> + <1410021689-15901-1-git-send-email-jani@nikula.org> +User-Agent: Notmuch/0.18.1+65~g9f0f30f (http://notmuchmail.org) Emacs/24.3.1 + (x86_64-pc-linux-gnu) +Date: Sat, 06 Sep 2014 19:47:36 +0300 +Message-ID: <8738c41ys7.fsf@nikula.org> +MIME-Version: 1.0 +Content-Type: text/plain +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 16:47:48 -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. + +*sigh* this was supposed to be: + +--- + +cli: add --output=sender and --output=recipients to notmuch search + +sender prints from, recipients prints to, cc, and bcc. + +--- + +I don't have the time for this, and I'm rushing too much... + + +BR, +Jani. + + + +> --- +> notmuch-search.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++----- +> 1 file changed, 100 insertions(+), 9 deletions(-) +> +> diff --git a/notmuch-search.c b/notmuch-search.c +> index bc9be4593ecc..e7cf3d2a0fdf 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_SENDER = 1 << 5, +> + OUTPUT_RECIPIENTS = 1 << 6, +> + OUTPUT_ADDRESSES = OUTPUT_SENDER | OUTPUT_RECIPIENTS, +> } 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,29 @@ 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_SENDER) { +> + const char *addrs; +> + +> + addrs = notmuch_message_get_header (message, "from"); +> + print_address_string (format, addrs); +> + } +> + +> + if (output & OUTPUT_RECIPIENTS) { +> + 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 +419,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 +445,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 }, +> + { "sender", OUTPUT_SENDER }, +> + { "recipients", OUTPUT_RECIPIENTS }, +> { "files", OUTPUT_FILES }, +> { "tags", OUTPUT_TAGS }, +> { 0, 0 } } }, +> @@ -387,6 +470,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 +539,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_SENDER: +> + case OUTPUT_RECIPIENTS: +> + case OUTPUT_ADDRESSES: +> 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 -- 2.26.2