mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 06:10:10 +08:00
FIX: don't duplicate attachments
This commit is contained in:
@ -939,6 +939,7 @@ module Email
|
|||||||
attachments << part if part.attachment? && is_whitelisted_attachment?(part)
|
attachments << part if part.attachment? && is_whitelisted_attachment?(part)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
attachments.uniq!
|
||||||
attachments
|
attachments
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -524,47 +524,52 @@ describe Email::Receiver do
|
|||||||
it "supports attachments" do
|
it "supports attachments" do
|
||||||
SiteSetting.authorized_extensions = "txt|jpg"
|
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>/)
|
post = topic.posts.last
|
||||||
expect(topic.posts.last.uploads.length).to eq 1
|
expect(post.raw).to match(/\APlease find some text file attached\.\s+<a class='attachment' href='\/uploads\/default\/original\/.+?txt'>text\.txt<\/a> \(20 Bytes\)\z/)
|
||||||
|
expect(post.uploads.size).to eq 1
|
||||||
|
|
||||||
expect { process(:apple_mail_attachment) }.to change { topic.posts.count }
|
expect { process(:apple_mail_attachment) }.to change { topic.posts.count }
|
||||||
expect(topic.posts.last.raw).to match /<img.+?src="\/uploads\/default\/original\//
|
post = topic.posts.last
|
||||||
expect(topic.posts.last.uploads.length).to eq 1
|
expect(post.raw).to match(/\APicture below\.\s+<img.+?src="\/uploads\/default\/original\/.+?jpeg" class="">\s+Picture above\.\z/)
|
||||||
|
expect(post.uploads.size).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it "supports eml attachments" do
|
it "supports eml attachments" do
|
||||||
SiteSetting.authorized_extensions = "eml"
|
SiteSetting.authorized_extensions = "eml"
|
||||||
expect { process(:attached_eml_file) }.to change { topic.posts.count }
|
expect { process(:attached_eml_file) }.to change { topic.posts.count }
|
||||||
expect(topic.posts.last.raw).to match(/<a\sclass='attachment'[^>]*>sample\.eml<\/a>/)
|
post = topic.posts.last
|
||||||
expect(topic.posts.last.uploads.length).to eq 1
|
expect(post.raw).to match(/\APlease find the eml file attached\.\s+<a class='attachment' href='\/uploads\/default\/original\/.+?eml'>sample\.eml<\/a> \(193 Bytes\)\z/)
|
||||||
|
expect(post.uploads.size).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when attachment is rejected" do
|
context "when attachment is rejected" do
|
||||||
it "sends out the warning email" do
|
it "sends out the warning email" do
|
||||||
expect { process(:attached_txt_file) }.to change { EmailLog.count }.by(1)
|
expect { process(:attached_txt_file) }.to change { EmailLog.count }.by(1)
|
||||||
expect(EmailLog.last.email_type).to eq("email_reject_attachment")
|
expect(EmailLog.last.email_type).to eq("email_reject_attachment")
|
||||||
expect(topic.posts.last.uploads.length).to eq 0
|
expect(topic.posts.last.uploads.size).to eq 0
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't send out the warning email if sender is staged user" do
|
it "doesn't send out the warning email if sender is staged user" do
|
||||||
user.update_columns(staged: true)
|
user.update_columns(staged: true)
|
||||||
expect { process(:attached_txt_file) }.not_to change { EmailLog.count }
|
expect { process(:attached_txt_file) }.not_to change { EmailLog.count }
|
||||||
expect(topic.posts.last.uploads.length).to eq 0
|
expect(topic.posts.last.uploads.size).to eq 0
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates the post with attachment missing message" do
|
it "creates the post with attachment missing message" do
|
||||||
missing_attachment_regex = Regexp.escape(I18n.t('emails.incoming.missing_attachment', filename: "text.txt"))
|
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 { process(:attached_txt_file) }.to change { topic.posts.count }
|
||||||
expect(topic.posts.last.raw).to match(/#{missing_attachment_regex}/)
|
post = topic.posts.last
|
||||||
expect(topic.posts.last.uploads.length).to eq 0
|
expect(post.raw).to match(/#{missing_attachment_regex}/)
|
||||||
|
expect(post.uploads.size).to eq 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "supports emails with just an attachment" do
|
it "supports emails with just an attachment" do
|
||||||
SiteSetting.authorized_extensions = "pdf"
|
SiteSetting.authorized_extensions = "pdf"
|
||||||
expect { process(:attached_pdf_file) }.to change { topic.posts.count }
|
expect { process(:attached_pdf_file) }.to change { topic.posts.count }
|
||||||
expect(topic.posts.last.raw).to match(/<a\sclass='attachment'[^>]*>discourse\.pdf<\/a>/)
|
post = topic.posts.last
|
||||||
expect(topic.posts.last.uploads.length).to eq 1
|
expect(post.raw).to match(/\A\s+<a class='attachment' href='\/uploads\/default\/original\/.+?pdf'>discourse\.pdf<\/a> \(64 KB\)\z/)
|
||||||
|
expect(post.uploads.size).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it "supports liking via email" do
|
it "supports liking via email" do
|
||||||
|
Reference in New Issue
Block a user