FIX: don't blow up on badly encoding incoming email body

This commit is contained in:
Régis Hanol 2018-01-30 23:47:58 +01:00
parent 361030d8ad
commit c6fac68ccd
2 changed files with 9 additions and 2 deletions

View File

@ -33,14 +33,19 @@ class IncomingEmailDetailsSerializer < ApplicationSerializer
end
def subject
@mail.subject.presence || "(no subject)"
@mail.subject.presence || I18n.t("emails.incoming.no_subject")
end
def body
body = @mail.text_part.decoded rescue nil
body ||= @mail.html_part.decoded rescue nil
body ||= @mail.body.decoded rescue nil
body.strip.truncate_words(100, escape: false)
return I18n.t("emails.incoming.no_body") if body.blank?
body.encode("utf-8", invalid: :replace, undef: :replace, replace: "")
.strip
.truncate_words(100, escape: false)
end
end

View File

@ -63,6 +63,8 @@ en:
default_subject: "This topic needs a title"
show_trimmed_content: "Show trimmed content"
maximum_staged_user_per_email_reached: "Reached maximum number of staged users created per email."
no_subject: "(no subject)"
no_body: "(no body)"
errors:
empty_email_error: "Happens when the raw mail we received was blank."
no_message_id_error: "Happens when the mail has no 'Message-Id' header."