diff --git a/app/services/email_importer.rb b/app/services/email_importer.rb index b95f2f2..022d3b6 100644 --- a/app/services/email_importer.rb +++ b/app/services/email_importer.rb @@ -45,10 +45,10 @@ class EmailImporter else mail.parts[0].decoded end - elsif mail.content_type.match?(/text\/html/) - Nokogiri::HTML(mail.body.decoded).text + elsif mail.content_type && mail.content_type.match?(/text\/html/) + Nokogiri::HTML(mail.decoded).text else - mail.body.decoded + mail.decoded end end diff --git a/test/fixtures/files/no_content_type.eml b/test/fixtures/files/no_content_type.eml new file mode 100644 index 0000000..dec8e79 --- /dev/null +++ b/test/fixtures/files/no_content_type.eml @@ -0,0 +1,28 @@ +Return-Path: +Delivered-To: delivered-to-1@example.com +Received: by mx.example.com (Postfix, from userid 1000) + id 8B3187F5D3; Sat, 12 Sep 2020 06:43:04 +0200 (CEST) +From: from-foo@example.com +To: Foo +Subject: Cron Dummy subject +Date: Sat, 12 Sep 2020 06:43:02 +0200 (CEST) +Message-Id: + +This is a RAID status update from megaraidsas-statusd. The megaraidsas-status +program reports that one of the RAIDs changed state: + +-- Arrays informations -- +-- ID | Type | Size | Status +a0d0 | RAID 1 | 476GiB | optimal +a0d1 | RAID 1 | 278GiB | optimal + +-- Disks informations +-- ID | Model | Status | Warnings +a0e32s0 | ATA KINGSTON SKC6005 476GiB | online | errs: media:0 other:6 predictive-failure +a0e32s1 | ATA SAMSUNG MZ7LN512 476GiB a0d0 | predictive-failure +a0e32s2 | SEAGATE ST3300657SS 279GiB | online +a0e32s3 | SEAGATE ST3300657SS 279GiB | online + +There is at least one disk/array in a NOT OPTIMAL state. + +Report from /etc/init.d/megaraidsas-statusd on kampn-kvm00 diff --git a/test/services/email_importer_test.rb b/test/services/email_importer_test.rb index 16a8e71..5641c4b 100644 --- a/test/services/email_importer_test.rb +++ b/test/services/email_importer_test.rb @@ -102,4 +102,12 @@ class EmailImporterTest < ActiveSupport::TestCase 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 end