X-Envelope-From: notmuch-bounces@notmuchmail.org  Sun Mar 22 13:55:58 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 5AD6D5E298;
	Sun, 22 Mar 2026 13:55:58 +0000 (UTC)
X-Greylist: delayed 329 seconds by postgrey-1.36 at yantan; Sun, 22 Mar 2026 13:55:55 UTC
Received: from lahtoruutu.iki.fi (lahtoruutu.iki.fi [185.185.170.37])
	by mail.notmuchmail.org (Postfix) with ESMTPS id 3EDF85DF37
	for <notmuch@notmuchmail.org>; Sun, 22 Mar 2026 13:55:55 +0000 (UTC)
Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	by lahtoruutu.iki.fi (Postfix) with ESMTPS id 4fdyNx5LkRz49Q55
	for <notmuch@notmuchmail.org>; Sun, 22 Mar 2026 15:50:25 +0200 (EET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu;
	t=1774187425;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 in-reply-to:in-reply-to:references:references;
	bh=2qHTjCXigRshj/MkzTBURu640huJHzOcmJNNAzZoYeY=;
	b=WREYKiSD7a6RU4PREg8Kgk3u64HcE+uOn2KqR68rZQLncqHZv8vObA7PNvpL6/XXB5Z0FJ
	4k31gcNLHP0eGiF6UHl/5YcAY++Wx3nX94TZnAF+jDT42GTk38U3brCyY4s9/JqJPDuj85
	mM3dW4rDkhYx8tYnEwL9W1qW0T3UWCM3ca4m8fuTH8wW4bOavkQSbSzHQLG4wyluRuWMYW
	VQtRtpYA4idBAPcXsP2jrGLxN9lKe/HU3EXIOw9jIVG035riHE5g6542XjhY4NCH6tE4+l
	dIW846Lug0xLXdsauMXb+Wqo25SjKhIom5QoS334q4/cdL4+fUpJaMLfANvI7w==
Received: from mithlond (mobile-access-2e8427-129.dhcp.inet.fi [46.132.39.129])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange secp256r1 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	(Authenticated sender: tlikonen)
	by meesny.iki.fi (Postfix) with ESMTPSA id 4fdyNn3lnwzyQC;
	Sun, 22 Mar 2026 15:50:17 +0200 (EET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny;
	t=1774187417;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 in-reply-to:in-reply-to:references:references;
	bh=2qHTjCXigRshj/MkzTBURu640huJHzOcmJNNAzZoYeY=;
	b=oHcysP+88pxrSHi7hbPVRRLYhsgUCPubTm56PkOST74PTNAIJsxvyCndBl26nTne9EkGg/
	2dKMCPPnsYNSOBFwoIekBq/1p+TEWSAb898tp35BsNBwo1yALfWddBqdJdt4NWz3hXJiRn
	r+8w6vVq9oZWHJPj8hry6ZwYIiIwl2c=
ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=meesny; cv=none; t=1774187417;
	b=PYAEsMHdnWncH7W9A7u7w1cSOOyKiV5CSpUWDE2JtbUZJN3YJFmNRQiKM66kIF8Q6bL+/q
	uLl9kABmo9P7bErFf53m1ysYnGVldNCZn+V5/ANKCl6xGWr3e7kNBRzcrprReRPGnFsxyn
	Us6tsH1okPgjnJwIwbw5BVlYwRZEivE=
ARC-Authentication-Results: i=1;
	ORIGINATING;
	auth=pass smtp.auth=tlikonen smtp.mailfrom=tlikonen@iki.fi
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi;
	s=meesny; t=1774187417;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 in-reply-to:in-reply-to:references:references;
	bh=2qHTjCXigRshj/MkzTBURu640huJHzOcmJNNAzZoYeY=;
	b=Djefmj3Y46gRreU4Dxx7buYJr276uKI8oWBBEeT5OoIUeCsZoJY55XehHQeHZjOl5+2awj
	eBz6YV9hZX33EAx/vGyF1xuij5BnLjvDO49saFuBCPyD1CIohvaInIHz+uhEKWAr8Wl66F
	ajkfIGoRJK8JgJwjMgfeQ7xrLogh2CU=
From: Teemu Likonen <tlikonen@iki.fi>
To: Alan Schmitt <alan.schmitt@polytechnique.org>, notmuch@notmuchmail.org
Subject: Re: dealing with spam
In-Reply-To: <m21phc40wk.fsf@petitepomme.net>
References: <m21phc40wk.fsf@petitepomme.net>
User-Agent: Notmuch/0.39 (https://notmuchmail.org) Emacs/30.1
 (x86_64-pc-linux-gnu)
Date: Sun, 22 Mar 2026 15:50:07 +0200
Message-ID: <87ldfkas8g.fsf@mithlond.arda>
MIME-Version: 1.0
Message-ID-Hash: XEDOVLAFF7MOYO6M45B5O4T7KOGDZHNS
X-Message-ID-Hash: XEDOVLAFF7MOYO6M45B5O4T7KOGDZHNS
X-MailFrom: tlikonen@iki.fi
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: multipart/mixed; boundary="===============5856228638050543590=="

--===============5856228638050543590==
Content-Type: multipart/signed; boundary="=-=-=";
	micalg=pgp-sha512; protocol="application/pgp-signature"

--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

* 2026-03-22 11:24:43+0100, Alan Schmitt wrote:

> I would like to have a local spam bayesian filtering system that works
> with notmuch (so that I can use tagging to train and then filter
> mails), and I don=E2=80=99t know how to proceed. I searched the FAQ, the
> How-to, and the mailing-list archives and could not find much. Do you
> have any pointers or tips to share?

I have a full script written in the Fish shell language but it's pretty
much of my custom stuff that it would be probably too much as a starting
point. I'll paste some parts of it and strip it down to make it more
easily understandable. This is the Fish language and bogofilter spam
filtering program.

Check and tag new messages

    function bogofilter_check
        for msgid in (notmuch search --output=3Dmessages tag:new)
            notmuch show --exclude=3Dfalse --format=3Draw $msgid | bogofilt=
er

            switch $status
                case 0 # Spam
                    notmuch tag +spam $msgid
                    notmuch tag +learn-spam $msgid

                case 1 # Ham
                    notmuch tag +learn-ham $msgid

                case 2
                    notmuch tag +unsure $msgid

                case '*'
                    return 1
            end
        end
    end

Teach the spam system

    function bogofilter_execute
        set -l bf_opts $argv[1]
        set -l other $argv[2..]
        notmuch show --exclude=3Dfalse --format=3Dmbox $other | bogofilter =
-M "$bf_opts"
    end

    function bogofilter_teach
        # Mark old spam as read.
        notmuch tag -unread tag:unread AND tag:spam AND date:..7days

        # Convert conflicting learn tags as unsure.
        notmuch tag +unsure -spam -learn-ham -learn-spam \
            tag:learn-ham AND tag:learn-spam
        notmuch tag +unsure -spam -unlearn-ham -unlearn-spam \
            tag:unlearn-ham AND tag:unlearn-spam

        set -l query tag:learn-spam
        bogofilter_execute -s $query
        notmuch tag +spam-db +spam -learn-spam -unsure -- $query

        set -l query tag:learn-ham
        bogofilter_execute -n $query
        notmuch tag +ham-db -learn-ham -spam -unsure -- $query

        return 0
    end

Remove old spam message files

    function remove_old_spam
        # Save spam messages at least days_min and count_min.
        set -l days_min 365
        set -l count_min 1000

        set -l msgs (notmuch count tag:spam AND date:"$days_min"days..)
        if test "$msgs" -lt "$count_min"
            set msgs $count_min
        end

        notmuch search --exclude=3Dfalse --output=3Dfiles --format=3Dtext0 \
            --sort=3Dnewest-first --offset=3D"$msgs" tag:spam | xargs -0r /=
usr/bin/rm -f
    end

=2D-=20
/// Teemu Likonen - .-.. https://www.iki.fi/tlikonen/
// OpenPGP: DD3B8E8ABD28B98176E6A7CCCC9A5E615FCC1D93
/ old key: 6965F03973F0D4CA22B9410F0F2CAE0E07608462

--=-=-=
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

wr0EARYKAG8Fgmm/848JEPDAoNzWp6sPRxQAAAAAAB4AIHNhbHRAbm90YXRpb25z
LnNlcXVvaWEtcGdwLm9yZzNGYi7Jv0hSkT2insY8anYdOgaJjGdGwEPkS0Csoz1s
FiEEjUTuCml9qsOsoFih8MCg3Nanqw8AAAZPAP9z+oTQ0HZPZIqsWM7omoYo9ynW
YqS0VpxOv4bfzONYKgD+JjbnUHMlvBrbpfSee73UbhUb8w/Yd2jVpi9NexwvwwXC
vQQBFgoAbwWCab/zjwkQee8ZJX1rVltHFAAAAAAAHgAgc2FsdEBub3RhdGlvbnMu
c2VxdW9pYS1wZ3Aub3JncgngUYIhXqLgHOeuxQfdaU49DTdWDQbQy+OZuBPb2v8W
IQQL23klfGMkeOvdGCt57xklfWtWWwAAy7MA/iwWnzvNkxIpDun6MCS6Ml1HNJ2B
lDytjuiruina4c08AP9zG5FzYGPLA4QPEB/fqoRZ7me8Trhfzjjn+5zNwky2Cw==
=NKbY
-----END PGP SIGNATURE-----
--=-=-=--

--===============5856228638050543590==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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

--===============5856228638050543590==--
