summaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2018-03-03 04:29:54 +0000
committerGo MAEDA <maeda@farend.jp>2018-03-03 04:29:54 +0000
commit76f12c1316ebcf93bc86ccd449b6032c378cc760 (patch)
tree65c3cf6726b3c3a048d296dbeaa1dc10f158e7ec /app/models
parent03c8fc51033ed68920bd74e6caf21d51a2db6f9f (diff)
downloadredmine-76f12c1316ebcf93bc86ccd449b6032c378cc760.tar.gz
redmine-76f12c1316ebcf93bc86ccd449b6032c378cc760.zip
Optional regex for filtering attachments on incoming emails (#27025).
Patch by Jan Schulz-Hofen. git-svn-id: http://svn.redmine.org/redmine/trunk@17225 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rwxr-xr-xapp/models/mail_handler.rb4
-rw-r--r--app/models/setting.rb19
2 files changed, 16 insertions, 7 deletions
diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb
index 518e8c84b..0231d84db 100755
--- a/app/models/mail_handler.rb
+++ b/app/models/mail_handler.rb
@@ -310,7 +310,11 @@ class MailHandler < ActionMailer::Base
def accept_attachment?(attachment)
@excluded ||= Setting.mail_handler_excluded_filenames.to_s.split(',').map(&:strip).reject(&:blank?)
@excluded.each do |pattern|
+ if Setting.mail_handler_enable_regex_excluded_filenames?
+ regexp = %r{\A#{pattern}\z}i
+ else
regexp = %r{\A#{Regexp.escape(pattern).gsub("\\*", ".*")}\z}i
+ end
if attachment.filename.to_s =~ regexp
logger.info "MailHandler: ignoring attachment #{attachment.filename} matching #{pattern}"
return false
diff --git a/app/models/setting.rb b/app/models/setting.rb
index b73aae4f2..d66470d0a 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -143,21 +143,26 @@ class Setting < ActiveRecord::Base
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'
+ [[:mail_handler_enable_regex_delimiters, :mail_handler_body_delimiters, /[\r\n]+/],
+ [:mail_handler_enable_regex_excluded_filenames, :mail_handler_excluded_filenames, /\s*,\s*/]
+ ].each do |enable_regex, regex_field, delimiter|
+
+ if settings.key?(regex_field) || settings.key?(enable_regex)
+ regexp = Setting.send("#{enable_regex}?")
+ if settings.key?(enable_regex)
+ regexp = settings[enable_regex].to_s != '0'
end
if regexp
- settings[:mail_handler_body_delimiters].to_s.split(/[\r\n]+/).each do |delimiter|
+ settings[regex_field].to_s.split(delimiter).each do |value|
begin
- Regexp.new(delimiter)
+ Regexp.new(value)
rescue RegexpError => e
- messages << [:mail_handler_body_delimiters, "#{l('activerecord.errors.messages.not_a_regexp')} (#{e.message})"]
+ messages << [regex_field, "#{l('activerecord.errors.messages.not_a_regexp')} (#{e.message})"]
end
end
end
end
+ end
messages
end