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 2F8AA429E35 for ; Fri, 24 Oct 2014 01:48:30 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.699 X-Spam-Level: X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7, UNPARSEABLE_RELAY=0.001] 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 LlRI0j5+cJ+R for ; Fri, 24 Oct 2014 01:48:22 -0700 (PDT) Received: from mail-wg0-f50.google.com (mail-wg0-f50.google.com [74.125.82.50]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 79AD7431FD8 for ; Fri, 24 Oct 2014 01:48:14 -0700 (PDT) Received: by mail-wg0-f50.google.com with SMTP id a1so586860wgh.21 for ; Fri, 24 Oct 2014 01:48:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:user-agent:from:to:subject:date:message-id :in-reply-to:references; bh=WOabpojA0ZyiQ3501Wf2/8Oh2cBz/sxCFHVCk7aVLrg=; b=LeHlT5cXPz6UPlMcge30eqU3xtBv+fRVMbLXsTmr0tN5UhZEvv/4iq2nSLEUdHZUgY +F2TxGdD0C3stdFFDWU4IsZDPigZlQWFQWj7uaLHHT6o6XoQpjK54qqI1SqGce678w4y orQMl6feVtXanQhdhW/X8g8jOly251e2fwzf5MGLgTDflt9Be/h6iZxfA7ASCsmM1Nfv o774eB/kLYkxlnBna8yv6rhDU072KZM/KwLJ6fLcnT7KGnp3p9lb7GzunjThiqWD/AbL zcfx9TC99zTINO4J1DngrL35IjnG24Ii8iwbBHTLrmkmHWS3aJnKu9DhM+iDfbDhbmAk 5Sew== X-Gm-Message-State: ALoCoQnYdm/N7iBEL6wWpB69pXli1iq22Qya4Hf53V5tU7mpWVpHAIoIv7sjvBJJGYlp+62tFu6S X-Received: by 10.180.79.228 with SMTP id m4mr2631132wix.26.1414140491848; Fri, 24 Oct 2014 01:48:11 -0700 (PDT) Received: from disaster-area.hh.sledj.net (disaster-area.hh.sledj.net. [81.149.164.25]) by mx.google.com with ESMTPSA id wt3sm4840424wjb.40.2014.10.24.01.48.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Oct 2014 01:48:11 -0700 (PDT) Received: from localhost (30000@localhost [local]); by localhost (OpenSMTPD) with ESMTPA id ff3c1fde; for ; Fri, 24 Oct 2014 08:48:08 +0000 (UTC) User-Agent: OpenSMTPD enqueuer (Demoostik) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH v1 1/3] search: Seperately report matching and non-matching authors. Date: Fri, 24 Oct 2014 09:48:06 +0100 Message-Id: <1414140488-29978-2-git-send-email-dme@dme.org> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1414140488-29978-1-git-send-email-dme@dme.org> References: <1414140488-29978-1-git-send-email-dme@dme.org> 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: Fri, 24 Oct 2014 08:48:30 -0000 In addition to the :authors attribute of each search result, include :authors_matched and :authors_non_matched attributes. Both attributes are always included. If there are no non-matching authors, the :authors_non_matched attribute is set to the empty string. --- lib/notmuch.h | 34 ++++++++++++++++++++++++++++++++ lib/thread.cc | 60 +++++++++++++++++++++++++++++++++++++++----------------- notmuch-search.c | 6 ++++++ 3 files changed, 82 insertions(+), 18 deletions(-) diff --git a/lib/notmuch.h b/lib/notmuch.h index dae0416..30ce6c3 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -993,6 +993,40 @@ const char * notmuch_thread_get_authors (notmuch_thread_t *thread); /** + * Get the matched authors of 'thread' as a UTF-8 string. + * + * The returned string is a comma-separated list of the names of the + * authors of mail messages in the query results that belong to this + * thread. + * + * Authors are ordered by date. + * + * The returned string belongs to 'thread' and as such, should not be + * modified by the caller and will only be valid for as long as the + * thread is valid, (which is until notmuch_thread_destroy or until + * the query from which it derived is destroyed). + */ +const char * +notmuch_thread_get_authors_matched (notmuch_thread_t *thread); + +/** + * Get the non-matched authors of 'thread' as a UTF-8 string. + * + * The returned string is a comma-separated list of the names of the + * authors of mail messages in the query results that belong to this + * thread. + * + * Authors are ordered by date. + * + * The returned string belongs to 'thread' and as such, should not be + * modified by the caller and will only be valid for as long as the + * thread is valid, (which is until notmuch_thread_destroy or until + * the query from which it derived is destroyed). + */ +const char * +notmuch_thread_get_authors_non_matched (notmuch_thread_t *thread); + +/** * Get the subject of 'thread' as a UTF-8 string. * * The subject is taken from the first message (according to the query diff --git a/lib/thread.cc b/lib/thread.cc index 8922403..b344875 100644 --- a/lib/thread.cc +++ b/lib/thread.cc @@ -33,6 +33,8 @@ struct visible _notmuch_thread { GHashTable *matched_authors_hash; GPtrArray *matched_authors_array; char *authors; + char *authors_matched; + char *authors_non_matched; GHashTable *tags; /* All messages, oldest first. */ @@ -112,10 +114,11 @@ _thread_add_matched_author (notmuch_thread_t *thread, g_ptr_array_add (thread->matched_authors_array, author_copy); } -/* Construct an authors string from matched_authors_array and - * authors_array. The string contains matched authors first, then - * non-matched authors (with the two groups separated by '|'). Within - * each group, authors are listed in date order. */ +/* Construct the authors_matched, authors_non_matched and authors + * strings from matched_authors_array and authors_array. The authors + * string contains matched authors first, then non-matched authors + * (with the two groups separated by '|'). Within each group, authors + * are listed in date order. */ static void _resolve_thread_authors_string (notmuch_thread_t *thread) { @@ -123,36 +126,43 @@ _resolve_thread_authors_string (notmuch_thread_t *thread) char *author; int first_non_matched_author = 1; - /* First, list all matched authors in date order. */ + /* List all matched authors in date order. */ for (i = 0; i < thread->matched_authors_array->len; i++) { author = (char *) g_ptr_array_index (thread->matched_authors_array, i); - if (thread->authors) - thread->authors = talloc_asprintf (thread, "%s, %s", - thread->authors, - author); - else - thread->authors = author; + if (thread->authors_matched) { + thread->authors_matched = talloc_asprintf (thread, "%s, %s", + thread->authors_matched, + author); + } else { + thread->authors_matched = author; + } } - /* Next, append any non-matched authors that haven't already appeared. */ + /* List any non-matched authors that haven't already appeared. */ for (i = 0; i < thread->authors_array->len; i++) { author = (char *) g_ptr_array_index (thread->authors_array, i); if (g_hash_table_lookup_extended (thread->matched_authors_hash, author, NULL, NULL)) continue; if (first_non_matched_author) { - thread->authors = talloc_asprintf (thread, "%s| %s", - thread->authors, - author); + thread->authors_non_matched = author; } else { - thread->authors = talloc_asprintf (thread, "%s, %s", - thread->authors, - author); + thread->authors_non_matched = talloc_asprintf (thread, "%s, %s", + thread->authors_non_matched, + author); } first_non_matched_author = 0; } + /* List both matched and any non-matched authors. */ + if (thread->authors_non_matched) + thread->authors = talloc_asprintf (thread, "%s| %s", + thread->authors_matched, + thread->authors_non_matched); + else + thread->authors = thread->authors_matched; + g_ptr_array_free (thread->authors_array, TRUE); thread->authors_array = NULL; g_ptr_array_free (thread->matched_authors_array, TRUE); @@ -473,6 +483,8 @@ _notmuch_thread_create (void *ctx, NULL, NULL); thread->matched_authors_array = g_ptr_array_new (); thread->authors = NULL; + thread->authors_matched = NULL; + thread->authors_non_matched = NULL; thread->tags = g_hash_table_new_full (g_str_hash, g_str_equal, free, NULL); @@ -568,6 +580,18 @@ notmuch_thread_get_authors (notmuch_thread_t *thread) } const char * +notmuch_thread_get_authors_matched (notmuch_thread_t *thread) +{ + return thread->authors_matched; +} + +const char * +notmuch_thread_get_authors_non_matched (notmuch_thread_t *thread) +{ + return thread->authors_non_matched; +} + +const char * notmuch_thread_get_subject (notmuch_thread_t *thread) { return thread->subject; diff --git a/notmuch-search.c b/notmuch-search.c index bc9be45..f1b096d 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -114,6 +114,8 @@ do_search_threads (sprinter_t *format, } else { /* output == OUTPUT_SUMMARY */ void *ctx_quote = talloc_new (thread); const char *authors = notmuch_thread_get_authors (thread); + const char *authors_matched = notmuch_thread_get_authors_matched (thread); + const char *authors_non_matched = notmuch_thread_get_authors_non_matched (thread); const char *subject = notmuch_thread_get_subject (thread); const char *thread_id = notmuch_thread_get_thread_id (thread); int matched = notmuch_thread_get_matched_messages (thread); @@ -152,6 +154,10 @@ do_search_threads (sprinter_t *format, format->integer (format, total); format->map_key (format, "authors"); format->string (format, authors); + format->map_key (format, "authors_matched"); + format->string (format, authors_matched); + format->map_key (format, "authors_non_matched"); + format->string (format, authors_non_matched); format->map_key (format, "subject"); format->string (format, subject); if (notmuch_format_version >= 2) { -- 2.1.1