diff options
author | mms <git@sapka.me> | 2024-11-27 20:50:16 +0100 |
---|---|---|
committer | mms <git@sapka.me> | 2024-11-27 20:50:16 +0100 |
commit | 1354fcfd222a922762999cd6a97dfe5845d4f835 (patch) | |
tree | 44522c5d6eddcd58e98f8507c274a8c1ca351112 /filters | |
parent | 4c911a441e9533b5bb323b26be748abfd4c5d316 (diff) |
Diffstat (limited to 'filters')
-rw-r--r-- | filters/mailing_lists_filter.rb | 5 | ||||
-rw-r--r-- | filters/spam_filter.rb | 23 |
2 files changed, 25 insertions, 3 deletions
diff --git a/filters/mailing_lists_filter.rb b/filters/mailing_lists_filter.rb index feaee0e..ce11018 100644 --- a/filters/mailing_lists_filter.rb +++ b/filters/mailing_lists_filter.rb @@ -6,7 +6,7 @@ module Chotto module MailingListsFilter def self.list_id_from_header(value) id = value.match(/<(.*)>/) - if id + if id id[1]&.gsub(' ', '') else value @@ -18,12 +18,11 @@ end MAILING_LIST_FILTER = lambda do Chotto.rule_set 'mailing_lists' do messages.filter('NOT tag:lists').each do |msg| - unless msg.list_id.empty? + next if msg.list_id.empty? list_id = Chotto::MailingListsFilter.list_id_from_header(msg.list_id) msg.tags = ['unread', 'inbox', 'lists', "lists/#{list_id}"] msg.save! - end end end end 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 |