From 8072c0dd1e75e8df65548b8a98b1a471ea206b88 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 7 Jan 2018 21:48:02 +0000 Subject: [PATCH] Merged r17147 to 3.3-stable (#27885). git-svn-id: http://svn.redmine.org/redmine/branches/3.3-stable@17149 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/mail_handler.rb | 1 + .../ticket_with_empty_attachment.eml | 58 +++++++++++++++++++ test/unit/mail_handler_test.rb | 8 +++ 3 files changed, 67 insertions(+) create mode 100644 test/fixtures/mail_handler/ticket_with_empty_attachment.eml diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 28841310e..7e16ee6a8 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -296,6 +296,7 @@ class MailHandler < ActionMailer::Base if email.attachments && email.attachments.any? email.attachments.each do |attachment| next unless accept_attachment?(attachment) + next unless attachment.body.decoded.size > 0 obj.attachments << Attachment.create(:container => obj, :file => attachment.body.decoded, :filename => attachment.filename, diff --git a/test/fixtures/mail_handler/ticket_with_empty_attachment.eml b/test/fixtures/mail_handler/ticket_with_empty_attachment.eml new file mode 100644 index 000000000..2dfc88b8d --- /dev/null +++ b/test/fixtures/mail_handler/ticket_with_empty_attachment.eml @@ -0,0 +1,58 @@ +Return-Path: +Received: from osiris ([127.0.0.1]) + by OSIRIS + with hMailServer ; Sat, 21 Jun 2008 15:53:25 +0200 +Message-ID: <002301c8d3a6$2cdf6950$0a00a8c0@osiris> +From: "John Smith" +To: +Subject: Ticket created by email with attachment +Date: Sat, 21 Jun 2008 15:53:25 +0200 +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="----=_NextPart_000_001F_01C8D3B6.F05C5270" +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2900.2869 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 + +This is a multi-part message in MIME format. + +------=_NextPart_000_001F_01C8D3B6.F05C5270 +Content-Type: multipart/alternative; + boundary="----=_NextPart_001_0020_01C8D3B6.F05C5270" + + +------=_NextPart_001_0020_01C8D3B6.F05C5270 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + +This is a new ticket with attachments +------=_NextPart_001_0020_01C8D3B6.F05C5270 +Content-Type: text/html; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + + + + + + + + +
This is  a new ticket with=20 +attachments
+ +------=_NextPart_001_0020_01C8D3B6.F05C5270-- + +------=_NextPart_000_001F_01C8D3B6.F05C5270 +Content-Type: application/json; + name="response.json" +Content-Transfer-Encoding: base64 +Content-Disposition: attachment; + filename="response.json" + + +------=_NextPart_000_001F_01C8D3B6.F05C5270-- + diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index c1afdaebd..634968ef4 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -606,6 +606,14 @@ class MailHandlerTest < ActiveSupport::TestCase assert_equal content, File.read(attachment.diskfile).force_encoding('CP852') end + def test_empty_attachment_should_not_be_imported + issue = submit_email( + 'ticket_with_empty_attachment.eml', + issue: { project: 'ecookbook' } + ) + assert_equal 0, issue.attachments.size + end + def test_multiple_inline_text_parts_should_be_appended_to_issue_description issue = submit_email('multiple_text_parts.eml', :issue => {:project => 'ecookbook'}) assert_include 'first', issue.description -- 2.39.5