# frozen_string_literal: true module Chotto # Adds "list" and "list/" tags to messages from mailing list # Baed on RFC 2919 module MailingListsFilter def self.list_id_from_header(value) id = value.match(/<(.*)>/) if id id[1]&.gsub(' ', '') else value end end end end MAILING_LIST_FILTER = lambda do Chotto.rule_set 'mailing_lists' do messages.filter('NOT tag:lists').each do |msg| 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