From a77dce2850045f76f8ae9ab5f7c0c74538a10b9e Mon Sep 17 00:00:00 2001 From: Mikhail Voronyuk Date: Sun, 8 Mar 2015 11:44:39 +0400 Subject: [PATCH] Filter email attachments based on content (ignore files listed in specific directory) issue #19289 --- app/models/mail_handler.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 75c90d7..b30a788 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -287,6 +287,21 @@ class MailHandler < ActionMailer::Base return false end end + # check if the attachment is match some ignored file + Dir::Tmpname.create('tmpattach') do |tmpfilename| + tmpfilenameextended = "#{tmpfilename}#{attachment.filename}" + File.open(tmpfilenameextended, 'wb') do |file| + file.write(attachment.body.decoded) + end + Dir['/home/redmine/redmine-ignored-attachments/*'].each do |ignoredf| + if FileUtils.cmp(ignoredf, tmpfilenameextended) + logger.info "MailHandler: ignoring attachment #{attachment.filename} matching #{ignoredf}" + FileUtils.rm(tmpfilenameextended) + return false + end + end + FileUtils.rm(tmpfilenameextended) + end true end -- 1.8.4.5