From 57176aedbbab272b63ab5b6e8dc38fefc73df9a1 Mon Sep 17 00:00:00 2001 From: Mantas Masalskis Date: Tue, 4 Aug 2020 10:08:28 +0200 Subject: [PATCH] Fixes #3143 - unprocessible mail "FrozenError: can't modify frozen String" --- app/models/channel/email_parser.rb | 6 ++- test/data/mail/mail092.box | 62 ++++++++++++++++++++++++++++++ test/data/mail/mail092.yml | 45 ++++++++++++++++++++++ 3 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 test/data/mail/mail092.box create mode 100644 test/data/mail/mail092.yml diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index f97e9a1fa..76f1ae6a8 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -709,11 +709,13 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again end end + file_body = String.new(file.body.to_s) + # generate file name based on content type if filename.blank? && headers_store['Content-Type'].present? && headers_store['Content-Type'].match?(%r{^message/rfc822}i) begin parser = Channel::EmailParser.new - mail_local = parser.parse(file.body.to_s) + mail_local = parser.parse(file_body) filename = if mail_local[:subject].present? "#{mail_local[:subject]}.eml" elsif headers_store['Content-Description'].present? @@ -813,7 +815,7 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again headers_store.delete('Content-Disposition') attach = { - data: file.body.to_s, + data: file_body, filename: filename, preferences: headers_store, } diff --git a/test/data/mail/mail092.box b/test/data/mail/mail092.box new file mode 100644 index 000000000..14ad19e39 --- /dev/null +++ b/test/data/mail/mail092.box @@ -0,0 +1,62 @@ +Return-Path: <> +X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on + mail.example.com +X-Original-To: test@example.com +Delivered-To: receiver@example.org +X-policyd-weight: NOT_IN_SPAMCOP=-1.5 NOT_IN_IX_MANITU=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .. - helo: .mail.example. - helo-domain: .example.) FROM/MX_MATCHES_NOT_HELO(DOMAIN)=1; rate: -4 +Received: from mail.example.com (mail.example.com [127.0.0.1]) + by mail.example.com (Postfix) with ESMTPS id 82CC2418018B + for ; Wed, 22 Jul 2020 13:43:07 +0200 (CEST) +Received: from bouncer (unknown [127.0.0.1]) + by mail.example.com (Postfix) with ESMTP id 39A27804391D + for ; Wed, 22 Jul 2020 13:43:06 +0200 (CEST) +To: receiver@example.org +Subject: Undelivered Mail Returned to Sender +Auto-Submitted: auto-replied +MIME-Version: 1.0 +Content-Type: multipart/report; report-type=delivery-status; boundary="5E5F521185D1.1207995974/gmmr" +From: MAILER-DAEMON (Mail Delivery System) +Message-Id: <20200722114311.82CC2418018B@mail.example.com> +Date: Wed, 22 Jul 2020 13:43:07 +0200 (CEST) +X-KasLoop: m0506075 + +This is a MIME-encapsulated message. + +--5E5F521185D1.1207995974/gmmr +Content-Description: Notification +Content-Type: text/plain; charset=us-ascii + +This is the mail system at Centrum Holdings + +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 contact your system administrator. + +If you do so, please include this problem report. You can +delete your own text from the attached returned message. + + The mail system + +--5E5F521185D1.1207995974/gmmr +Content-Description: Delivery report +Content-Type: message/delivery-status + +Reporting-MTA: dns; mail.example.com +X-Postfix-Queue-ID: 242788039D8C +X-Postfix-Sender: rfc822; receiver@example.org +Arrival-Date: Wed, 22 Jul 2020 13:43:06 +0200 (CEST) + +Final-Recipient: rfc822; receiver@example.org +Action: failed +Status: 5.2.2 +Diagnostic-Code: X-Postfix; Mailbox is full + +--5E5F521185D1.1207995974/gmmr +Content-Description: Undelivered Message +Content-Type: message/rfc822 +Content-Transfer-Encoding: 8bit + + +--5E5F521185D1.1207995974/gmmr-- + diff --git a/test/data/mail/mail092.yml b/test/data/mail/mail092.yml new file mode 100644 index 000000000..cab33533b --- /dev/null +++ b/test/data/mail/mail092.yml @@ -0,0 +1,45 @@ +--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess +from: MAILER-DAEMON (Mail Delivery System) +from_email: postmaster@example.com +from_display_name: MAILER-DAEMON +to: receiver@example.org +subject: Undelivered Mail Returned to Sender +body: | + This is the mail system at Centrum Holdings + + 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 contact your system administrator. + + If you do so, please include this problem report. You can + delete your own text from the attached returned message. + + The mail system +content_type: text/plain +attachments: +- !ruby/hash:ActiveSupport::HashWithIndifferentAccess + data: | + Reporting-MTA: dns; mail.example.com + X-Postfix-Queue-ID: 242788039D8C + X-Postfix-Sender: rfc822; receiver@example.org + Arrival-Date: Wed, 22 Jul 2020 13:43:06 +0200 (CEST) + + Final-Recipient: rfc822; receiver@example.org + Action: failed + Status: 5.2.2 + Diagnostic-Code: X-Postfix; Mailbox is full + filename: Delivery report.txt + preferences: !ruby/hash:ActiveSupport::HashWithIndifferentAccess + Content-Type: message/delivery-status + Content-Description: Delivery report + Mime-Type: message/delivery-status + Charset: UTF-8 +- !ruby/hash:ActiveSupport::HashWithIndifferentAccess + data: '' + filename: Undelivered Message.eml + preferences: !ruby/hash:ActiveSupport::HashWithIndifferentAccess + Content-Type: message/rfc822 + Content-Description: Undelivered Message + Mime-Type: message/rfc822 + Charset: UTF-8