From: David Bremner Date: Sun, 10 Jan 2016 02:51:36 +0000 (+2000) Subject: [WIP patch 4/9] lib: add and test function to retrieve current metadata value X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4310c70549e11db748918c28c162cb77367fcb48;p=notmuch-archives.git [WIP patch 4/9] lib: add and test function to retrieve current metadata value --- diff --git a/c1/21c4747690c1260cb038eb63ddad40724ada93 b/c1/21c4747690c1260cb038eb63ddad40724ada93 new file mode 100644 index 000000000..49ca6acf0 --- /dev/null +++ b/c1/21c4747690c1260cb038eb63ddad40724ada93 @@ -0,0 +1,113 @@ +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 A2E366DE0A94 + for ; Sat, 9 Jan 2016 18:52:09 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: -0.313 +X-Spam-Level: +X-Spam-Status: No, score=-0.313 tagged_above=-999 required=5 tests=[AWL=0.238, + RP_MATCHES_RCVD=-0.55, SPF_PASS=-0.001] 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 cFOhjkT2s6H3 for ; + Sat, 9 Jan 2016 18:52:08 -0800 (PST) +Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) + by arlo.cworth.org (Postfix) with ESMTPS id E40BA6DE119D + for ; Sat, 9 Jan 2016 18:51:57 -0800 (PST) +Received: from remotemail by fethera.tethera.net with local (Exim 4.84) + (envelope-from ) + id 1aI66e-0007Dt-5A; Sat, 09 Jan 2016 21:51:48 -0500 +Received: (nullmailer pid 29646 invoked by uid 1000); + Sun, 10 Jan 2016 02:51:47 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [WIP patch 4/9] lib: add and test function to retrieve current + metadata value +Date: Sat, 9 Jan 2016 22:51:36 -0400 +Message-Id: <1452394301-29499-5-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.6.4 +In-Reply-To: <1452394301-29499-1-git-send-email-david@tethera.net> +References: <1452394301-29499-1-git-send-email-david@tethera.net> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.20 +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, 10 Jan 2016 02:52:09 -0000 + +--- + lib/metadata.cc | 11 +++++++++++ + lib/notmuch.h | 7 +++++++ + test/T590-metadata.sh | 2 ++ + 3 files changed, 20 insertions(+) + +diff --git a/lib/metadata.cc b/lib/metadata.cc +index 20805e5..6236992 100644 +--- a/lib/metadata.cc ++++ b/lib/metadata.cc +@@ -227,4 +227,15 @@ notmuch_metadata_key (notmuch_metadata_t *metadata) + } + + const char * ++notmuch_metadata_value (notmuch_metadata_t *metadata) ++{ ++ const char *key = notmuch_metadata_key (metadata); ++ char *val; ++ notmuch_status_t status; ++ ++ status=notmuch_database_get_metadata (metadata->notmuch, metadata->mclass, key, &val); ++ if (status) ++ return NULL; ++ ++ return val; + } +diff --git a/lib/notmuch.h b/lib/notmuch.h +index 16d0973..dd359c8 100644 +--- a/lib/notmuch.h ++++ b/lib/notmuch.h +@@ -1872,6 +1872,13 @@ notmuch_metadata_valid (notmuch_metadata_t *metadata); + */ + const char * + notmuch_metadata_key (notmuch_metadata_t *metadata); ++ ++/** ++ * return value for current metadata pair ++ */ ++const char * ++notmuch_metadata_value (notmuch_metadata_t *metadata); ++ + /* @} */ + + NOTMUCH_END_DECLS +diff --git a/test/T590-metadata.sh b/test/T590-metadata.sh +index 2c44746..d2326d4 100755 +--- a/test/T590-metadata.sh ++++ b/test/T590-metadata.sh +@@ -62,12 +62,14 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} + RUN(notmuch_database_get_all_metadata (db, NOTMUCH_METADATA_CONFIG, &meta)); + printf("valid = %d\n", notmuch_metadata_valid (meta)); + printf("key = %s\n", notmuch_metadata_key (meta)); ++ printf("val = %s\n", notmuch_metadata_value (meta)); + } + EOF + cat <<'EOF' >EXPECTED + == stdout == + valid = 1 + key = testkey1 ++val = testvalue1 + == stderr == + EOF + test_expect_equal_file EXPECTED OUTPUT +-- +2.6.4 +