diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-12-13 18:46:29 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-12-13 18:46:29 +0000 |
commit | f30462595e83f512cd5f29246a4542773595a224 (patch) | |
tree | 56eb7ce08ea5a8c6e0c21806e067c8c652e652b9 /app/models/setting.rb | |
parent | 3186130966cea85d842faf5c038006f8fb40bb61 (diff) | |
download | redmine-f30462595e83f512cd5f29246a4542773595a224.tar.gz redmine-f30462595e83f512cd5f29246a4542773595a224.zip |
Optional Regex delimiters to truncate incoming emails (#5864).
git-svn-id: http://svn.redmine.org/redmine/trunk@16065 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/setting.rb')
-rw-r--r-- | app/models/setting.rb | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/app/models/setting.rb b/app/models/setting.rb index 934e6bf2a..321b1cd38 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -120,8 +120,12 @@ class Setting < ActiveRecord::Base # Updates multiple settings from params and sends a security notification if needed def self.set_all_from_params(settings) - return false unless settings.is_a?(Hash) + return nil unless settings.is_a?(Hash) settings = settings.dup.symbolize_keys + + errors = validate_all_from_params(settings) + return errors if errors.present? + changes = [] settings.each do |name, value| next unless available_settings[name.to_s] @@ -134,7 +138,29 @@ class Setting < ActiveRecord::Base if changes.any? Mailer.security_settings_updated(changes) end - true + nil + end + + def self.validate_all_from_params(settings) + messages = [] + + if settings.key?(:mail_handler_body_delimiters) || settings.key?(:mail_handler_enable_regex_delimiters) + regexp = Setting.mail_handler_enable_regex_delimiters? + if settings.key?(:mail_handler_enable_regex_delimiters) + regexp = settings[:mail_handler_enable_regex_delimiters].to_s != '0' + end + if regexp + settings[:mail_handler_body_delimiters].to_s.split(/[\r\n]+/).each do |delimiter| + begin + Regexp.new(delimiter) + rescue RegexpError => e + messages << [:mail_handler_body_delimiters, "#{l('activerecord.errors.messages.not_a_regexp')} (#{e.message})"] + end + end + end + end + + messages end # Sets a setting value from params |