summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-09-29 11:50:49 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-09-29 11:50:49 +0000
commitcfc05d310e711de8326fbf9e71cbe7ffb264c54a (patch)
tree01de23a22d2f01dfa81e728e36bdd61a5e14c0e0 /app
parent2c97f9ecde0df139a7dff3582200b2af54d8b1c0 (diff)
downloadredmine-cfc05d310e711de8326fbf9e71cbe7ffb264c54a.tar.gz
redmine-cfc05d310e711de8326fbf9e71cbe7ffb264c54a.zip
Exclude attachments from incoming emails based on file name (#3413).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12167 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/models/mail_handler.rb14
-rw-r--r--app/views/settings/_mail_handler.html.erb5
2 files changed, 19 insertions, 0 deletions
diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb
index fec2675fc..3c9857873 100644
--- a/app/models/mail_handler.rb
+++ b/app/models/mail_handler.rb
@@ -267,6 +267,7 @@ class MailHandler < ActionMailer::Base
def add_attachments(obj)
if email.attachments && email.attachments.any?
email.attachments.each do |attachment|
+ next unless accept_attachment?(attachment)
obj.attachments << Attachment.create(:container => obj,
:file => attachment.decoded,
:filename => attachment.filename,
@@ -276,6 +277,19 @@ class MailHandler < ActionMailer::Base
end
end
+ # Returns false if the +attachment+ of the incoming email should be ignored
+ def accept_attachment?(attachment)
+ @excluded ||= Setting.mail_handler_excluded_filenames.to_s.split(',').map(&:strip).reject(&:blank?)
+ @excluded.each do |pattern|
+ regexp = %r{\A#{Regexp.escape(pattern).gsub("\\*", ".*")}\z}i
+ if attachment.filename.to_s =~ regexp
+ logger.info "MailHandler: ignoring attachment #{attachment.filename} matching #{pattern}"
+ return false
+ end
+ end
+ true
+ end
+
# Adds To and Cc as watchers of the given object if the sender has the
# appropriate permission
def add_watchers(obj)
diff --git a/app/views/settings/_mail_handler.html.erb b/app/views/settings/_mail_handler.html.erb
index 1051436b5..f255b4adc 100644
--- a/app/views/settings/_mail_handler.html.erb
+++ b/app/views/settings/_mail_handler.html.erb
@@ -5,6 +5,11 @@
<%= setting_text_area :mail_handler_body_delimiters, :rows => 5 %>
<em class="info"><%= l(:text_line_separated) %></em>
</p>
+ <p>
+ <%= setting_text_field :mail_handler_excluded_filenames, :size => 60 %>
+ <em class="info"><%= l(:text_comma_separated) %>
+ <%= l(:label_example) %>: smime.p7s, *.vcf</em>
+ </p>
</div>
<div class="box tabular settings">