mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 00:56:19 +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,12 +692,18 @@ module Email
|
||||||
raise InvalidPostAction.new(e)
|
raise InvalidPostAction.new(e)
|
||||||
end
|
end
|
||||||
|
|
||||||
def attachments
|
def is_whitelisted_attachment?(attachment)
|
||||||
# strip blacklisted attachments (mostly signatures)
|
|
||||||
@attachments ||= @mail.attachments.select do |attachment|
|
|
||||||
attachment.content_type !~ SiteSetting.attachment_content_type_blacklist_regex &&
|
attachment.content_type !~ SiteSetting.attachment_content_type_blacklist_regex &&
|
||||||
attachment.filename !~ SiteSetting.attachment_filename_blacklist_regex
|
attachment.filename !~ SiteSetting.attachment_filename_blacklist_regex
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def attachments
|
||||||
|
# strip blacklisted attachments (mostly signatures)
|
||||||
|
@attachments ||= begin
|
||||||
|
attachments = @mail.attachments.select { |attachment| is_whitelisted_attachment?(attachment) }
|
||||||
|
attachments << @mail if @mail.attachment? && is_whitelisted_attachment?(@mail)
|
||||||
|
attachments
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_post_with_attachments(options = {})
|
def create_post_with_attachments(options = {})
|
||||||
|
|
|
@ -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