From: VA <dev+notmuch@indigo.re>
To: notmuch@notmuchmail.org
Subject: [PATCH] python: bind add_property/remove_property and related methods
Date: Sat, 8 Jun 2019 17:37:10 +0200 [thread overview]
Message-ID: <d0e8775c-08f6-2742-41fc-eff180c4e8da@indigo.re> (raw)
[-- 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
next reply other threads:[~2019-06-08 15:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-08 15:37 VA [this message]
2019-06-09 19:58 ` [PATCH] python: bind add_property/remove_property and related methods 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d0e8775c-08f6-2742-41fc-eff180c4e8da@indigo.re \
--to=dev+notmuch@indigo.re \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).