From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 884396DE00D4 for ; Wed, 15 Nov 2017 14:35:53 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.011 X-Spam-Level: X-Spam-Status: No, score=-0.011 tagged_above=-999 required=5 tests=[SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-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 v2SLOkaaM_mw for ; Wed, 15 Nov 2017 14:35:52 -0800 (PST) X-Greylist: delayed 342 seconds by postgrey-1.36 at arlo; Wed, 15 Nov 2017 14:35:51 PST Received: from eternauta.sindominio.net (eternauta.sindominio.net [80.81.122.47]) by arlo.cworth.org (Postfix) with ESMTPS id E8FEC6DE00C4 for ; Wed, 15 Nov 2017 14:35:51 -0800 (PST) Received: from localhost (localhost.localdomain [127.0.0.1]) by lesnaus.sindominio.net (Postfix) with ESMTP id E8B36401FE2; Wed, 15 Nov 2017 23:30:06 +0100 (CET) Received: from eternauta.sindominio.net ([127.0.0.1]) by localhost (lesnaus.sindominio.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GVVfMHkxoQxH; Wed, 15 Nov 2017 23:30:04 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lesnaus.sindominio.net (Postfix) with ESMTPSA id 5A48D401FDE; Wed, 15 Nov 2017 23:30:03 +0100 (CET) From: Ruben Pollan To: notmuch@notmuchmail.org Subject: [PATCH] python: add bindings for notmuch_message_get_property Date: Wed, 15 Nov 2017 23:29:54 +0100 Message-Id: <20171115222954.8216-1-meskio@sindominio.net> X-Mailer: git-send-email 2.15.0 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 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: Wed, 15 Nov 2017 22:35:53 -0000 Message.get_property (prop) returns a string with the value of the property. --- bindings/python/notmuch/message.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py index d5b98e4f..11263736 100644 --- a/bindings/python/notmuch/message.py +++ b/bindings/python/notmuch/message.py @@ -19,7 +19,7 @@ Copyright 2010 Sebastian Spaeth """ -from ctypes import c_char_p, c_long, c_uint, c_int +from ctypes import c_char_p, c_long, c_uint, c_int, POINTER, byref from datetime import date from .globals import ( nmlib, @@ -113,6 +113,11 @@ class Message(Python3StringMixIn): _maildir_flags_to_tags.argtypes = [NotmuchMessageP] _maildir_flags_to_tags.restype = c_int + """notmuch_message_get_property""" + _get_property = nmlib.notmuch_message_get_property + _get_property.argtypes = [NotmuchMessageP, c_char_p, POINTER(c_char_p)] + _get_property.restype = c_int + #Constants: Flags that can be set/get with set_flag FLAG = Enum(['MATCH']) @@ -433,6 +438,26 @@ class Message(Python3StringMixIn): _freeze.argtypes = [NotmuchMessageP] _freeze.restype = c_uint + def get_property(self, prop): + """ Retrieve the value for a single property key + + :param prop: The name of the property to get. + :returns: String with the property value or None if there is no such + key. In the case of multiple values for the given key, the + first one is retrieved. + :raises: :exc:`NotInitializedError` if message has not been + initialized + """ + if not self._msg: + raise NotInitializedError() + + value = c_char_p("") + status = Message._get_property(self._msg, prop, byref(value)) + if status != 0: + raise NotmuchError(status) + + return value.value + def freeze(self): """Freezes the current state of 'message' within the database -- 2.15.0