Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 365A76DE1B7F for ; Sun, 5 Apr 2015 16:03:11 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.519 X-Spam-Level: X-Spam-Status: No, score=0.519 tagged_above=-999 required=5 tests=[AWL=0.509, T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0VnzuO-pRVzu for ; Sun, 5 Apr 2015 16:03:09 -0700 (PDT) Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net [87.98.215.224]) by arlo.cworth.org (Postfix) with ESMTPS id ACFBA6DE1BB6 for ; Sun, 5 Apr 2015 16:03:01 -0700 (PDT) Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim 4.80) (envelope-from ) id 1YetYZ-0002pl-PW; Sun, 05 Apr 2015 23:02:19 +0000 Received: (nullmailer pid 2245 invoked by uid 1000); Sun, 05 Apr 2015 22:59:25 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [WIP2 05/12] cli: add two sprinter utility functions Date: Mon, 6 Apr 2015 07:59:07 +0900 Message-Id: <1428274754-1698-6-git-send-email-david@tethera.net> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1428274754-1698-1-git-send-email-david@tethera.net> References: <1428274754-1698-1-git-send-email-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.18 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, 05 Apr 2015 23:03:11 -0000 These are called directly, rather than via a vtable. They will help add common metadata to search/show/reply --- devel/schemata | 1 + sprinter-utils.c | 41 +++++++++++++++++++++++++++++++++++++++++ sprinter.h | 7 +++++++ 3 files changed, 49 insertions(+) create mode 100644 sprinter-utils.c diff --git a/devel/schemata b/devel/schemata index 41dc4a6..98a1b2b 100644 --- a/devel/schemata +++ b/devel/schemata @@ -147,6 +147,7 @@ search_files = [string*] search_tags = [string*] thread_summary = { + database: database_metadata thread: threadid, timestamp: unix_time, date_relative: string, # user-friendly timestamp diff --git a/sprinter-utils.c b/sprinter-utils.c new file mode 100644 index 0000000..2ba588e --- /dev/null +++ b/sprinter-utils.c @@ -0,0 +1,41 @@ +#include "notmuch-client.h" +#include "sprinter.h" + +notmuch_status_t +sprinter_start_output (sprinter_t *sp, + const notmuch_query_t *query, + const char *query_type) +{ + long int rev; + const char *uuid; + notmuch_database_t *notmuch; + + sp->begin_list (sp); + + if (sp->type != NOTMUCH_SPRINTER_TEXT && notmuch_format_version >= 3) { + notmuch = notmuch_query_get_database (query); + + rev = notmuch_database_get_revision (notmuch, &uuid); + + sp->begin_map (sp); + sp->map_key (sp, "query_type"); + sp->string (sp, query_type); + + sp->map_key (sp, "uuid"); + sp->string (sp, uuid); + + sp->map_key (sp, "lastmod"); + sp->integer (sp, rev); + + sp->end (sp); + + } + return NOTMUCH_STATUS_SUCCESS; +} + +notmuch_status_t +sprinter_finish_output (sprinter_t *sp) +{ + sp->end (sp); /* map */ + return NOTMUCH_STATUS_SUCCESS; +} diff --git a/sprinter.h b/sprinter.h index 7e58f69..4873f69 100644 --- a/sprinter.h +++ b/sprinter.h @@ -91,4 +91,11 @@ sprinter_json_create (const void *ctx, FILE *stream); struct sprinter * sprinter_sexp_create (const void *ctx, FILE *stream); +notmuch_status_t +sprinter_start_output (struct sprinter *sp, + const notmuch_query_t *query, + const char *query_type); + +notmuch_status_t +sprinter_finish_output (struct sprinter *sp); #endif // NOTMUCH_SPRINTER_H -- 2.1.4