From 5aac2acf56fb42c342d4fafcd4ea9e997272f737 Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Thu, 15 Jul 2021 22:50:32 +0530 Subject: [PATCH] fix: Improve mail content parsing (#2638) --- app/mailboxes/support_mailbox.rb | 10 ++++++---- app/presenters/mail_presenter.rb | 10 +++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/mailboxes/support_mailbox.rb b/app/mailboxes/support_mailbox.rb index dad8b4bb1..4ff0bb0a5 100644 --- a/app/mailboxes/support_mailbox.rb +++ b/app/mailboxes/support_mailbox.rb @@ -9,10 +9,12 @@ class SupportMailbox < ApplicationMailbox :decorate_mail def process - find_or_create_contact - create_conversation - create_message - add_attachments_to_message + ActiveRecord::Base.transaction do + find_or_create_contact + create_conversation + create_message + add_attachments_to_message + end end private diff --git a/app/presenters/mail_presenter.rb b/app/presenters/mail_presenter.rb index 4b26e86a3..ce8433151 100644 --- a/app/presenters/mail_presenter.rb +++ b/app/presenters/mail_presenter.rb @@ -12,7 +12,7 @@ class MailPresenter < SimpleDelegator end def text_content - @decoded_text_content ||= encode_to_unicode(text_part&.decoded || mail.decoded || '') + @decoded_text_content ||= encode_to_unicode(text_part&.decoded || decoded_message || '') return {} if @decoded_text_content.blank? @@ -47,6 +47,14 @@ class MailPresenter < SimpleDelegator end end + def decoded_message + if mail.multipart? + return mail.text_part ? mail.text_part.decoded : nil + end + + mail.decoded + end + def number_of_attachments mail.attachments.count end