---
 contrib/filter/filter.py    | 23 +++++++++++++++++++++++
 doc/man1/notmuch-config.rst |  7 +++++++
 2 files changed, 30 insertions(+)
 create mode 100755 contrib/filter/filter.py

diff --git a/contrib/filter/filter.py b/contrib/filter/filter.py
new file mode 100755
index 00000000..88394d6e
--- /dev/null
+++ b/contrib/filter/filter.py
@@ -0,0 +1,23 @@
+#!/usr/bin/python3
+
+import os
+import shutil
+import sys
+
+mime_type = os.environ['NOTMUCH_FILTER_MIME_TYPE'].lower()
+
+cmdline = None
+if mime_type == 'application/pdf':
+    if shutil.which('pdftotext'):
+        cmdline = ('pdftotext', '-', '-')
+elif mime_type == 'text/html':
+    if shutil.which('elinks'):
+        cmdline = ('elinks', '-force-html', '-dump')
+    elif shutil.which('w3m'):
+        cmdline = ('w3m', '-T', 'text/html', '-dump')
+
+if cmdline:
+    os.execvp(cmdline[0], cmdline)
+
+# unhandled mime types are treated as text and passed through
+shutil.copyfileobj(sys.stdin.buffer, sys.stdout.buffer)
diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst
index 8d0aa11b..7e026069 100644
--- a/doc/man1/notmuch-config.rst
+++ b/doc/man1/notmuch-config.rst
@@ -160,6 +160,13 @@ paths are presumed relative to `$HOME` for items in section
    * NOTMUCH_FILTER_MIME_TYPE - the ``type/subtype`` part of the
      "content-type" header
 
+   A sample filtering script is shipped with notmuch source as
+   ``contrib/filter/filter.py``. You may use it as e.g.:
+
+   * ``notmuch config set index.as_text text/html application/pdf``
+   * ``notmuch config set index.filter '<your sandbox>
+     <.../contrib/filter/filter.py>'``
+
    History: This configuration value was introduced in notmuch 0.40.
 
 .. nmconfig:: index.decrypt
-- 
2.47.3

_______________________________________________
notmuch mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to