postmaster_filter.rb 934 B

12345678910111213141516171819202122232425
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class PostmasterFilter < ApplicationModel
  3. store :perform
  4. store :match
  5. validates :name, presence: true
  6. before_create :validate_condition
  7. before_update :validate_condition
  8. def validate_condition
  9. raise Exceptions::UnprocessableEntity, 'Min. one match rule needed!' if match.blank?
  10. match.each_value do |meta|
  11. raise Exceptions::UnprocessableEntity, 'operator invalid, ony "contains" and "contains not" is supported' if meta['operator'].blank? || meta['operator'] !~ /^(contains|contains not)$/
  12. raise Exceptions::UnprocessableEntity, 'value invalid/empty' if meta['value'].blank?
  13. begin
  14. Channel::Filter::Match::EmailRegex.match(value: 'test content', match_rule: meta['value'], check_mode: true)
  15. rescue => e
  16. raise Exceptions::UnprocessableEntity, e.message
  17. end
  18. end
  19. true
  20. end
  21. end