aboutsummaryrefslogtreecommitdiff
path: root/filters/spam_filter.rb
diff options
context:
space:
mode:
authormms <git@sapka.me>2024-11-27 20:50:16 +0100
committermms <git@sapka.me>2024-11-27 20:50:16 +0100
commit1354fcfd222a922762999cd6a97dfe5845d4f835 (patch)
tree44522c5d6eddcd58e98f8507c274a8c1ca351112 /filters/spam_filter.rb
parent4c911a441e9533b5bb323b26be748abfd4c5d316 (diff)
Diffstat (limited to 'filters/spam_filter.rb')
-rw-r--r--filters/spam_filter.rb23
1 files changed, 23 insertions, 0 deletions
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