Feature #32085 » 32085-allow-newline-as-separator-v2.patch
| app/models/attachment.rb | ||
|---|---|---|
|
extension = extension.downcase.sub(/\A\.+/, '')
|
||
|
unless extensions.is_a?(Array)
|
||
|
extensions = extensions.to_s.split(",").map(&:strip)
|
||
|
extensions = extensions.to_s.split(/[\s,]+/)
|
||
|
end
|
||
|
extensions = extensions.map {|s| s.downcase.sub(/\A\.+/, '')}.reject(&:blank?)
|
||
|
extensions.include?(extension)
|
||
| app/models/mail_handler.rb | ||
|---|---|---|
|
# 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 ||= Setting.mail_handler_excluded_filenames.to_s.split(/[\s,]+/).reject(&:blank?)
|
||
|
@excluded.each do |pattern|
|
||
|
if Setting.mail_handler_enable_regex_excluded_filenames?
|
||
|
regexp = %r{\A#{pattern}\z}i
|
||
| test/unit/attachment_test.rb | ||
|---|---|---|
|
end
|
||
|
def test_extension_should_be_validated_against_denied_extensions
|
||
|
with_settings :attachment_extensions_denied => "txt, png" do
|
||
|
with_settings :attachment_extensions_denied => "txt, png\r\ncsv" do
|
||
|
a = Attachment.new(:container => Issue.find(1),
|
||
|
:file => mock_file_with_options(:original_filename => "test.jpeg"),
|
||
|
:author => User.find(1))
|
||
| ... | ... | |
|
end
|
||
|
def test_valid_extension_should_be_case_insensitive
|
||
|
with_settings :attachment_extensions_allowed => "txt, Png" do
|
||
|
with_settings :attachment_extensions_allowed => "txt, Png\r\ncsv" do
|
||
|
assert Attachment.valid_extension?(".pnG")
|
||
|
assert !Attachment.valid_extension?(".jpeg")
|
||
|
end
|
||
|
with_settings :attachment_extensions_denied => "txt, Png" do
|
||
|
with_settings :attachment_extensions_denied => "txt, Png\r\ncsv" do
|
||
|
assert !Attachment.valid_extension?(".pnG")
|
||
|
assert Attachment.valid_extension?(".jpeg")
|
||
|
end
|
||
| test/unit/mail_handler_test.rb | ||
|---|---|---|
|
FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
|
||
|
def setup
|
||
|
set_tmp_attachments_directory
|
||
|
ActionMailer::Base.deliveries.clear
|
||
|
Setting.notified_events = Redmine::Notifiable.all.collect(&:name)
|
||
|
User.current = nil
|
||
| ... | ... | |
|
end
|
||
|
def test_add_issue_from_apple_mail
|
||
|
set_tmp_attachments_directory
|
||
|
issue = submit_email(
|
||
|
'apple_mail_with_attachment.eml',
|
||
|
:issue => {:project => 'ecookbook'}
|
||
| ... | ... | |
|
end
|
||
|
def test_thunderbird_with_attachment_ja
|
||
|
set_tmp_attachments_directory
|
||
|
issue = submit_email(
|
||
|
'thunderbird_with_attachment_ja.eml',
|
||
|
:issue => {:project => 'ecookbook'}
|
||
| ... | ... | |
|
end
|
||
|
def test_gmail_with_attachment_ja
|
||
|
set_tmp_attachments_directory
|
||
|
issue = submit_email(
|
||
|
'gmail_with_attachment_ja.eml',
|
||
|
:issue => {:project => 'ecookbook'}
|
||
| ... | ... | |
|
end
|
||
|
def test_thunderbird_with_attachment_latin1
|
||
|
set_tmp_attachments_directory
|
||
|
issue = submit_email(
|
||
|
'thunderbird_with_attachment_iso-8859-1.eml',
|
||
|
:issue => {:project => 'ecookbook'}
|
||
| ... | ... | |
|
end
|
||
|
def test_gmail_with_attachment_latin1
|
||
|
set_tmp_attachments_directory
|
||
|
issue = submit_email(
|
||
|
'gmail_with_attachment_iso-8859-1.eml',
|
||
|
:issue => {:project => 'ecookbook'}
|
||
| ... | ... | |
|
end
|
||
|
def test_mail_with_attachment_latin2
|
||
|
set_tmp_attachments_directory
|
||
|
issue = submit_email(
|
||
|
'ticket_with_text_attachment_iso-8859-2.eml',
|
||
|
:issue => {:project => 'ecookbook'}
|
||
| ... | ... | |
|
end
|
||
|
def test_reply_to_a_nonexistent_issue
|
||
|
set_tmp_attachments_directory
|
||
|
Issue.find(2).destroy
|
||
|
assert_no_difference 'Issue.count' do
|
||
|
assert_no_difference 'Journal.count' do
|
||
| ... | ... | |
|
end
|
||
|
def test_attachments_that_match_mail_handler_excluded_filenames_should_be_ignored
|
||
|
with_settings :mail_handler_excluded_filenames => "*.vcf,\n *.jpg" do
|
||
|
with_settings :mail_handler_excluded_filenames => "*.vcf,\n *.jpg\r\n*.csv" do
|
||
|
issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
|
||
|
assert issue.is_a?(Issue)
|
||
|
assert !issue.new_record?
|
||
| ... | ... | |
|
end
|
||
|
def test_attachments_that_match_mail_handler_excluded_filenames_by_regex_should_be_ignored
|
||
|
with_settings :mail_handler_excluded_filenames => '.+\.vcf,(pa|nut)ella\.jpg',
|
||
|
with_settings :mail_handler_excluded_filenames => ".+\\.vcf,(pa|nut)ella\\.jpg\r\n.+\\.csv",
|
||
|
:mail_handler_enable_regex_excluded_filenames => 1 do
|
||
|
issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
|
||
|
assert issue.is_a?(Issue)
|
||