diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index b8b78be9f..2ddfec7bc 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -713,6 +713,7 @@ module Mail class Field def raw_value value = Encode.conv('utf8', @raw_value) + return value if value.blank? value.sub(/^.+?:(\s|)/, '') end end diff --git a/app/models/channel/filter/identify_sender.rb b/app/models/channel/filter/identify_sender.rb index 38c88aed3..e8594c3cc 100644 --- a/app/models/channel/filter/identify_sender.rb +++ b/app/models/channel/filter/identify_sender.rb @@ -93,6 +93,7 @@ module Channel::Filter::IdentifySender next if !mail[item.to_sym].addrs items = mail[item.to_sym].addrs items.each { |address_data| + next if address_data.address.blank? user_create( firstname: address_data.display_name, lastname: '', @@ -114,7 +115,7 @@ module Channel::Filter::IdentifySender if recipient =~ /^(.+?)<(.+?)>/ display_name = $1 end - next if address.empty? + next if address.blank? user_create( firstname: display_name, lastname: '', @@ -126,6 +127,9 @@ module Channel::Filter::IdentifySender end def self.user_create(data) + if data[:email] !~ /@/ + data[:email] += '@local' + end user = User.find_by(email: data[:email].downcase) if !user user = User.find_by(login: data[:email].downcase) diff --git a/test/fixtures/mail52.box b/test/fixtures/mail52.box new file mode 100644 index 000000000..fa5795333 --- /dev/null +++ b/test/fixtures/mail52.box @@ -0,0 +1,11 @@ +Return-Path: <> +From: MAILER-DAEMON@example.com (Mail Delivery System) +Content-Type: text/plain; + charset=iso-8859-1 +Content-Transfer-Encoding: quoted-printable +Subject: Undelivered Mail Returned to Sender +To: you@example.com +Date: Fri, 4 May 2018 14:01:03 +0200 +Message-Id: <20170516045518.E63C61882@example.com> + +some test diff --git a/test/fixtures/mail53.box b/test/fixtures/mail53.box new file mode 100644 index 000000000..c023d1dd2 --- /dev/null +++ b/test/fixtures/mail53.box @@ -0,0 +1,110 @@ +Delivered-To: feedback_en@example.com +Return-Path: <> +Delivered-To: feedback_en@example.com +Received: from director15.mail.dfw1a.example.net ([1.1.1.1]) + by store512a.mail.iad3a.example.net (Dovecot) with LMTP id ZXf9G3t1tFhAbgAA7aV/mQ + for ; Mon, 27 Feb 2017 13:52:43 -0500 +Received: from smtp20.gate.dfw1a ([1.1.1.1]) + (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) + by director15.mail.dfw1a.example.net (Dovecot) with LMTP id wnMQKQhztFggHQAAREf9Rg + ; Mon, 27 Feb 2017 13:52:43 -0500 +Return-Path: <> +X-Spam-Threshold: 95 +X-Spam-Score: 0 +X-Spam-Flag: NO +X-Virus-Scanned: OK +X-MessageSniffer-Scan-Result: 0 +X-MessageSniffer-Rules: 0-0-0-7364-c +X-CMAE-Scan-Result: 0 +X-CNFS-Analysis: v=2.2 cv=IuBcS/3g c=1 sm=1 tr=0 a=scmLJpidNJD1CDJrwSPlCg==:117 a=KiCxJD0x+Pe5VASQKmYoJrcyuOo=:19 a=HpWyMqnf4hoA:10 a=HFcG5fkciocA:10 a=n2v9WMKugxEA:10 a=ZZnuYtJkoWoA:10 a=vX-N2HuyvEP-EhXdXtwA:9 a=GF4HiIEFAAAA:8 a=l1aLL7fvAAAA:8 a=m9wmmNRzG3RnX796Uw4A:9 a=CjuIK1q_8ugA:10 a=fSRcLqLQAAAA:8 a=n3WKkpLOXN7oL6whe2YA:9 a=oWI6YT3fg6wA:10 a=JGRhF4uQAAAA:8 a=YoI8Y-owAAAA:8 a=xW0offs3AAAA:8 a=cuXalqQTuEIKHF7dZIwA:9 a=hHE8zlonNCKEIyoE4Yab:22 a=NPV240f7YeaO3CCHy0GZ:22 a=6Ojsp-TqxlhusgkSIWu7:22 a=kcHpxALSlUaRulRdPvIa:22 a=-zJbGfyDzD99htaT2oAx:22 a=_3VCzNpgjGu_f5hyB7JW:22 +X-Orig-To: feedback@example.com +X-Originating-Ip: [XX.example.example.example] +Authentication-Results: smtp20.gate.dfw1a.example.net; iprev=pass policy.iprev="XX.example.example.example"; spf=neutral smtp.mailfrom="" smtp.helo="smtp136.dfw.example.com"; dkim=none (message not signed) header.d=none +X-Classification-ID: ebb2f874-fd1d-11e6-968d-001ec95b9664-1-1 +Received: from [XX.example.example.example] ([XX.example.example.example:58318] helo=smtp136.dfw.example.com) + by smtp20.gate.dfw1a.example.net (envelope-from <>) + (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) + id 50/40-17519-B7574B85; Mon, 27 Feb 2017 13:52:43 -0500 +Received: by smtp30.relay.dfw1a.example.com (SMTP Server) + id 23593E043D; Mon, 27 Feb 2017 13:52:43 -0500 (EST) +Date: Mon, 27 Feb 2017 13:52:43 -0500 (EST) +From: MAILER-DAEMON (Mail Delivery System) +Subject: Undelivered Mail Returned to Sender +To: feedback@example.com +Auto-Submitted: auto-replied +MIME-Version: 1.0 +Content-Type: multipart/report; report-type=delivery-status; + boundary="342ADE03AD.1488221563/smtp30.relay.dfw1a.example.com" +Message-Id: <20170227185243.23593E043D@smtp30.relay.dfw1a.example.com> + +This is a MIME-encapsulated message. + +--342ADE03AD.1488221563/smtp30.relay.dfw1a.example.com +Content-Description: Notification +Content-Type: text/plain; charset=us-ascii + +This is the mail system at host smtp30.relay.dfw1a.example.com. + +I'm sorry to have to inform you that your message could not +be delivered to one or more recipients. It's attached below. + +For further assistance, please send mail to postmaster. + +If you do so, please include this problem report. You can +delete your own text from the attached returned message. + + The mail system + +: connect to example.com[XX.example.example.example]:25: Connection timed + out + +--342ADE03AD.1488221563/smtp30.relay.dfw1a.example.com +Content-Description: Delivery report +Content-Type: message/delivery-status + +Reporting-MTA: dns; smtp30.relay.dfw1a.example.com +X-SMTP-Server-Queue-ID: 342ADE03AD +X-SMTP-Server-Sender: rfc822; feedback@example.com +Arrival-Date: Mon, 27 Feb 2017 05:35:21 -0500 (EST) + +Final-Recipient: rfc822; john_example@example.com +Original-Recipient: rfc822;john_example@example.com +Action: failed +Status: 4.4.1 +Diagnostic-Code: X-SMTP-Server; connect to example.com[XX.example.example.example]:25: + Connection timed out + +--342ADE03AD.1488221563/smtp30.relay.dfw1a.example.com +Content-Description: Undelivered Message Headers +Content-Type: text/rfc822-headers + +Return-Path: +Received: from smtp30.relay.dfw1a.example.com (localhost [127.0.0.1]) + by smtp30.relay.dfw1a.example.com (SMTP Server) with ESMTP id 342ADE03AD + for ; Mon, 27 Feb 2017 05:35:21 -0500 (EST) +X-Auth-ID: feedback_en@example.com +Received: by smtp30.relay.dfw1a.example.com (Authenticated sender: feedback_en-AT-example.com) with ESMTPSA id BC4C5E016E + for ; Mon, 27 Feb 2017 05:35:20 -0500 (EST) +X-Sender-Id: feedback_en@example.com +Received: from help.example.com (example.node.dockerapp.io [example.example.example.example]) + (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) + by 0.0.0.0:25 (trex/5.7.12); + Mon, 27 Feb 2017 05:35:21 -0500 +Date: Mon, 27 Feb 2017 10:35:19 +0000 +From: Oliver Grahl | Support +To: John Stewart +Message-ID: <20170227103514.188.920664@help.example.com> +In-Reply-To: <92a8950479d35e18cb39263e9a35de3b@www.example.com> +References: <92a8950479d35e18cb39263e9a35de3b@www.example.com> + <92a8950479d35e18cb39263e9a35de3b@www.example.com> +Subject: RE: Feedback after Uninstallation [Ticket#62188] +Mime-Version: 1.0 +Content-Type: multipart/mixed; + boundary="--==_mimepart_58b400e72487d_32c43ffa32ed5c3010848"; + charset=UTF-8 +Content-Transfer-Encoding: 7bit +Organization: example +X-Powered-By: Zammad - Helpdesk/Support (https://zammad.org/) +X-Mailer: Zammad Mail Service + +--342ADE03AD.1488221563/smtp30.relay.dfw1a.example.com-- diff --git a/test/fixtures/mail54.box b/test/fixtures/mail54.box new file mode 100644 index 000000000..19a1f4c72 --- /dev/null +++ b/test/fixtures/mail54.box @@ -0,0 +1,77 @@ +From Karoline.Smith@example.com Wed Apr 19 20:56:33 2017 +Return-Path: +Delivered-To: unknown +Received: from betelgeuse.example.de (1.1.1.1:993) by zmd-clx with IMAP4-SSL; 19 Apr 2017 20:56:33 -0000 +Delivered-To: climax-hussein@example.com +Received: (qmail 31952 invoked from network); 5 Apr 2017 07:45:31 -0000 +Received: from unknown (HELO mail1.bemta3.example.com) (2.1.1.1) by betelgeuse.example.de with SMTP; 5 Apr 2017 07:45:31 -0000 +Received: from [85.158.138.179] by server-17.bemta-3.example.com id D5/73-04270-A90A4E85; Wed, 05 Apr 2017 07:45:30 +0000 +X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrIKsWRWlGSWpSXmKPExsWi75nTrTtrwZM +Ig5drOCwmrVzP5sDoseXbDeYAxijWzLyk/IoE1owFz6ezFkxKrWjafpWpgfFOchcjF4eQwDZG +iZbLL1ggnEOMEg3T97FCOIcZJX7/WsDcxcgJ5GxmlDg5wwvEZhPwkPhx6DUbiC0iYChxfOFUd +hBbWEBWYsW5JYwQcTmJqY/OA9VwANluEivnqIGEWQRUJN69u8cCYvMKhEpsPziBCWLXUxaJk/ +Mvgc3hBJp/ueUn2BxGoJkbNpwHu4FZQFxi07PvrCC2hICAxJI9EHEJAVGJl4//sYLsYhbIk7j +2Ww5ivqDEyZlPWCDO15bYuXs60wRGkVlIJs1C6JiFpAMirCmxfpc+RLWixJTuh+wQtoZE65y5 +7MjiCxjZVzFqFKcWlaUW6RoZ6SUVZaZnlOQmZuboGhoY6+WmFhcnpqfmJCYV6yXn525iBEZXP +QMD4w7GqSf8DjFKcjApifIq+DyJEOJLyk+pzEgszogvKs1JLT7EKMPBoSTB6zQPKCdYlJqeWp +GWmQOMc5i0BAePkghv53ygNG9xQWJucWY6ROoUoy7HsX1H3jAJseTl56VKifMqgBQJgBRllOb +BjYClnEuMslLCvIwMDAxCPAWpRbmZJajyrxjFORiVhHmngEzhycwrgdv0CugIJqAjntx5CHJE +SSJCSqqBscVE4ZBQvBPTgb3tc0qzH931fTz53yz2ffrMx++rrthVtq6zRfDx8k0LDeekF0+0v +HJXc0o19w+JLmPmI3OeCl+rETt/8MmjAxarDBw3i7X///H873fr1JJEf0feTxoJO27vYNF065 +WL2aW/TrRKrlLj19r1H4uNT+mcsr7Fd77e0ynR7MPSdiWW4oxEQy3mouJEAFAagtA0AwAA +X-Env-Sender: Karoline.Smith@example.com +X-Msg-Ref: server-9.tower-169.example.com!1491378329!108245161!2 +X-Originating-IP: [3.1.1.1] +X-StarScan-Received: +X-StarScan-Version: 9.4.12; banners=-,-,- +X-VirusChecked: Checked +Received: (qmail 4383 invoked from network); 5 Apr 2017 07:45:30 -0000 +Received: from vgdpm13vr.example.com (HELO voxe03hw.internal.example.com) (4.1.1.1) +by server-9.tower-169.example.com with SMTP; 5 Apr 2017 07:45:30 -0000 +Received: from VOEXH09W.internal.example.com (5.1.1.1) by +edge1.example.com (195.232.244.48) with Microsoft SMTP Server (TLS) id +15.0.1263.5; Wed, 5 Apr 2017 09:45:23 +0200 +Received: from VOEXC01W.internal.example.com (6.1.1.1) by +VOEXH09W.internal.example.com (5.1.1.1) with Microsoft SMTP Server +(TLS) id 15.0.1263.5; Wed, 5 Apr 2017 09:45:23 +0200 +Received: from AVOEXH03W.internal.example.com (7.1.1.1) by +VOEXC01W.internal.example.com (6.1.1.1) with Microsoft SMTP Server +(TLS) id 14.3.294.0; Wed, 5 Apr 2017 09:45:22 +0200 +Received: from VOEXM32W.internal.example.com ([8.1.1.1]) by +AVOEXH03W.internal.example.com ([7.1.1.1]) with mapi id +14.03.0294.000; Wed, 5 Apr 2017 09:45:20 +0200 +From: "Smith, Karoline, Example DE" +To: Maruan Break +Subject: AW: One Net Business +Thread-Topic: One Net Business +Thread-Index: AQHSrJW/Plvrkd7dvEe1pr4cBZSIz6Gz0rpmgAAAyYaAASlrAIABavZw +Date: Wed, 5 Apr 2017 07:45:19 +0000 +Message-ID: +References: ,<5C1F374E-737B-46BA-97F4-4829F1DF5E95@example.com> +,<45715EA78C7B5D4EAA1B775B56507F9B8C7715@VOEXM22W.internal.example.com> +<071EAD34-9F10-4D76-9405-C1B3445A0C56@example.com>,<45715EA78C7B5D4EAA1B775B56507F9B8C78E3@VOEXM22W.internal.example.com>,,<58B6BD0C-6E26-43F9-815B-70E3233C0935@example.com> +<1FDE0238-F38F-40D1-B7B7-F24ECFFBE5A1@example.com> +<1D7115FC-2F22-486C-B4B5-820D8A64A4D2@example.com> +In-Reply-To: <1D7115FC-2F22-486C-B4B5-820D8A64A4D2@example.com> +Accept-Language: de-DE, en-US +Content-Language: de-DE +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Content-Type: multipart/alternative; +boundary="_000_D98C7360C87D6642B509616EFFD4ED2D421C542Cvoexm32winterna_" +MIME-Version: 1.0 +X-getmail-retrieved-from-mailbox: INBOX + +--_000_D98C7360C87D6642B509616EFFD4ED2D421C542Cvoexm32winterna_ +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: base64 + +c29tZSB0ZXh0 + +--_000_D98C7360C87D6642B509616EFFD4ED2D421C542Cvoexm32winterna_ +Content-Type: text/html; charset="utf-8" +Content-Transfer-Encoding: base64 + +PGI+c29tZSB0ZXh0PC9iPg== + +--_000_D98C7360C87D6642B509616EFFD4ED2D421C542Cvoexm32winterna_-- diff --git a/test/unit/email_parser_test.rb b/test/unit/email_parser_test.rb index 944417915..c2d0e5be6 100644 --- a/test/unit/email_parser_test.rb +++ b/test/unit/email_parser_test.rb @@ -1068,6 +1068,37 @@ end subject: 'AW: OTRS / Anfrage OTRS Einführung/Präsentation [Ticket#11545]', }, }, + { + data: IO.binread('test/fixtures/mail52.box'), + body_md5: 'ad0c0727cd7d023ec9065daea03335f7', + params: { + from: 'MAILER-DAEMON@example.com (Mail Delivery System)', + from_email: 'MAILER-DAEMON@example.com', + from_display_name: 'Mail Delivery System', + subject: 'Undelivered Mail Returned to Sender', + }, + }, + { + data: IO.binread('test/fixtures/mail53.box'), + body_md5: '104da300f70d5683f007951c9780c83d', + params: { + from: 'MAILER-DAEMON (Mail Delivery System)', + from_email: 'MAILER-DAEMON', + from_display_name: 'Mail Delivery System', + subject: 'Undelivered Mail Returned to Sender', + }, + }, + { + data: IO.binread('test/fixtures/mail54.box'), + body_md5: '5872ddcdfdf6bfe40f36cd0408fca667', + params: { + from: '"Smith, Karoline, Example DE" ', + from_email: 'Karoline.Smith@example.com', + from_display_name: 'Smith, Karoline, Example DE', + subject: 'AW: One Net Business', + body: 'no visible content' + }, + }, ] count = 0 diff --git a/test/unit/email_process_test.rb b/test/unit/email_process_test.rb index 7c91adcdf..7a067cd42 100644 --- a/test/unit/email_process_test.rb +++ b/test/unit/email_process_test.rb @@ -2399,6 +2399,56 @@ Some Text', ], }, }, + { + data: IO.binread('test/fixtures/mail52.box'), + success: true, + result: { + 0 => { + priority: '2 normal', + title: 'Undelivered Mail Returned to Sender', + }, + 1 => { + from: 'MAILER-DAEMON@example.com (Mail Delivery System)', + sender: 'Customer', + type: 'email', + }, + }, + verify: { + users: [ + { + firstname: 'Mail', + lastname: 'Delivery System', + fullname: 'Mail Delivery System', + email: 'mailer-daemon@example.com', + }, + ], + }, + }, + { + data: IO.binread('test/fixtures/mail53.box'), + success: true, + result: { + 0 => { + priority: '2 normal', + title: 'Undelivered Mail Returned to Sender', + }, + 1 => { + from: 'MAILER-DAEMON (Mail Delivery System)', + sender: 'Customer', + type: 'email', + }, + }, + verify: { + users: [ + { + firstname: 'Mail', + lastname: 'Delivery System', + fullname: 'Mail Delivery System', + email: 'mailer-daemon@local', + }, + ], + }, + }, ] assert_process(files) end