Project

General

Profile

Patch #27885 » 27885.patch

Felix Schäfer, 2018-01-03 14:28

View differences:

app/models/mail_handler.rb
296 296
    if email.attachments && email.attachments.any?
297 297
      email.attachments.each do |attachment|
298 298
        next unless accept_attachment?(attachment)
299
        next unless attachment.body.decoded.size > 0
299 300
        obj.attachments << Attachment.create(:container => obj,
300 301
                          :file => attachment.body.decoded,
301 302
                          :filename => attachment.filename,
test/fixtures/mail_handler/ticket_with_empty_attachment.eml
1
Return-Path: <jsmith@somenet.foo>
2
Received: from osiris ([127.0.0.1])
3
	by OSIRIS
4
	with hMailServer ; Sat, 21 Jun 2008 15:53:25 +0200
5
Message-ID: <002301c8d3a6$2cdf6950$0a00a8c0@osiris>
6
From: "John Smith" <jsmith@somenet.foo>
7
To: <redmine@somenet.foo>
8
Subject: Ticket created by email with attachment
9
Date: Sat, 21 Jun 2008 15:53:25 +0200
10
MIME-Version: 1.0
11
Content-Type: multipart/mixed;
12
	boundary="----=_NextPart_000_001F_01C8D3B6.F05C5270"
13
X-Priority: 3
14
X-MSMail-Priority: Normal
15
X-Mailer: Microsoft Outlook Express 6.00.2900.2869
16
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
17

  
18
This is a multi-part message in MIME format.
19

  
20
------=_NextPart_000_001F_01C8D3B6.F05C5270
21
Content-Type: multipart/alternative;
22
	boundary="----=_NextPart_001_0020_01C8D3B6.F05C5270"
23

  
24

  
25
------=_NextPart_001_0020_01C8D3B6.F05C5270
26
Content-Type: text/plain;
27
	charset="iso-8859-1"
28
Content-Transfer-Encoding: quoted-printable
29

  
30
This is  a new ticket with attachments
31
------=_NextPart_001_0020_01C8D3B6.F05C5270
32
Content-Type: text/html;
33
	charset="iso-8859-1"
34
Content-Transfer-Encoding: quoted-printable
35

  
36
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
37
<HTML><HEAD>
38
<META http-equiv=3DContent-Type content=3D"text/html; =
39
charset=3Diso-8859-1">
40
<META content=3D"MSHTML 6.00.2900.2883" name=3DGENERATOR>
41
<STYLE></STYLE>
42
</HEAD>
43
<BODY bgColor=3D#ffffff>
44
<DIV><FONT face=3DArial size=3D2>This is&nbsp; a new ticket with=20
45
attachments</FONT></DIV></BODY></HTML>
46

  
47
------=_NextPart_001_0020_01C8D3B6.F05C5270--
48

  
49
------=_NextPart_000_001F_01C8D3B6.F05C5270
50
Content-Type: application/json;
51
	name="response.json"
52
Content-Transfer-Encoding: base64
53
Content-Disposition: attachment;
54
	filename="response.json"
55

  
56

  
57
------=_NextPart_000_001F_01C8D3B6.F05C5270--
58

  
test/unit/mail_handler_test.rb
631 631
    assert_equal content, File.read(attachment.diskfile).force_encoding('CP852')
632 632
  end
633 633

  
634
  def test_empty_attachment_should_not_be_imported
635
    issue = submit_email(
636
              'ticket_with_empty_attachment.eml',
637
              issue: { project: 'ecookbook' }
638
            )
639
    assert_equal 0, issue.attachments.size
640
  end
641

  
634 642
  def test_multiple_inline_text_parts_should_be_appended_to_issue_description
635 643
    issue = submit_email('multiple_text_parts.eml', :issue => {:project => 'ecookbook'})
636 644
    assert_include 'first', issue.description
    (1-1/1)