From b1e40797d7089309d497e71a51a393e181c85751 Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Tue, 26 Jan 2021 16:01:09 +0100 Subject: [PATCH] Ajout de "junk" pour les emails --- app/models/email.rb | 5 +++++ app/services/email_action/junk.rb | 13 +++++++++++++ test/fixtures/actions.yml | 6 ++++++ test/fixtures/rule_sets.yml | 4 ++++ test/fixtures/rules.yml | 9 +++++++++ test/services/rule_set_processor_test.rb | 9 +++++++++ 6 files changed, 46 insertions(+) create mode 100644 app/services/email_action/junk.rb diff --git a/app/models/email.rb b/app/models/email.rb index 22946d0..6e5bb56 100644 --- a/app/models/email.rb +++ b/app/models/email.rb @@ -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 diff --git a/app/services/email_action/junk.rb b/app/services/email_action/junk.rb new file mode 100644 index 0000000..9a3c738 --- /dev/null +++ b/app/services/email_action/junk.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module EmailAction + class Junk < Base + + def process(email) + email.junk = true + + email + end + + end +end diff --git a/test/fixtures/actions.yml b/test/fixtures/actions.yml index e3e8525..eabf490 100644 --- a/test/fixtures/actions.yml +++ b/test/fixtures/actions.yml @@ -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 diff --git a/test/fixtures/rule_sets.yml b/test/fixtures/rule_sets.yml index e4f863c..df07f83 100644 --- a/test/fixtures/rule_sets.yml +++ b/test/fixtures/rule_sets.yml @@ -70,3 +70,7 @@ postpone_past_valid: postpone_invalid: name: Postpone to invalid date enabled: true + +junk: + name: Junk mail + enabled: true diff --git a/test/fixtures/rules.yml b/test/fixtures/rules.yml index c9411bb..2969a72 100644 --- a/test/fixtures/rules.yml +++ b/test/fixtures/rules.yml @@ -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 diff --git a/test/services/rule_set_processor_test.rb b/test/services/rule_set_processor_test.rb index 11accd2..c067f6d 100644 --- a/test/services/rule_set_processor_test.rb +++ b/test/services/rule_set_processor_test.rb @@ -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