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
|
||||
elsif @mail.content_type.to_s["text/html"]
|
||||
html = fix_charset(@mail)
|
||||
else
|
||||
elsif @mail.content_type.blank? || @mail.content_type["text/plain"]
|
||||
text = fix_charset(@mail)
|
||||
text_content_type = @mail.content_type
|
||||
end
|
||||
|
||||
return unless text.present? || html.present?
|
||||
|
||||
if text.present?
|
||||
text = trim_discourse_markers(text)
|
||||
text, elided_text = trim_reply_and_extract_elided(text)
|
||||
|
@ -690,12 +692,18 @@ module Email
|
|||
raise InvalidPostAction.new(e)
|
||||
end
|
||||
|
||||
def attachments
|
||||
# strip blacklisted attachments (mostly signatures)
|
||||
@attachments ||= @mail.attachments.select do |attachment|
|
||||
def is_whitelisted_attachment?(attachment)
|
||||
attachment.content_type !~ SiteSetting.attachment_content_type_blacklist_regex &&
|
||||
attachment.filename !~ SiteSetting.attachment_filename_blacklist_regex
|
||||
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
|
||||
|
||||
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(topic.posts.last.raw).to eq("hab vergessen kritische zeichen einzufügen:\näöüÄÖÜß")
|
||||
|
||||
end
|
||||
|
||||
it "prefers text over html" do
|
||||
|
@ -390,6 +389,12 @@ describe Email::Receiver do
|
|||
expect(topic.posts.last.raw).to_not match(/text\.txt/)
|
||||
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
|
||||
expect { process(:like) }.to change(PostAction, :count)
|
||||
end
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue