From 3b107f0a31249e625276eae5ad675c869ef78260 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 4 Jul 2018 13:37:56 +0200 Subject: [PATCH] Fixes issue #2087 - No mime_type on nil message (no message body) / email will not be processed. --- app/models/channel/email_parser.rb | 2 +- test/data/mail/mail067.box | 19 +++++++++++++++++++ test/unit/email_process_test.rb | 27 +++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 test/data/mail/mail067.box diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index a475bc463..4b5d10bf2 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -504,7 +504,7 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again def message_body_hash(mail) message = [mail.html_part, mail.text_part, mail].find { |m| m&.body.present? } - if message.mime_type.nil? || message.mime_type.match?(%r{^text/(plain|html)$}) + if message.present? && (message.mime_type.nil? || message.mime_type.match?(%r{^text/(plain|html)$})) content_type = message.mime_type || 'text/plain' body = body_text(message, strict_html: content_type.eql?('text/html')) end diff --git a/test/data/mail/mail067.box b/test/data/mail/mail067.box new file mode 100644 index 000000000..fe7137702 --- /dev/null +++ b/test/data/mail/mail067.box @@ -0,0 +1,19 @@ +Return-Path: +X-Original-To: info@example.de +Delivered-To: m032b9f7@dd38536.example.com +Received: from dd38536.example.com (dd0801.example.com [1.1.1.1]) + by dd38536.example.com (Postfix) with ESMTPSA id 343463D42403 + for ; Wed, 4 Jul 2018 10:02:32 +0200 (CEST) +MIME-Version: 1.0 +Content-Type: text/plain; charset=ISO-8859-1 +Content-Transfer-Encoding: 8bit +X-SenderIP: 1.1.1.1 +User-Agent: ALL-INKL Webmail 2.11 +Subject: Testmail - Alias in info@example.de Gruppe +From: "Bob Smith | deal" +To: info@example.de +Message-Id: <20180704080232.343463D42403@dd38536.example.com> +Date: Wed, 4 Jul 2018 10:02:32 +0200 (CEST) +X-KasLoop: m032b9f7 + + diff --git a/test/unit/email_process_test.rb b/test/unit/email_process_test.rb index e4b934f20..5819e8a2a 100644 --- a/test/unit/email_process_test.rb +++ b/test/unit/email_process_test.rb @@ -2804,6 +2804,33 @@ Some Text', }, }, }, + { + data: File.read(Rails.root.join('test', 'data', 'mail', 'mail067.box')), + success: true, + result: { + 0 => { + priority: '2 normal', + title: 'Testmail - Alias in info@example.de Gruppe', + }, + 1 => { + from: 'Bob Smith | deal ', + sender: 'Customer', + type: 'email', + subject: 'Testmail - Alias in info@example.de Gruppe', + body: 'no visible content', + }, + }, + verify: { + users: [ + { + firstname: 'Bob', + lastname: 'Smith | deal', + fullname: 'Bob Smith | deal', + email: 'info@example.de', + }, + ], + }, + }, ] assert_process(files) end