unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] python: add bindings for notmuch_message_get_property
@ 2017-11-15 22:29 Ruben Pollan
  2017-11-15 22:48 ` meskio
  2017-11-17  9:03 ` Daniel Kahn Gillmor
  0 siblings, 2 replies; 21+ messages in thread
From: Ruben Pollan @ 2017-11-15 22:29 UTC (permalink / raw)
  To: notmuch

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 <Sebastian@SSpaeth.de>
 """
 
 
-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

^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2018-05-02 23:50 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-15 22:29 [PATCH] python: add bindings for notmuch_message_get_property Ruben Pollan
2017-11-15 22:48 ` meskio
2017-11-17  9:03 ` Daniel Kahn Gillmor
2017-11-28 22:46   ` [PATCH] python: add bindings for notmuch_message_get_propert(y/ies) Ruben Pollan
2017-11-28 22:51     ` meskio
2017-11-29  1:57     ` Daniel Kahn Gillmor
2017-11-29  8:02       ` meskio
2017-11-29  8:03         ` Ruben Pollan
2017-12-23 15:59           ` David Bremner
2018-04-27 19:12             ` meskio
2018-04-27 19:15               ` Ruben Pollan
2018-05-01 13:06                 ` David Bremner
2018-05-01 15:24                   ` meskio
2018-05-01 15:28                     ` Ruben Pollan
2018-05-02  0:08                       ` David Bremner
2018-05-02 17:00                         ` meskio
2018-05-02 17:01                           ` Ruben Pollan
2018-05-02 23:50                             ` David Bremner
2017-11-29 21:40       ` Floris Bruynooghe
2017-11-30 13:44         ` David Bremner
2017-11-30 14:19           ` Daniel Kahn Gillmor

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).