Fix: handling UTF encoded mail (#4384)
This commit is contained in:
parent
7a8aa4ca2e
commit
821b953ee9
3 changed files with 25 additions and 1 deletions
|
@ -33,7 +33,7 @@ class MailPresenter < SimpleDelegator
|
|||
# encodes mail raw body if mail.content_type is plain/text
|
||||
# encodes mail raw body if mail.content_type is html/text
|
||||
def text_html_mail(mail_part)
|
||||
decoded = mail_part&.decoded || @mail.body&.decoded
|
||||
decoded = mail_part&.decoded || @mail.decoded
|
||||
encoded = encode_to_unicode(decoded)
|
||||
|
||||
encoded if html_mail_body? || text_mail_body?
|
||||
|
|
15
spec/fixtures/files/non_utf_encoded_mail.eml
vendored
Normal file
15
spec/fixtures/files/non_utf_encoded_mail.eml
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
In-Reply-To: <4e6e35f5a38b4_479f13bb90078178@small-app-01.mail>, <4e6e35f5a38b4_479f13bb90078178@small-app-01.mail>
|
||||
To: "Replies" <reply+6bdc3f4d-0bec-4515-a284-5d916fdde489@example.com>
|
||||
From: "=?UTF-8?B?2YXYqtis2LEg2LPZiNmCINmG2Ko=?=" <example@gmail.com>
|
||||
Date: Sun, 3 Apr 2022 11:48:20 -0700
|
||||
Message-ID: <CAEjnyt3uiyywAF3SrJzEedMRV5H5XG4aYvFrGdFwxtuGoRCc0w@mail.gmail.com>
|
||||
Subject: =?UTF-8?Q?=D8=A3=D9=87=D9=84=D9=8A=D9=86_=D8=B9?= =?UTF-8?Q?=D9=85=D9=8A=D9=84=D9=86=D8=A7_=D8=A7=D9=84?= =?UTF-8?Q?=D9=83=D8=B1=D9=8A=D9=85_?=
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: base64
|
||||
Content-Disposition: inline
|
||||
Precedence: bulk
|
||||
X-Autoreply: yes
|
||||
Auto-Submitted: auto-replied
|
||||
|
||||
2KPZhti42LHZiNin2Iwg2KPZhtinINij2K3Yqtin2KzZh9inINmB2YLYtyDZhNiq2YLZiNmFINio2KfZhNiq2K/ZgtmK2YIg2YHZiiDZhdmC2KfZhNiq2Yog2KfZhNi02K7YtdmK2KkK
|
|
@ -5,6 +5,7 @@ RSpec.describe MailPresenter do
|
|||
describe 'parsed mail decorator' do
|
||||
let(:mail) { create_inbound_email_from_fixture('welcome.eml').mail }
|
||||
let(:html_mail) { create_inbound_email_from_fixture('welcome_html.eml').mail }
|
||||
let(:ascii_mail) { create_inbound_email_from_fixture('non_utf_encoded_mail.eml').mail }
|
||||
let(:decorated_mail) { described_class.new(mail) }
|
||||
|
||||
let(:mail_with_no_subject) { create_inbound_email_from_fixture('mail_with_no_subject.eml').mail }
|
||||
|
@ -65,5 +66,13 @@ RSpec.describe MailPresenter do
|
|||
"I'm learning English as a first language for the past 13 years, but to "
|
||||
)
|
||||
end
|
||||
|
||||
it 'encodes email to UTF-8' do
|
||||
decorated_html_mail = described_class.new(ascii_mail)
|
||||
expect(decorated_html_mail.subject).to eq('أهلين عميلنا الكريم ')
|
||||
expect(decorated_html_mail.text_content[:reply][0..70]).to eq(
|
||||
'أنظروا، أنا أحتاجها فقط لتقوم بالتدقيق في مقالتي الشخصية'
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue