chore: Improve email parsing using email trimmer gem (#3611)

Email parsing using email_trimmer gem

Fixes: #3539 , #2954, #3572
This commit is contained in:
Tejaswini Chile
2021-12-22 18:16:40 +05:30
committed by GitHub
parent 009abc1948
commit 44486fc8e1
9 changed files with 1232 additions and 32 deletions

View File

@@ -0,0 +1,15 @@
require 'rails_helper'
RSpec.describe HtmlParser do
include ActionMailbox::TestHelper
describe 'parsed mail decorator' do
let(:html_mail) { create_inbound_email_from_fixture('welcome_html.eml').mail }
it 'parse html content in the mail' do
decorated_html_mail = described_class.parse_reply(html_mail.text_part.decoded)
expect(decorated_html_mail[0..70]).to eq(
"I'm learning English as a first language for the past 13 years, but to "
)
end
end
end

View File

@@ -4,6 +4,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(:decorated_mail) { described_class.new(mail) }
let(:mail_with_no_subject) { create_inbound_email_from_fixture('mail_with_no_subject.eml').mail }
@@ -56,5 +57,13 @@ RSpec.describe MailPresenter do
it 'give email from in downcased format' do
expect(decorated_mail.from.first.eql?(mail.from.first.downcase)).to eq true
end
it 'parse html content in the mail' do
decorated_html_mail = described_class.new(html_mail)
expect(decorated_html_mail.subject).to eq('Fwd: How good are you in English? How did you improve your English?')
expect(decorated_html_mail.text_content[:reply][0..70]).to eq(
"I'm learning English as a first language for the past 13 years, but to "
)
end
end
end