mirror of
https://github.com/discourse/discourse.git
synced 2025-02-06 03:18:23 +00:00
FIX: don't strip eml attachments from received emails
This commit is contained in:
parent
48501b0d45
commit
1ac3e5473a
@ -882,7 +882,7 @@ module Email
|
||||
def attachments
|
||||
# strip blacklisted attachments (mostly signatures)
|
||||
@attachments ||= begin
|
||||
attachments = @mail.attachments.select { |attachment| is_whitelisted_attachment?(attachment) }
|
||||
attachments = @mail.parts.select { |part| part.attachment? && is_whitelisted_attachment?(part) }
|
||||
attachments << @mail if @mail.attachment? && is_whitelisted_attachment?(@mail)
|
||||
attachments
|
||||
end
|
||||
|
@ -470,31 +470,43 @@ describe Email::Receiver do
|
||||
it "supports attachments" do
|
||||
SiteSetting.authorized_extensions = "txt"
|
||||
expect { process(:attached_txt_file) }.to change { topic.posts.count }
|
||||
expect(topic.posts.last.raw).to match(/text\.txt/)
|
||||
expect(topic.posts.last.raw).to match(/<a\sclass='attachment'[^>]*>text\.txt<\/a>/)
|
||||
expect(topic.posts.last.uploads.length).to eq 1
|
||||
end
|
||||
|
||||
it "supports eml attachments" do
|
||||
SiteSetting.authorized_extensions = "eml"
|
||||
expect { process(:attached_eml_file) }.to change { topic.posts.count }
|
||||
expect(topic.posts.last.raw).to match(/<a\sclass='attachment'[^>]*>sample\.eml<\/a>/)
|
||||
expect(topic.posts.last.uploads.length).to eq 1
|
||||
end
|
||||
|
||||
context "when attachment is rejected" do
|
||||
it "sends out the warning email" do
|
||||
expect { process(:attached_txt_file) }.to change { EmailLog.count }.by(1)
|
||||
expect(EmailLog.last.email_type).to eq("email_reject_attachment")
|
||||
expect(topic.posts.last.uploads.length).to eq 0
|
||||
end
|
||||
|
||||
it "doesn't send out the warning email if sender is staged user" do
|
||||
user.update_columns(staged: true)
|
||||
expect { process(:attached_txt_file) }.not_to change { EmailLog.count }
|
||||
expect(topic.posts.last.uploads.length).to eq 0
|
||||
end
|
||||
|
||||
it "creates the post with attachment missing message" do
|
||||
missing_attachment_regex = Regexp.escape(I18n.t('emails.incoming.missing_attachment', filename: "text.txt"))
|
||||
expect { process(:attached_txt_file) }.to change { topic.posts.count }
|
||||
expect(topic.posts.last.raw).to match(/#{missing_attachment_regex}/)
|
||||
expect(topic.posts.last.uploads.length).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
it "supports emails with just an attachment" do
|
||||
SiteSetting.authorized_extensions = "pdf"
|
||||
expect { process(:attached_pdf_file) }.to change { topic.posts.count }
|
||||
expect(topic.posts.last.raw).to match(/discourse\.pdf/)
|
||||
expect(topic.posts.last.raw).to match(/<a\sclass='attachment'[^>]*>discourse\.pdf<\/a>/)
|
||||
expect(topic.posts.last.uploads.length).to eq 1
|
||||
end
|
||||
|
||||
it "supports liking via email" do
|
||||
@ -638,7 +650,8 @@ describe Email::Receiver do
|
||||
it "supports any kind of attachments when 'allow_all_attachments_for_group_messages' is enabled" do
|
||||
SiteSetting.allow_all_attachments_for_group_messages = true
|
||||
expect { process(:attached_rb_file) }.to change(Topic, :count)
|
||||
expect(Post.last.raw).to match(/discourse\.rb/)
|
||||
expect(Post.last.raw).to match(/<a\sclass='attachment'[^>]*>discourse\.rb<\/a>/)
|
||||
expect(Post.last.uploads.length).to eq 1
|
||||
end
|
||||
|
||||
it "enables user's email_private_messages setting when user emails new topic to group" do
|
||||
|
BIN
spec/fixtures/emails/attached_eml_file.eml
vendored
Normal file
BIN
spec/fixtures/emails/attached_eml_file.eml
vendored
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user