2020-10-17 12:46:09 +02:00
|
|
|
class InMailbox < ApplicationMailbox
|
|
|
|
def process
|
2021-01-22 14:50:56 +01:00
|
|
|
email_importer = EmailImporter.new
|
2020-12-28 00:53:14 +01:00
|
|
|
repository = EmailRepository.new
|
2021-01-22 14:50:56 +01:00
|
|
|
rules_evaluator = RulesEvaluator.new
|
2020-10-28 23:53:42 +01:00
|
|
|
|
2020-12-31 11:56:13 +01:00
|
|
|
email = email_importer.import(mail)
|
2021-01-22 14:50:56 +01:00
|
|
|
|
|
|
|
RuleSet.enabled.each do |rule_set|
|
|
|
|
if rules_evaluator.evaluate(email, rule_set)
|
|
|
|
rule_set.actions.enabled.each do |action|
|
|
|
|
klass = action.class_name.constantize
|
|
|
|
email = klass.new.process(email)
|
|
|
|
rescue NameError => ex
|
|
|
|
# TODO: log a warning
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-31 11:56:13 +01:00
|
|
|
repository.save(email)
|
2020-10-28 23:53:42 +01:00
|
|
|
end
|
2020-10-17 12:46:09 +02:00
|
|
|
end
|