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 C4580421176 for ; Sun, 12 Feb 2012 10:49:03 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0.201 X-Spam-Level: X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, 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 hem2A18O-8EC for ; Sun, 12 Feb 2012 10:49:01 -0800 (PST) Received: from mail-we0-f181.google.com (mail-we0-f181.google.com [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 9DB50421174 for ; Sun, 12 Feb 2012 10:49:00 -0800 (PST) Received: by mail-we0-f181.google.com with SMTP id p13so3496132wer.26 for ; Sun, 12 Feb 2012 10:49:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=Gw+MTKJh76ZaxG2KE28nPs2RsTQV2hOnc94mLutAvYw=; b=XKa+i/FLAzW7W77g9jv4lXr9b9XwtA7+FjLu6OJZI2+27P6lbjv1xwS89AORKD7aHQ lecRCrno4SZCLyRpwYLZ4MPSTK1IpJuuNv+vvQifvVRzXo3UQ4r/fa0Mo4fClSPFqzin wyrYAh5/PtKgNXgbTmKyYnIH37U4XfipgHrcg= Received: by 10.180.101.165 with SMTP id fh5mr20092094wib.10.1329072540340; Sun, 12 Feb 2012 10:49:00 -0800 (PST) Received: from localhost (94-192-233-223.zone6.bethere.co.uk. [94.192.233.223]) by mx.google.com with ESMTPS id q7sm16745258wix.5.2012.02.12.10.48.58 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 12 Feb 2012 10:48:59 -0800 (PST) From: Mark Walters To: notmuch@notmuchmail.org Subject: [RFC PATCH v2 1/3] cli: notmuch-show changes to support pick Date: Sun, 12 Feb 2012 18:49:37 +0000 Message-Id: <1329072579-27340-2-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1329072579-27340-1-git-send-email-markwalters1009@gmail.com> References: <1329072579-27340-1-git-send-email-markwalters1009@gmail.com> 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: Sun, 12 Feb 2012 18:49:04 -0000 --- notmuch-client.h | 9 +++++- notmuch-show.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 88 insertions(+), 11 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index 60828aa..b4dc7bf 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -97,10 +97,17 @@ typedef struct notmuch_show_format { const char *message_set_end; } notmuch_show_format_t; +enum { + NOTMUCH_SHOW_THREAD_MATCH, + NOTMUCH_SHOW_THREAD_ENTIRE, + NOTMUCH_SHOW_THREAD_NONE +}; + typedef struct notmuch_show_params { - notmuch_bool_t entire_thread; + int entire_thread; notmuch_bool_t raw; int part; + int headers_only; #ifdef GMIME_ATLEAST_26 GMimeCryptoContext* cryptoctx; #else diff --git a/notmuch-show.c b/notmuch-show.c index d930f94..ec2b078 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -841,7 +841,7 @@ show_message (void *ctx, fputs (format->body_start, stdout); } - if (format->part_content) + if (format->part_content && !params->headers_only) show_message_body (message, format, params); if (params->part <= 0) { @@ -888,11 +888,16 @@ show_messages (void *ctx, fputs (format->message_set_sep, stdout); } - show_messages (ctx, - format, - notmuch_message_get_replies (message), - next_indent, - params); + if (params->entire_thread != NOTMUCH_SHOW_THREAD_NONE) + show_messages (ctx, + format, + notmuch_message_get_replies (message), + next_indent, + params); + else { + fputs (format->message_set_start, stdout); + fputs (format->message_set_end, stdout); + } notmuch_message_destroy (message); @@ -902,6 +907,50 @@ show_messages (void *ctx, fputs (format->message_set_end, stdout); } +static int +do_show_messages (void *ctx, + notmuch_query_t *query, + const notmuch_show_format_t *format, + notmuch_show_params_t *params) +{ + notmuch_messages_t *messages; + notmuch_message_t *message; + int first_set = 1; + + fputs (format->message_set_start, stdout); + messages = notmuch_query_search_messages (query); + + for (; + notmuch_messages_valid (messages); + notmuch_messages_move_to_next (messages)) + { + if (!first_set) + fputs (format->message_set_sep, stdout); + first_set = 0; + + fputs (format->message_set_start, stdout); + fputs (format->message_set_start, stdout); + + message = notmuch_messages_get (messages); + notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH, 1); + show_message (ctx, format, message, 0, params); + + fputs (format->message_set_sep, stdout); + + fputs (format->message_set_start, stdout); + fputs (format->message_set_end, stdout); + + + notmuch_message_destroy (message); + + fputs (format->message_set_end, stdout); + fputs (format->message_set_end, stdout); + } + + fputs (format->message_set_end, stdout); + return 0; +} + /* Formatted output of single message */ static int do_show_single (void *ctx, @@ -1029,11 +1078,13 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[])) notmuch_database_t *notmuch; notmuch_query_t *query; char *query_string; - int opt_index, ret; + int opt_index, ret, entire_thread; + notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST; const notmuch_show_format_t *format = &format_text; notmuch_show_params_t params = { .part = -1 }; int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED; notmuch_bool_t verify = FALSE; + notmuch_bool_t headers_only = FALSE; notmuch_opt_desc_t options[] = { { NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f', @@ -1042,10 +1093,19 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[])) { "mbox", NOTMUCH_FORMAT_MBOX }, { "raw", NOTMUCH_FORMAT_RAW }, { 0, 0 } } }, + { NOTMUCH_OPT_KEYWORD, &sort, "sort", 's', + (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST }, + { "newest-first", NOTMUCH_SORT_NEWEST_FIRST }, + { 0, 0 } } }, { NOTMUCH_OPT_INT, ¶ms.part, "part", 'p', 0 }, - { NOTMUCH_OPT_BOOLEAN, ¶ms.entire_thread, "entire-thread", 't', 0 }, + { NOTMUCH_OPT_KEYWORD, &entire_thread, "thread", 't', + (notmuch_keyword_t []){ { "match", NOTMUCH_SHOW_THREAD_MATCH, }, + { "entire", NOTMUCH_SHOW_THREAD_ENTIRE }, + { "none", NOTMUCH_SHOW_THREAD_NONE }, + { 0, 0 } } }, { NOTMUCH_OPT_BOOLEAN, ¶ms.decrypt, "decrypt", 'd', 0 }, { NOTMUCH_OPT_BOOLEAN, &verify, "verify", 'v', 0 }, + { NOTMUCH_OPT_BOOLEAN, &headers_only, "headers-only", 'h', 0 }, { 0, 0, 0, 0, 0 } }; @@ -1055,6 +1115,9 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[])) return 1; } + params.entire_thread = entire_thread; + params.headers_only = headers_only; + if (format_sel == NOTMUCH_FORMAT_NOT_SPECIFIED) { /* if part was requested and format was not specified, use format=raw */ if (params.part >= 0) @@ -1066,7 +1129,9 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[])) switch (format_sel) { case NOTMUCH_FORMAT_JSON: format = &format_json; - params.entire_thread = TRUE; + if (!params.entire_thread) params.entire_thread = NOTMUCH_SHOW_THREAD_ENTIRE; + // params.entire_thread = 1; + break; case NOTMUCH_FORMAT_TEXT: format = &format_text; @@ -1133,10 +1198,15 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[])) return 1; } + notmuch_query_set_sort (query, sort); + if (params.part >= 0) ret = do_show_single (ctx, query, format, ¶ms); else - ret = do_show (ctx, query, format, ¶ms); + if (params.entire_thread == NOTMUCH_SHOW_THREAD_NONE) + ret = do_show_messages (ctx, query, format, ¶ms); + else + ret = do_show (ctx, query, format, ¶ms); notmuch_query_destroy (query); notmuch_database_close (notmuch); -- 1.7.2.3