unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] python: bind add_property/remove_property and related methods
@ 2019-06-08 15:37 VA
  2019-06-09 19:58 ` Daniel Kahn Gillmor
  0 siblings, 1 reply; 7+ messages in thread
From: VA @ 2019-06-08 15:37 UTC (permalink / raw)
  To: notmuch

[-- Attachment #1: Type: text/plain, Size: 60 bytes --]

These methods were simply missing from the Python bindings.

[-- Attachment #2: 0001-python-bind-add_property-remove_property-and-related.patch --]
[-- Type: text/x-patch, Size: 5565 bytes --]

From 47dcf1659377f1ec8a237fbe474a5412123d0aa1 Mon Sep 17 00:00:00 2001
From: hydrargyrum <dev@indigo.re>
Date: Sun, 27 Jan 2019 09:43:57 +0100
Subject: [PATCH] python: bind add_property/remove_property and related methods

Methods for manipulating properties were not bound in Python.
---
 bindings/python/notmuch/message.py | 117 +++++++++++++++++++++++++++++
 1 file changed, 117 insertions(+)

diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py
index 6e32b5f7..d5378b17 100644
--- a/bindings/python/notmuch/message.py
+++ b/bindings/python/notmuch/message.py
@@ -144,6 +144,28 @@ class Message(Python3StringMixIn):
     _properties_move_to_next.argtypes = [NotmuchMessagePropertiesP]
     _properties_move_to_next.restype = None
 
+    """notmuch_message_add_property"""
+    _add_property = nmlib.notmuch_message_add_property
+    _add_property.argtypes = [NotmuchMessageP, c_char_p, c_char_p]
+    _add_property.restype = c_int
+
+    """notmuch_message_remove_property"""
+    _remove_property = nmlib.notmuch_message_remove_property
+    _remove_property.argtypes = [NotmuchMessageP, c_char_p, c_char_p]
+    _remove_property.restype = c_int
+
+    """notmuch_message_remove_all_properties"""
+    _remove_all_properties = nmlib.notmuch_message_remove_all_properties
+    _remove_all_properties.argtypes = [NotmuchMessageP, c_char_p]
+    _remove_all_properties.restype = c_int
+
+    """notmuch_message_remove_all_properties_with_prefix"""
+    _remove_all_properties_with_prefix = \
+        nmlib.notmuch_message_remove_all_properties_with_prefix
+    _remove_all_properties_with_prefix.argtypes = \
+        [NotmuchMessageP, c_char_p]
+    _remove_all_properties_with_prefix.restype = c_int
+
     #Constants: Flags that can be set/get with set_flag
     FLAG = Enum(['MATCH'])
 
@@ -513,6 +535,101 @@ class Message(Python3StringMixIn):
             yield key.decode("utf-8"), value.decode("utf-8")
             Message._properties_move_to_next(properties)
 
+    def add_property(self, key, value):
+        """ Add a (key,value) pair to a message
+
+        :param key: The name of the property (may not contain an
+            '=' character).
+        :param value: The value of the property to add.
+        :returns: STATUS.SUCCESS if the property was successfully added.
+                  Raises an exception otherwise.
+        :raises: :exc:`NotInitializedError` if message has not been
+                 initialized
+        """
+        if not self._msg:
+            raise NotInitializedError()
+
+        status = self._add_property(self._msg, _str(key), _str(value))
+
+        # bail out on failure
+        if status != STATUS.SUCCESS:
+            raise NotmuchError(status)
+
+        return STATUS.SUCCESS
+
+    def remove_property(self, key, value):
+        """ Remove a (key,value) pair from a message
+
+        It is not an error to remove a non-existant (key,value) pair.
+
+        :param key: The name of the property (may not contain an
+            '=' character).
+        :param value: The value of the property to remove.
+        :returns: STATUS.SUCCESS if the property was successfully removed.
+                  Raises an exception otherwise.
+        :raises: :exc:`NotInitializedError` if message has not been
+                 initialized
+        """
+        if not self._msg:
+            raise NotInitializedError()
+
+        status = self._remove_property(self._msg, _str(key), _str(value))
+
+        # bail out on failure
+        if status != STATUS.SUCCESS:
+            raise NotmuchError(status)
+
+        return STATUS.SUCCESS
+
+    def remove_all_properties(self, key):
+        """ Remove all (key,value) pairs from the given message
+
+        :param key: key to delete properties for. If None, delete properties
+            properties for all keys
+        :returns: STATUS.SUCCESS if the properties were successfully removed.
+                  Raises an exception otherwise.
+        :raises: :exc:`NotInitializedError` if message has not been
+                 initialized
+        """
+        if not self._msg:
+            raise NotInitializedError()
+
+        if key is None:
+            status = self._remove_all_properties(self._msg, None)
+        else:
+            status = self._remove_all_properties(self._msg, _str(key))
+
+        # bail out on failure
+        if status != STATUS.SUCCESS:
+            raise NotmuchError(status)
+
+        return STATUS.SUCCESS
+
+    def remove_all_properties_with_prefix(self, key):
+        """ Remove all (prefix*,value) pairs from the given message
+
+        :param key: delete properties with keys that start with prefix.
+            If None, delete all properties.
+        :returns: STATUS.SUCCESS if the properties were successfully removed.
+                  Raises an exception otherwise.
+        :raises: :exc:`NotInitializedError` if message has not been
+                 initialized
+        """
+        if not self._msg:
+            raise NotInitializedError()
+
+        if key is None:
+            status = self._remove_all_properties_with_prefix(self._msg, None)
+        else:
+            status = self._remove_all_properties_with_prefix(self._msg,
+                                                             _str(key))
+
+        # bail out on failure
+        if status != STATUS.SUCCESS:
+            raise NotmuchError(status)
+
+        return STATUS.SUCCESS
+
     def freeze(self):
         """Freezes the current state of 'message' within the database
 
-- 
2.20.1


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

end of thread, other threads:[~2019-06-17  4:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-08 15:37 [PATCH] python: bind add_property/remove_property and related methods VA
2019-06-09 19:58 ` Daniel Kahn Gillmor
2019-06-10 12:55   ` VA
2019-06-11  9:31     ` Daniel Kahn Gillmor
2019-06-14 20:34       ` VA
2019-06-15 23:52         ` Daniel Kahn Gillmor
2019-06-17  4:31           ` 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).