aboutsummaryrefslogtreecommitdiff
path: root/filters/spam_filter.rb
blob: ef3ba9e4dcd0049690032719e2678bbdf3f27126 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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