Ajout de "junk" pour les emails

This commit is contained in:
Jérémy Lecour 2021-01-26 16:01:09 +01:00 committed by Jérémy Lecour
parent 9d21b2c266
commit b1e40797d7
6 changed files with 46 additions and 0 deletions

View file

@ -18,6 +18,7 @@ class Email
attribute :plain_body
attribute :cron, :boolean, default: false
attribute :mailing_list, :boolean, default: false
attribute :junk, :boolean, default: false
attribute :organisations, default: []
attribute :servers, default: []
attribute :issues, default: []
@ -48,6 +49,10 @@ class Email
mailing_list
end
def junk?
junk
end
def postponed?
postponed_until.present? && postponed_until > DateTime.now
end

View file

@ -0,0 +1,13 @@
# frozen_string_literal: true
module EmailAction
class Junk < Base
def process(email)
email.junk = true
email
end
end
end

View file

@ -56,3 +56,9 @@ postpone_invalid:
enabled: true
class_name: EmailAction::Postpone
argument: Foo Bar Baz
junk:
rule_set: junk
name: Mark mail as junk
enabled: true
class_name: EmailAction::Junk

View file

@ -70,3 +70,7 @@ postpone_past_valid:
postpone_invalid:
name: Postpone to invalid date
enabled: true
junk:
name: Junk mail
enabled: true

View file

@ -76,3 +76,12 @@ postpone_invalid:
condition_type: match
condition_value: Postponable
inverted: false
junk_subject:
rule_set: junk
name: Junk in subject
enabled: true
subject_type: Subject
condition_type: match
condition_value: Junk
inverted: false

View file

@ -106,4 +106,13 @@ class RuleSetProcessorTest < ActiveSupport::TestCase
assert_nil email.postponed_until
assert_not_predicate email, :postponed?
end
test "junk mail" do
email = Email.new(subject: "Junk")
processor = RuleSetProcessor.new
email = processor.process(rule_sets(:junk), email)
assert_predicate email, :junk?
end
end