2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-05 08:59:27 +08:00

FIX: support incoming emails with just an attachment

This commit is contained in:
Régis Hanol 2018-02-16 18:14:56 +01:00
parent 9bb7c3dcf0
commit 61930e092a
3 changed files with 1176 additions and 5 deletions

View file

@ -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,11 +692,17 @@ module Email
raise InvalidPostAction.new(e)
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
# strip blacklisted attachments (mostly signatures)
@attachments ||= @mail.attachments.select do |attachment|
attachment.content_type !~ SiteSetting.attachment_content_type_blacklist_regex &&
attachment.filename !~ SiteSetting.attachment_filename_blacklist_regex
@attachments ||= begin
attachments = @mail.attachments.select { |attachment| is_whitelisted_attachment?(attachment) }
attachments << @mail if @mail.attachment? && is_whitelisted_attachment?(@mail)
attachments
end
end