@@ -267,6 +267,7 class MailHandler < ActionMailer::Base | |||
|
267 | 267 | def add_attachments(obj) |
|
268 | 268 | if email.attachments && email.attachments.any? |
|
269 | 269 | email.attachments.each do |attachment| |
|
270 | next unless accept_attachment?(attachment) | |
|
270 | 271 | obj.attachments << Attachment.create(:container => obj, |
|
271 | 272 | :file => attachment.decoded, |
|
272 | 273 | :filename => attachment.filename, |
@@ -276,6 +277,19 class MailHandler < ActionMailer::Base | |||
|
276 | 277 | end |
|
277 | 278 | end |
|
278 | 279 | |
|
280 | # Returns false if the +attachment+ of the incoming email should be ignored | |
|
281 | def accept_attachment?(attachment) | |
|
282 | @excluded ||= Setting.mail_handler_excluded_filenames.to_s.split(',').map(&:strip).reject(&:blank?) | |
|
283 | @excluded.each do |pattern| | |
|
284 | regexp = %r{\A#{Regexp.escape(pattern).gsub("\\*", ".*")}\z}i | |
|
285 | if attachment.filename.to_s =~ regexp | |
|
286 | logger.info "MailHandler: ignoring attachment #{attachment.filename} matching #{pattern}" | |
|
287 | return false | |
|
288 | end | |
|
289 | end | |
|
290 | true | |
|
291 | end | |
|
292 | ||
|
279 | 293 | # Adds To and Cc as watchers of the given object if the sender has the |
|
280 | 294 | # appropriate permission |
|
281 | 295 | def add_watchers(obj) |
@@ -5,6 +5,11 | |||
|
5 | 5 | <%= setting_text_area :mail_handler_body_delimiters, :rows => 5 %> |
|
6 | 6 | <em class="info"><%= l(:text_line_separated) %></em> |
|
7 | 7 | </p> |
|
8 | <p> | |
|
9 | <%= setting_text_field :mail_handler_excluded_filenames, :size => 60 %> | |
|
10 | <em class="info"><%= l(:text_comma_separated) %> | |
|
11 | <%= l(:label_example) %>: smime.p7s, *.vcf</em> | |
|
12 | </p> | |
|
8 | 13 | </div> |
|
9 | 14 | |
|
10 | 15 | <div class="box tabular settings"> |
@@ -407,6 +407,7 en: | |||
|
407 | 407 | setting_non_working_week_days: Non-working days |
|
408 | 408 | setting_jsonp_enabled: Enable JSONP support |
|
409 | 409 | setting_default_projects_tracker_ids: Default trackers for new projects |
|
410 | setting_mail_handler_excluded_filenames: Exclude attachments by name | |
|
410 | 411 | |
|
411 | 412 | permission_add_project: Create project |
|
412 | 413 | permission_add_subprojects: Create subprojects |
@@ -404,6 +404,7 fr: | |||
|
404 | 404 | setting_non_working_week_days: Jours non travaillés |
|
405 | 405 | setting_jsonp_enabled: Activer le support JSONP |
|
406 | 406 | setting_default_projects_tracker_ids: Trackers par défaut pour les nouveaux projets |
|
407 | setting_mail_handler_excluded_filenames: Exclure les fichiers attachés par leur nom | |
|
407 | 408 | |
|
408 | 409 | permission_add_project: Créer un projet |
|
409 | 410 | permission_add_subprojects: Créer des sous-projets |
@@ -147,6 +147,8 notified_events: | |||
|
147 | 147 | - issue_updated |
|
148 | 148 | mail_handler_body_delimiters: |
|
149 | 149 | default: '' |
|
150 | mail_handler_excluded_filenames: | |
|
151 | default: '' | |
|
150 | 152 | mail_handler_api_enabled: |
|
151 | 153 | default: 0 |
|
152 | 154 | mail_handler_api_key: |
@@ -759,6 +759,24 class MailHandlerTest < ActiveSupport::TestCase | |||
|
759 | 759 | end |
|
760 | 760 | end |
|
761 | 761 | |
|
762 | def test_attachments_that_match_mail_handler_excluded_filenames_should_be_ignored | |
|
763 | with_settings :mail_handler_excluded_filenames => '*.vcf, *.jpg' do | |
|
764 | issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'}) | |
|
765 | assert issue.is_a?(Issue) | |
|
766 | assert !issue.new_record? | |
|
767 | assert_equal 0, issue.reload.attachments.size | |
|
768 | end | |
|
769 | end | |
|
770 | ||
|
771 | def test_attachments_that_do_not_match_mail_handler_excluded_filenames_should_be_attached | |
|
772 | with_settings :mail_handler_excluded_filenames => '*.vcf, *.gif' do | |
|
773 | issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'}) | |
|
774 | assert issue.is_a?(Issue) | |
|
775 | assert !issue.new_record? | |
|
776 | assert_equal 1, issue.reload.attachments.size | |
|
777 | end | |
|
778 | end | |
|
779 | ||
|
762 | 780 | def test_email_with_long_subject_line |
|
763 | 781 | issue = submit_email('ticket_with_long_subject.eml') |
|
764 | 782 | assert issue.is_a?(Issue) |
General Comments 0
You need to be logged in to leave comments.
Login now