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 EC48B6DE0E8B for ; Sat, 8 Jun 2019 08:43:01 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -2.634 X-Spam-Level: X-Spam-Status: No, score=-2.634 tagged_above=-999 required=5 tests=[AWL=-0.333, RCVD_IN_DNSWL_MED=-2.3, 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 yLcvk6zpxRgz for ; Sat, 8 Jun 2019 08:43:00 -0700 (PDT) X-Greylist: delayed 344 seconds by postgrey-1.36 at arlo; Sat, 08 Jun 2019 08:43:00 PDT Received: from smtp-sh.infomaniak.ch (smtp-sh.infomaniak.ch [128.65.195.4]) by arlo.cworth.org (Postfix) with ESMTPS id 7B68D6DE0E7E for ; Sat, 8 Jun 2019 08:43:00 -0700 (PDT) Received: from smtp8.infomaniak.ch (smtp8.infomaniak.ch [83.166.132.38]) by smtp-sh.infomaniak.ch (8.14.5/8.14.5) with ESMTP id x58FbDDK001975 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sat, 8 Jun 2019 17:37:13 +0200 Received: from [IPv6:2a01:e35:8be3:1490:22cf:30ff:fe9a:43cf] ([IPv6:2a01:e35:8be3:1490:22cf:30ff:fe9a:43cf]) (authenticated bits=0) by smtp8.infomaniak.ch (8.14.5/8.14.5) with ESMTP id x58FbAxJ147784 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Sat, 8 Jun 2019 17:37:13 +0200 From: VA Subject: [PATCH] python: bind add_property/remove_property and related methods To: notmuch@notmuchmail.org Message-ID: Date: Sat, 8 Jun 2019 17:37:10 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------13830185A8EE1A1DA4DDBAFD" Content-Language: fr X-Antivirus: Dr.Web (R) for Unix mail servers drweb plugin ver.6.0.2.8 X-Antivirus-Code: 0x100000 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 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: Sat, 08 Jun 2019 15:43:02 -0000 This is a multi-part message in MIME format. --------------13830185A8EE1A1DA4DDBAFD Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit These methods were simply missing from the Python bindings. --------------13830185A8EE1A1DA4DDBAFD Content-Type: text/x-patch; name="0001-python-bind-add_property-remove_property-and-related.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-python-bind-add_property-remove_property-and-related.pa"; filename*1="tch" >From 47dcf1659377f1ec8a237fbe474a5412123d0aa1 Mon Sep 17 00:00:00 2001 From: hydrargyrum 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 --------------13830185A8EE1A1DA4DDBAFD--