Ajout de "junk" pour les emails
This commit is contained in:
parent
9d21b2c266
commit
b1e40797d7
|
@ -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
|
||||
|
|
13
app/services/email_action/junk.rb
Normal file
13
app/services/email_action/junk.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module EmailAction
|
||||
class Junk < Base
|
||||
|
||||
def process(email)
|
||||
email.junk = true
|
||||
|
||||
email
|
||||
end
|
||||
|
||||
end
|
||||
end
|
6
test/fixtures/actions.yml
vendored
6
test/fixtures/actions.yml
vendored
|
@ -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
|
||||
|
|
4
test/fixtures/rule_sets.yml
vendored
4
test/fixtures/rule_sets.yml
vendored
|
@ -70,3 +70,7 @@ postpone_past_valid:
|
|||
postpone_invalid:
|
||||
name: Postpone to invalid date
|
||||
enabled: true
|
||||
|
||||
junk:
|
||||
name: Junk mail
|
||||
enabled: true
|
||||
|
|
9
test/fixtures/rules.yml
vendored
9
test/fixtures/rules.yml
vendored
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue