aboutsummaryrefslogtreecommitdiff
path: root/filters
diff options
context:
space:
mode:
Diffstat (limited to 'filters')
-rw-r--r--filters/mailing_lists_filter.rb5
-rw-r--r--filters/spam_filter.rb23
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