mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 03:32:45 +08:00
FIX: properly handle attachments in received emails
This regressed in 1ac3e547
when we added support for eml attachments.
This commit is contained in:
parent
0fa9c68d47
commit
db76e5a368
|
@ -931,18 +931,20 @@ module Email
|
||||||
end
|
end
|
||||||
|
|
||||||
def attachments
|
def attachments
|
||||||
# strip blacklisted attachments (mostly signatures)
|
|
||||||
@attachments ||= begin
|
@attachments ||= begin
|
||||||
attachments = @mail.parts.select { |part| part.attachment? && is_whitelisted_attachment?(part) }
|
attachments = @mail.attachments.select { |attachment| is_whitelisted_attachment?(attachment) }
|
||||||
attachments << @mail if @mail.attachment? && is_whitelisted_attachment?(@mail)
|
attachments << @mail if @mail.attachment? && is_whitelisted_attachment?(@mail)
|
||||||
|
|
||||||
|
@mail.parts.each do |part|
|
||||||
|
attachments << part if part.attachment? && is_whitelisted_attachment?(part)
|
||||||
|
end
|
||||||
|
|
||||||
attachments
|
attachments
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_post_with_attachments(options = {})
|
def create_post_with_attachments(options = {})
|
||||||
# deal with attachments
|
|
||||||
options[:raw] = add_attachments(options[:raw], options[:user], options)
|
options[:raw] = add_attachments(options[:raw], options[:user], options)
|
||||||
|
|
||||||
create_post(options)
|
create_post(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -522,10 +522,14 @@ describe Email::Receiver do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "supports attachments" do
|
it "supports attachments" do
|
||||||
SiteSetting.authorized_extensions = "txt"
|
SiteSetting.authorized_extensions = "txt|jpg"
|
||||||
expect { process(:attached_txt_file) }.to change { topic.posts.count }
|
expect { process(:attached_txt_file) }.to change { topic.posts.count }
|
||||||
expect(topic.posts.last.raw).to match(/<a\sclass='attachment'[^>]*>text\.txt<\/a>/)
|
expect(topic.posts.last.raw).to match(/<a\sclass='attachment'[^>]*>text\.txt<\/a>/)
|
||||||
expect(topic.posts.last.uploads.length).to eq 1
|
expect(topic.posts.last.uploads.length).to eq 1
|
||||||
|
|
||||||
|
expect { process(:apple_mail_attachment) }.to change { topic.posts.count }
|
||||||
|
expect(topic.posts.last.raw).to match /<img.+?src="\/uploads\/default\/original\//
|
||||||
|
expect(topic.posts.last.uploads.length).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it "supports eml attachments" do
|
it "supports eml attachments" do
|
||||||
|
|
1810
spec/fixtures/emails/apple_mail_attachment.eml
vendored
Normal file
1810
spec/fixtures/emails/apple_mail_attachment.eml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user