--- /dev/null
+Return-Path: <tomi.ollila@iki.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 13E5E431FD8\r
+ for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 02:38:50 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id nJf74m1qpBbu for <notmuch@notmuchmail.org>;\r
+ Fri, 24 Oct 2014 02:38:41 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id A9723431FBD\r
+ for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 02:38:40 -0700 (PDT)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+ by guru.guru-group.fi (Postfix) with ESMTP id 8F83110008C;\r
+ Fri, 24 Oct 2014 12:38:18 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Mark Walters <markwalters1009@gmail.com>,\r
+ Michal Sojka <sojkam1@fel.cvut.cz>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v3 3/4] cli: Extend the search command\r
+ for --output={sender, recipients}\r
+In-Reply-To: <87egtzazs8.fsf@qmul.ac.uk>\r
+References: <87zjd51phx.fsf@steelpick.2x.cz>\r
+ <1413150093-8383-1-git-send-email-sojkam1@fel.cvut.cz>\r
+ <1413150093-8383-4-git-send-email-sojkam1@fel.cvut.cz>\r
+ <87egtzazs8.fsf@qmul.ac.uk>\r
+User-Agent: Notmuch/0.18.1+130~ga61922f (http://notmuchmail.org) Emacs/24.3.1\r
+ (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+ $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+ !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Fri, 24 Oct 2014 12:38:18 +0300\r
+Message-ID: <m2bnp1erjp.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Transfer-Encoding: quoted-printable\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 24 Oct 2014 09:38:50 -0000\r
+\r
+On Thu, Oct 23 2014, Mark Walters <markwalters1009@gmail.com> wrote:\r
+\r
+> On Sun, 12 Oct 2014, Michal Sojka <sojkam1@fel.cvut.cz> wrote:\r
+>> The new outputs allow printing senders, recipients or both of matching\r
+>> messages. The --output option is converted from "keyword" argument to\r
+>> "flags" argument, which means that the user can use --output=3Dsender and\r
+>> --output=3Drecipients simultaneously, to print both. Other combinations\r
+>> produce an error.\r
+>>\r
+>> ...\r
+>>\r
+>> +static void\r
+>> +print_address_list (const search_options_t *o, InternetAddressList *lis=\r
+t)\r
+>> +{\r
+>> + InternetAddress *address;\r
+>> + int i;\r
+>> +\r
+>> + for (i =3D 0; i < internet_address_list_length (list); i++) {\r
+>> + address =3D internet_address_list_get_address (list, i);\r
+>> + if (INTERNET_ADDRESS_IS_GROUP (address)) {\r
+>> + InternetAddressGroup *group;\r
+>> + InternetAddressList *group_list;\r
+>> +\r
+>> + group =3D INTERNET_ADDRESS_GROUP (address);\r
+>> + group_list =3D internet_address_group_get_members (group);\r
+>> + if (group_list =3D=3D NULL)\r
+>> + continue;\r
+>> +\r
+>> + print_address_list (o, group_list);\r
+>> + } else {\r
+>> + InternetAddressMailbox *mailbox;\r
+>> + const char *name;\r
+>> + const char *addr;\r
+>> + char *full_address;\r
+>> +\r
+>> + mailbox =3D INTERNET_ADDRESS_MAILBOX (address);\r
+>> +\r
+>> + name =3D internet_address_get_name (address);\r
+>> + addr =3D internet_address_mailbox_get_addr (mailbox);\r
+>> +\r
+>> + if (name && *name)\r
+>> + full_address =3D talloc_asprintf (o->format, "%s <%s>", name, addr);\r
+>> + else\r
+>> + full_address =3D talloc_strdup (o->format, addr);\r
+>> +\r
+>> + if (!full_address) {\r
+>> + fprintf (stderr, "Error: out of memory\n");\r
+>> + break;\r
+>> + }\r
+>> + o->format->string (o->format, full_address);\r
+>> + o->format->separator (o->format);\r
+>> +\r
+>> + talloc_free (full_address);\r
+>\r
+> Thinking about this some more how about printing the name and address as\r
+> a structured pair/map (at least for all cases except text/text0 output):\r
+> something like (in JSON)\r
+> [name: "John Doe" address: "john.doe@example.com"]\r
+>\r
+> It seems wrong to me to go to the effort of separating them in the C and\r
+> then combining them in the output.\r
+>\r
+> This could also help with the questions about uniqueness. If the client\r
+> can get the data ready parsed into name/address then it can deal with\r
+> much of the uniqueness itself.\r
+\r
+In that case client can also filter based on some substring, reducing the\r
+memory requirements...\r
+\r
+>\r
+> My preference would be for the default to print one line for each\r
+> distinct full_address, and then any filter-by options to refine from\r
+> there.\r
+\r
+Hmm, now I cannot decide whether this or just print out all addresses of\r
+messages, or do this distinct full_address output -- it looks like all\r
+other --output options prints unique lines, but there is potential of=20\r
+quite a lot of memory usage there...\r
+\r
+... probably the memory usage is not problem there, OOM-killer eventually\r
+does it's job if necessary (!) (but machine may be slow (and trashing) for\r
+a while (just thinking out loud))\r
+\r
+(!) but could we have general filter option for search to drop data before\r
+it is even considered for caching! -- maybe later ?\r
+\r
+\r
+> One other advantage of structuring the output is that it is extensible:\r
+> for example, at some later stage, we could include a "count" in the map\r
+> allowing the client can pick the most popular variant.\r
+\r
+, and in this case notmuch cannot print any output until the full address\r
+list is gathered... :D\r
+\r
+>\r
+> Best wishes\r
+>\r
+> Mark\r
+\r
+Tomi\r
+\r
+>\r
+>\r
+>\r
+>\r
+>> + }\r
+>> + }\r
+>> +}\r
+>> +\r
+>> +static void\r
+>> +print_address_string (const search_options_t *o, const char *recipients)\r
+>> +{\r
+>> + InternetAddressList *list;\r
+>> +\r
+>> + if (recipients =3D=3D NULL)\r
+>> + return;\r
+>> +\r
+>> + list =3D internet_address_list_parse_string (recipients);\r
+>> + if (list =3D=3D NULL)\r
+>> + return;\r
+>> +\r
+>> + print_address_list (o, list);\r
+>> +}\r
+>> +\r
+>> static int\r
+>> do_search_messages (search_options_t *o)\r
+>> {\r
+>> @@ -266,11 +330,29 @@ do_search_messages (search_options_t *o)\r
+>>=20=20=09=20=20=20=20\r
+>> notmuch_filenames_destroy( filenames );\r
+>>=20=20\r
+>> - } else { /* output =3D=3D OUTPUT_MESSAGES */\r
+>> + } else if (o->output =3D=3D OUTPUT_MESSAGES) {\r
+>> format->set_prefix (format, "id");\r
+>> format->string (format,\r
+>> notmuch_message_get_message_id (message));\r
+>> format->separator (format);\r
+>> + } else {\r
+>> + if (o->output & OUTPUT_SENDER) {\r
+>> + const char *addrs;\r
+>> +\r
+>> + addrs =3D notmuch_message_get_header (message, "from");\r
+>> + print_address_string (o, addrs);\r
+>> + }\r
+>> +\r
+>> + if (o->output & OUTPUT_RECIPIENTS) {\r
+>> + const char *hdrs[] =3D { "to", "cc", "bcc" };\r
+>> + const char *addrs;\r
+>> + size_t j;\r
+>> +\r
+>> + for (j =3D 0; j < ARRAY_SIZE (hdrs); j++) {\r
+>> + addrs =3D notmuch_message_get_header (message, hdrs[j]);\r
+>> + print_address_string (o, addrs);\r
+>> + }\r
+>> + }\r
+>> }\r
+>>=20=20\r
+>> notmuch_message_destroy (message);\r
+>> @@ -337,7 +419,7 @@ notmuch_search_command (notmuch_config_t *config, in=\r
+t argc, char *argv[])\r
+>> notmuch_database_t *notmuch;\r
+>> search_options_t o =3D {\r
+>> .sort =3D NOTMUCH_SORT_NEWEST_FIRST,\r
+>> - .output =3D OUTPUT_SUMMARY,\r
+>> + .output =3D 0,\r
+>> .offset =3D 0,\r
+>> .limit =3D -1, /* unlimited */\r
+>> .dupe =3D -1,\r
+>> @@ -366,10 +448,12 @@ notmuch_search_command (notmuch_config_t *config, =\r
+int argc, char *argv[])\r
+>> { "text0", NOTMUCH_FORMAT_TEXT0 },\r
+>> { 0, 0 } } },\r
+>> { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 },\r
+>> - { NOTMUCH_OPT_KEYWORD, &o.output, "output", 'o',\r
+>> + { NOTMUCH_OPT_KEYWORD_FLAGS, &o.output, "output", 'o',\r
+>> (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },\r
+>> { "threads", OUTPUT_THREADS },\r
+>> { "messages", OUTPUT_MESSAGES },\r
+>> + { "sender", OUTPUT_SENDER },\r
+>> + { "recipients", OUTPUT_RECIPIENTS },\r
+>> { "files", OUTPUT_FILES },\r
+>> { "tags", OUTPUT_TAGS },\r
+>> { 0, 0 } } },\r
+>> @@ -389,6 +473,9 @@ notmuch_search_command (notmuch_config_t *config, in=\r
+t argc, char *argv[])\r
+>> if (opt_index < 0)\r
+>> return EXIT_FAILURE;\r
+>>=20=20\r
+>> + if (! o.output)\r
+>> + o.output =3D OUTPUT_SUMMARY;\r
+>> +\r
+>> switch (format_sel) {\r
+>> case NOTMUCH_FORMAT_TEXT:\r
+>> o.format =3D sprinter_text_create (config, stdout);\r
+>> @@ -455,18 +542,23 @@ notmuch_search_command (notmuch_config_t *config, =\r
+int argc, char *argv[])\r
+>> }\r
+>>=20=20\r
+>> switch (o.output) {\r
+>> - default:\r
+>> case OUTPUT_SUMMARY:\r
+>> case OUTPUT_THREADS:\r
+>> ret =3D do_search_threads (&o);\r
+>> break;\r
+>> case OUTPUT_MESSAGES:\r
+>> + case OUTPUT_SENDER:\r
+>> + case OUTPUT_RECIPIENTS:\r
+>> + case OUTPUT_ADDRESSES:\r
+>> case OUTPUT_FILES:\r
+>> ret =3D do_search_messages (&o);\r
+>> break;\r
+>> case OUTPUT_TAGS:\r
+>> ret =3D do_search_tags (notmuch, o.format, o.query);\r
+>> break;\r
+>> + default:\r
+>> + fprintf (stderr, "Error: the combination of outputs is not supported.\=\r
+n");\r
+>> + ret =3D 1;\r
+>> }\r
+>>=20=20\r
+>> notmuch_query_destroy (o.query);\r
+>> diff --git a/test/T090-search-output.sh b/test/T090-search-output.sh\r
+>> index 947d572..e696c01 100755\r
+>> --- a/test/T090-search-output.sh\r
+>> +++ b/test/T090-search-output.sh\r
+>> @@ -387,6 +387,70 @@ cat <<EOF >EXPECTED\r
+>> EOF\r
+>> test_expect_equal_file OUTPUT EXPECTED\r
+>>=20=20\r
+>> +test_begin_subtest "--output=3Dsender"\r
+>> +notmuch search --output=3Dsender '*' | sort | uniq --count >OUTPUT\r
+>> +cat <<EOF >EXPECTED\r
+>> + 1 Adrian Perez de Castro <aperez@igalia.com>\r
+>> + 2 Alex Botero-Lowry <alex.boterolowry@gmail.com>\r
+>> + 4 Alexander Botero-Lowry <alex.boterolowry@gmail.com>\r
+>> + 1 Aron Griffis <agriffis@n01se.net>\r
+>> + 12 Carl Worth <cworth@cworth.org>\r
+>> + 1 Chris Wilson <chris@chris-wilson.co.uk>\r
+>> + 1 Fran=C3=A7ois Boulogne <boulogne.f@gmail.com>\r
+>> + 1 Ingmar Vanhassel <ingmar@exherbo.org>\r
+>> + 1 Israel Herraiz <isra@herraiz.org>\r
+>> + 4 Jan Janak <jan@ryngle.com>\r
+>> + 2 Jjgod Jiang <gzjjgod@gmail.com>\r
+>> + 7 Keith Packard <keithp@keithp.com>\r
+>> + 5 Lars Kellogg-Stedman <lars@seas.harvard.edu>\r
+>> + 5 Mikhail Gusarov <dottedmag@dottedmag.net>\r
+>> + 1 Olivier Berger <olivier.berger@it-sudparis.eu>\r
+>> + 1 Rolland Santimano <rollandsantimano@yahoo.com>\r
+>> + 3 Stewart Smith <stewart@flamingspork.com>\r
+>> +EOF\r
+>> +test_expect_equal_file OUTPUT EXPECTED\r
+>> +\r
+>> +test_begin_subtest "--output=3Drecipients"\r
+>> +notmuch search --output=3Drecipients '*' | sort | uniq --count >OUTPUT\r
+>> +cat <<EOF >EXPECTED\r
+>> + 1 Allan McRae <allan@archlinux.org>\r
+>> + 1 Discussion about the Arch User Repository (AUR) <aur-general@ar=\r
+chlinux.org>\r
+>> + 1 Keith Packard <keithp@keithp.com>\r
+>> + 1 Mikhail Gusarov <dottedmag@dottedmag.net>\r
+>> + 2 notmuch <notmuch@notmuchmail.org>\r
+>> + 48 notmuch@notmuchmail.org\r
+>> + 1 olivier.berger@it-sudparis.eu\r
+>> +EOF\r
+>> +test_expect_equal_file OUTPUT EXPECTED\r
+>> +\r
+>> +test_begin_subtest "--output=3Dsender --output=3Drecipients"\r
+>> +notmuch search --output=3Dsender --output=3Drecipients '*' | sort | uni=\r
+q --count >OUTPUT\r
+>> +cat <<EOF >EXPECTED\r
+>> + 1 Adrian Perez de Castro <aperez@igalia.com>\r
+>> + 2 Alex Botero-Lowry <alex.boterolowry@gmail.com>\r
+>> + 4 Alexander Botero-Lowry <alex.boterolowry@gmail.com>\r
+>> + 1 Allan McRae <allan@archlinux.org>\r
+>> + 1 Aron Griffis <agriffis@n01se.net>\r
+>> + 12 Carl Worth <cworth@cworth.org>\r
+>> + 1 Chris Wilson <chris@chris-wilson.co.uk>\r
+>> + 1 Discussion about the Arch User Repository (AUR) <aur-general@ar=\r
+chlinux.org>\r
+>> + 1 Fran=C3=A7ois Boulogne <boulogne.f@gmail.com>\r
+>> + 1 Ingmar Vanhassel <ingmar@exherbo.org>\r
+>> + 1 Israel Herraiz <isra@herraiz.org>\r
+>> + 4 Jan Janak <jan@ryngle.com>\r
+>> + 2 Jjgod Jiang <gzjjgod@gmail.com>\r
+>> + 8 Keith Packard <keithp@keithp.com>\r
+>> + 5 Lars Kellogg-Stedman <lars@seas.harvard.edu>\r
+>> + 6 Mikhail Gusarov <dottedmag@dottedmag.net>\r
+>> + 1 Olivier Berger <olivier.berger@it-sudparis.eu>\r
+>> + 1 Rolland Santimano <rollandsantimano@yahoo.com>\r
+>> + 3 Stewart Smith <stewart@flamingspork.com>\r
+>> + 2 notmuch <notmuch@notmuchmail.org>\r
+>> + 48 notmuch@notmuchmail.org\r
+>> + 1 olivier.berger@it-sudparis.eu\r
+>> +EOF\r
+>> +test_expect_equal_file OUTPUT EXPECTED\r
+>> +\r
+>> test_begin_subtest "sanitize output for quoted-printable line-breaks in=\r
+ author and subject"\r
+>> add_message "[subject]=3D'two =3D?ISO-8859-1?Q?line=3D0A_subject?=3D\r
+>> headers'"\r
+>> --=20\r
+>> 2.1.1\r
+>>\r
+>> _______________________________________________\r
+>> notmuch mailing list\r
+>> notmuch@notmuchmail.org\r
+>> http://notmuchmail.org/mailman/listinfo/notmuch\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r