2020-12-31 11:56:13 +01:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class EmailImporterTest < ActiveSupport::TestCase
|
2021-01-23 18:09:55 +01:00
|
|
|
|
2020-12-31 15:33:35 +01:00
|
|
|
test "convert html to text when not multipart html only" do
|
|
|
|
email = email_from_eml("html_only.eml")
|
2020-12-31 11:56:13 +01:00
|
|
|
|
2021-01-24 09:46:03 +01:00
|
|
|
expected = /Attention, plus que quelques jours pour/
|
2021-01-01 22:34:14 +01:00
|
|
|
|
|
|
|
assert_match(expected, email.plain_body)
|
2020-12-31 15:33:35 +01:00
|
|
|
assert_no_html email.plain_body
|
|
|
|
end
|
|
|
|
|
|
|
|
test "convert html to text when multipart and html only" do
|
|
|
|
email = email_from_eml("html_only_multipart.eml")
|
|
|
|
|
2021-01-23 18:16:55 +01:00
|
|
|
expected = /Complément d''information : suite du ticket 2009P88471/
|
2021-01-01 22:34:14 +01:00
|
|
|
|
|
|
|
assert_match(expected, email.plain_body)
|
2020-12-31 15:33:35 +01:00
|
|
|
assert_no_html email.plain_body
|
|
|
|
end
|
|
|
|
|
2021-01-23 18:17:50 +01:00
|
|
|
test "convert html to text when base64-encoded html only" do
|
|
|
|
email = email_from_eml("html_only_base64.eml")
|
|
|
|
|
|
|
|
expected = /Type: Health and Safety/
|
|
|
|
|
|
|
|
assert_match(expected, email.plain_body)
|
|
|
|
assert_no_html email.plain_body
|
|
|
|
end
|
|
|
|
|
|
|
|
test "single delivered-to" do
|
|
|
|
email = email_from_eml("delivered_to_single.eml")
|
|
|
|
|
|
|
|
expected = ["delivered-to-1@example.com"]
|
|
|
|
actual = email.delivered_to
|
|
|
|
|
|
|
|
assert_equal expected, actual
|
|
|
|
end
|
|
|
|
|
|
|
|
test "multiple delivered-to" do
|
|
|
|
email = email_from_eml("delivered_to_multiple.eml")
|
|
|
|
|
|
|
|
expected = ["delivered-to-1@example.com", "delivered-to-2@example.com", "delivered-to-3@example.com"]
|
|
|
|
actual = email.delivered_to
|
|
|
|
|
|
|
|
assert_equal expected, actual
|
|
|
|
end
|
|
|
|
|
|
|
|
test "missing delivered-to fallback to To field" do
|
|
|
|
email = email_from_eml("delivered_to_missing.eml")
|
|
|
|
|
|
|
|
expected = ["to-foo@example.com"]
|
|
|
|
actual = email.delivered_to
|
|
|
|
|
|
|
|
assert_equal expected, actual
|
|
|
|
end
|
|
|
|
|
|
|
|
test "mail without content-type" do
|
|
|
|
email = email_from_eml("no_content_type.eml")
|
|
|
|
|
|
|
|
expected = /This is a RAID status update from megaraidsas-statusd/
|
|
|
|
|
|
|
|
assert_match(expected, email.plain_body)
|
|
|
|
end
|
2021-01-01 19:12:50 +01:00
|
|
|
|
2020-12-31 11:56:13 +01:00
|
|
|
end
|