FEATURE: add indication if incoming email attachment was rejected and inform sender about it (#6376)

* FEATURE: add indication if incoming email attachment was rejected and inform sender about it

* include errors for rejected attachments in email

* don't send warning email to staged users

* use user object instead of user_id in add_attachments method
This commit is contained in:
Maja Komel
2018-10-04 16:08:28 +02:00
committed by Régis Hanol
parent 6ad13e5ae9
commit 361ad7ed2b
3 changed files with 57 additions and 6 deletions

View File

@ -465,10 +465,24 @@ describe Email::Receiver do
SiteSetting.authorized_extensions = "txt"
expect { process(:attached_txt_file) }.to change { topic.posts.count }
expect(topic.posts.last.raw).to match(/text\.txt/)
end
SiteSetting.authorized_extensions = "csv"
expect { process(:attached_txt_file_2) }.to change { topic.posts.count }
expect(topic.posts.last.raw).to_not match(/text\.txt/)
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")
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 }
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}/)
end
end
it "supports emails with just an attachment" do