From 1354fcfd222a922762999cd6a97dfe5845d4f835 Mon Sep 17 00:00:00 2001 From: mms Date: Wed, 27 Nov 2024 20:50:16 +0100 Subject: gemfile --- filters/spam_filter.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 filters/spam_filter.rb (limited to 'filters/spam_filter.rb') diff --git a/filters/spam_filter.rb b/filters/spam_filter.rb new file mode 100644 index 0000000..ef3ba9e --- /dev/null +++ b/filters/spam_filter.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +SPAM_THRESHOLD = 5.0 + +SPAM_FILTER = lambda do + Chotto.rule_set 'spam_filter' do + messages.filter('NOT tag:spam').each do |msg| + if msg.x_spam_score.to_f > SPAM_THRESHOLD + tags = [ + 'spam', + "spam/#{msg.x_spam_score}" + ] + + msg.tags = tags + msg.save! + + end + + # TODO: understand why sometimes Notmuch raises MemoryErrpr + rescue Notmuch::MemoryError + end + end +end -- cgit v1.2.3