mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 12:24:38 +08:00
FIX: support incoming emails with just an attachment
This commit is contained in:
parent
9bb7c3dcf0
commit
61930e092a
|
@ -238,11 +238,13 @@ module Email
|
||||||
text_content_type = @mail.text_part&.content_type
|
text_content_type = @mail.text_part&.content_type
|
||||||
elsif @mail.content_type.to_s["text/html"]
|
elsif @mail.content_type.to_s["text/html"]
|
||||||
html = fix_charset(@mail)
|
html = fix_charset(@mail)
|
||||||
else
|
elsif @mail.content_type.blank? || @mail.content_type["text/plain"]
|
||||||
text = fix_charset(@mail)
|
text = fix_charset(@mail)
|
||||||
text_content_type = @mail.content_type
|
text_content_type = @mail.content_type
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return unless text.present? || html.present?
|
||||||
|
|
||||||
if text.present?
|
if text.present?
|
||||||
text = trim_discourse_markers(text)
|
text = trim_discourse_markers(text)
|
||||||
text, elided_text = trim_reply_and_extract_elided(text)
|
text, elided_text = trim_reply_and_extract_elided(text)
|
||||||
|
@ -690,11 +692,17 @@ module Email
|
||||||
raise InvalidPostAction.new(e)
|
raise InvalidPostAction.new(e)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_whitelisted_attachment?(attachment)
|
||||||
|
attachment.content_type !~ SiteSetting.attachment_content_type_blacklist_regex &&
|
||||||
|
attachment.filename !~ SiteSetting.attachment_filename_blacklist_regex
|
||||||
|
end
|
||||||
|
|
||||||
def attachments
|
def attachments
|
||||||
# strip blacklisted attachments (mostly signatures)
|
# strip blacklisted attachments (mostly signatures)
|
||||||
@attachments ||= @mail.attachments.select do |attachment|
|
@attachments ||= begin
|
||||||
attachment.content_type !~ SiteSetting.attachment_content_type_blacklist_regex &&
|
attachments = @mail.attachments.select { |attachment| is_whitelisted_attachment?(attachment) }
|
||||||
attachment.filename !~ SiteSetting.attachment_filename_blacklist_regex
|
attachments << @mail if @mail.attachment? && is_whitelisted_attachment?(@mail)
|
||||||
|
attachments
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,6 @@ describe Email::Receiver do
|
||||||
|
|
||||||
expect { process(:reply_with_8bit_encoding) }.to change { topic.posts.count }
|
expect { process(:reply_with_8bit_encoding) }.to change { topic.posts.count }
|
||||||
expect(topic.posts.last.raw).to eq("hab vergessen kritische zeichen einzufügen:\näöüÄÖÜß")
|
expect(topic.posts.last.raw).to eq("hab vergessen kritische zeichen einzufügen:\näöüÄÖÜß")
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "prefers text over html" do
|
it "prefers text over html" do
|
||||||
|
@ -390,6 +389,12 @@ describe Email::Receiver do
|
||||||
expect(topic.posts.last.raw).to_not match(/text\.txt/)
|
expect(topic.posts.last.raw).to_not match(/text\.txt/)
|
||||||
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/)
|
||||||
|
end
|
||||||
|
|
||||||
it "supports liking via email" do
|
it "supports liking via email" do
|
||||||
expect { process(:like) }.to change(PostAction, :count)
|
expect { process(:like) }.to change(PostAction, :count)
|
||||||
end
|
end
|
||||||
|
|
1158
spec/fixtures/emails/attached_pdf_file.eml
vendored
Normal file
1158
spec/fixtures/emails/attached_pdf_file.eml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user