X-Envelope-From: notmuch-bounces@notmuchmail.org  Sat Apr  4 06:49:55 2026
Return-Path: <notmuch-bounces@notmuchmail.org>
X-Original-To: nmbug@yantan.tethera.net
Delivered-To: nmbug@yantan.tethera.net
Received: from yantan.tethera.net (localhost [127.0.0.1])
	by mail.notmuchmail.org (Postfix) with ESMTP id 6B50F60509;
	Sat,  4 Apr 2026 06:49:55 +0000 (UTC)
Received: from phubs.tethera.net (phubs.tethera.net [IPv6:2607:5300:60:3a9d::1])
	by mail.notmuchmail.org (Postfix) with ESMTPS id 8E66D5F813
	for <notmuch@notmuchmail.org>; Sat,  4 Apr 2026 06:49:51 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tethera.net;
 i=@tethera.net; q=dns/txt; s=2024; t=1775285388; h=from : to : subject
 : in-reply-to : references : date : message-id : mime-version :
 content-type : from; bh=Sd95u4kjxaulvNNuS+4K++u5sCVifcc0AWbXSbPNhD0=;
 b=gGir+nItblO5azsNE31TOCKA5FxOhw+nFQz1T8em2KqfeFGrDiJ+Q+DiJwNWo+wzbkGLX
 SHpYnHZ35rHr5mPyVW49d5V+5ZbmrTB5yUuz+a7XQNEFQ1BQakCIDBpFM7cFwS/kIglef9X
 KzxbRICuQDYf/IyGhntuxBxT+Nie209v0VW9A+Z+djkMiZCu0mo8L6YjjLIkP7M9WTRnwKf
 NHo/TNeOafauhcomUf8tABWyVMUePUaGIYCzncpzUrPvRpgxdbR3icoRObmTFqhqtxYFWhU
 EAfD9h+3isHbpXj52GJmY1EkkOJd3WucFOOZtsumMd1xuJ1TfqZl4FW2zzDA==
Received: from tethera.net (M111108027213.v4.enabler.ne.jp [111.108.27.213])
	by phubs.tethera.net (Postfix) with ESMTPS id 463C91800F7;
	Sat, 04 Apr 2026 03:49:48 -0300 (ADT)
Received: (nullmailer pid 1031987 invoked by uid 1000);
	Sat, 04 Apr 2026 06:42:45 -0000
From: David Bremner <david@tethera.net>
To: Anton Khirnov <anton@khirnov.net>, notmuch@notmuchmail.org
Subject: Re: [PATCH v4 1/6] Add API for filtering attachments with an
 external program.
In-Reply-To: <20260307160342.16482-2-anton@khirnov.net>
References: <20260307160342.16482-1-anton@khirnov.net>
 <20260307160342.16482-2-anton@khirnov.net>
Date: Sat, 04 Apr 2026 15:42:44 +0900
Message-ID: <87bjfz9qfv.fsf@tethera.net>
MIME-Version: 1.0
Message-ID-Hash: 5XUDTIB6TS7C2HZYACMX63KJHSUGXINY
X-Message-ID-Hash: 5XUDTIB6TS7C2HZYACMX63KJHSUGXINY
X-MailFrom: david@tethera.net
X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header
X-Mailman-Version: 3.3.3
Precedence: list
List-Id: "Use and development of the notmuch mail system." <notmuch.notmuchmail.org>
List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
List-Owner: <mailto:notmuch-owner@notmuchmail.org>
List-Post: <mailto:notmuch@notmuchmail.org>
List-Subscribe: <mailto:notmuch-join@notmuchmail.org>
List-Unsubscribe: <mailto:notmuch-leave@notmuchmail.org>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

Anton Khirnov <anton@khirnov.net> writes:

> diff --git a/bindings/python-cffi/notmuch2/_build.py b/bindings/python-cffi/notmuch2/_build.py
> index 2f3152c6..f918f96f 100644
> --- a/bindings/python-cffi/notmuch2/_build.py
> +++ b/bindings/python-cffi/notmuch2/_build.py
> @@ -328,6 +328,11 @@ ffibuilder.cdef(
>                                            notmuch_decryption_policy_t decrypt_policy);
>      notmuch_decryption_policy_t
>      notmuch_indexopts_get_decrypt_policy (const notmuch_indexopts_t *indexopts);
> +    notmuch_status_t
> +    notmuch_indexopts_set_filter (notmuch_indexopts_t *indexopts,
> +                                  const char *filter_cmd);
> +    const char *
> +    notmuch_indexopts_get_filter (const notmuch_indexopts_t *indexopts);
>      void
>      notmuch_indexopts_destroy (notmuch_indexopts_t *options);
>  
> diff --git a/bindings/python-cffi/notmuch2/_database.py b/bindings/python-cffi/notmuch2/_database.py
> index ba389a42..78a43d72 100644
> --- a/bindings/python-cffi/notmuch2/_database.py
> +++ b/bindings/python-cffi/notmuch2/_database.py
> @@ -878,3 +878,24 @@ class IndexOptions(base.NotmuchObject):
>              self._opts_p, val.value)
>          if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
>              raise errors.NotmuchError(ret)
> +
> +    @property
> +    def filter_cmd(self):
> +        """Filtering program to extract text from non-text MIME parts.
> +
> +        CAUTION: improper use of this option may lead to remote code
> +        execution on the user's machine. See the `index.filter` section
> +        in :any:`notmuch-config(1)` for details. Make sure you read and
> +        understand it before setting this property.
> +
> +        The value is a string that is split in a shell-like manner and
> +        executed.
> +        """
> +        raw = capi.lib.notmuch_indexopts_get_filter(self._opts_p)
> +        return base.BinString.from_cffi(raw)
> +
> +    @filter_cmd.setter
> +    def filter_cmd(self, val):
> +        ret = capi.lib.notmuch_indexopts_set_filter(self._opts_p, val)
> +        if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
> +            raise errors.NotmuchError(ret)
> diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst
> index 6a63e457..d2f80d19 100644

Although these are pretty simple, python being python, we
should at least exercise them with some simple tests. I didn't see any
tests for this in the remaining series. 

> +   The filter is a commandline split in a POSIX shell-like manner (without
> +   actually invoking the shell, so shell expansions are not performed and shell
> +   constructs are not allowed) and executed. The payload of the MIME part to be
> +   filtered will be supplied on its `stdin`, it is expected to write the text
> +   output to its `stdout`. The following environment variables will be set:
> +
> +   * NOTMUCH_FILTER_MIME_TYPE - the ``type/subtype`` part of the
> +     "content-type" header
> +   * NOTMUCH_FILTER_FILENAME - the file name associated with the attachment, if
> +     present
> +   * NOTMUCH_FILTER_MESSAGE_ID - the message ID, without enclosing angle
> +     brackets <>

There is a sphinx "role" :envvar: used in various places in the docs
that might improve things here; if nothing else it would generate
anchors for people to link to.

_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org
