diff options
author | mms <git@sapka.me> | 2024-11-25 00:11:05 +0100 |
---|---|---|
committer | mms <git@sapka.me> | 2024-11-25 00:11:05 +0100 |
commit | fcdfb62d0f9ca9773da57e20286b8623c2c866f5 (patch) | |
tree | e47b0d22548261f8690c3802445eb2ddab062c48 /filters | |
parent | c2623f1aa3638c988026b28f6a4131df6c61e0c6 (diff) |
feat: mailig list rule
Diffstat (limited to 'filters')
-rw-r--r-- | filters/mailing_lists_filter.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/filters/mailing_lists_filter.rb b/filters/mailing_lists_filter.rb new file mode 100644 index 0000000..872a817 --- /dev/null +++ b/filters/mailing_lists_filter.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Chotto + # Adds "list" and "list/<list-id>" tags to messages from mailing list + # Baed on RFC 2919 + module MailingListsFilter + def self.list_id_from_header(value) + value.match(/<(.*)>/)[1].gsub(' ', '') + end + end +end + +MAILING_LIST_FILTER = lambda do + Chotto.rule_set 'mailing_lists' do + messages.filter('NOT tag:lists').each do |msg| + list_id = Chotto::MailingListsFilter.list_id_from_header(msg.list_id) + msg.tags = ['unread', 'inbox', 'lists', "lists/#{list_id}"] + msg.save! + end + end +end |