Project

General

Profile

Patch #17705 » better_incoming_email_issue_id_recognition_with_tests.patch

Felix Schäfer, 2014-09-25 19:52

View differences:

app/models/mail_handler.rb
145 145
  private
146 146

  
147 147
  MESSAGE_ID_RE = %r{^<?redmine\.([a-z0-9_]+)\-(\d+)\.\d+(\.[a-f0-9]+)?@}
148
  ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]*#(\d+)\]}
148
  ISSUE_REPLY_SUBJECT_RE = %r{\[(?:[^\]]*\s+)?#(\d+)\]}
149 149
  MESSAGE_REPLY_SUBJECT_RE = %r{\[[^\]]*msg(\d+)\]}
150 150

  
151 151
  def dispatch
test/fixtures/mail_handler/ticket_reply_with_bogus_issue_strings_in_subject_1.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 18:41:39 +0200
5
Message-ID: <006a01c8d3bd$ad9baec0$0a00a8c0@osiris>
6
From: "John Smith" <jsmith@somenet.foo>
7
To: <redmine@somenet.foo>
8
References: <485d0ad366c88_d7014663a025f@osiris.tmail>
9
Subject: Re: [12345#1][bogus#1][#2] Add ingredients categories
10
Date: Sat, 21 Jun 2008 18:41:39 +0200
11
MIME-Version: 1.0
12
Content-Type: multipart/alternative;
13
	boundary="----=_NextPart_000_0067_01C8D3CE.711F9CC0"
14
X-Priority: 3
15
X-MSMail-Priority: Normal
16
X-Mailer: Microsoft Outlook Express 6.00.2900.2869
17
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
18

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

  
21
------=_NextPart_000_0067_01C8D3CE.711F9CC0
22
Content-Type: text/plain;
23
	charset="utf-8"
24
Content-Transfer-Encoding: quoted-printable
25

  
26
This is reply
27
------=_NextPart_000_0067_01C8D3CE.711F9CC0
28
Content-Type: text/html;
29
	charset="utf-8"
30
Content-Transfer-Encoding: quoted-printable
31

  
32
=EF=BB=BF<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
33
<HTML><HEAD>
34
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8">
35
<STYLE>BODY {
36
	FONT-SIZE: 0.8em; COLOR: #484848; FONT-FAMILY: Verdana, sans-serif
37
}
38
BODY H1 {
39
	FONT-SIZE: 1.2em; MARGIN: 0px; FONT-FAMILY: "Trebuchet MS", Verdana, =
40
sans-serif
41
}
42
A {
43
	COLOR: #2a5685
44
}
45
A:link {
46
	COLOR: #2a5685
47
}
48
A:visited {
49
	COLOR: #2a5685
50
}
51
A:hover {
52
	COLOR: #c61a1a
53
}
54
A:active {
55
	COLOR: #c61a1a
56
}
57
HR {
58
	BORDER-RIGHT: 0px; BORDER-TOP: 0px; BACKGROUND: #ccc; BORDER-LEFT: 0px; =
59
WIDTH: 100%; BORDER-BOTTOM: 0px; HEIGHT: 1px
60
}
61
.footer {
62
	FONT-SIZE: 0.8em; FONT-STYLE: italic
63
}
64
</STYLE>
65

  
66
<META content=3D"MSHTML 6.00.2900.2883" name=3DGENERATOR></HEAD>
67
<BODY bgColor=3D#ffffff>
68
<DIV><SPAN class=3Dfooter><FONT face=3DArial color=3D#000000 =
69
size=3D2>This is=20
70
reply</FONT></DIV></SPAN></BODY></HTML>
71

  
72
------=_NextPart_000_0067_01C8D3CE.711F9CC0--
73

  
test/fixtures/mail_handler/ticket_reply_with_bogus_issue_strings_in_subject_2.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 18:41:39 +0200
5
Message-ID: <006a01c8d3bd$ad9baec0$0a00a8c0@osiris>
6
From: "John Smith" <jsmith@somenet.foo>
7
To: <redmine@somenet.foo>
8
References: <485d0ad366c88_d7014663a025f@osiris.tmail>
9
Subject: Re: [12345#1][bogus#1][Feature request #2] Add ingredients categories
10
Date: Sat, 21 Jun 2008 18:41:39 +0200
11
MIME-Version: 1.0
12
Content-Type: multipart/alternative;
13
	boundary="----=_NextPart_000_0067_01C8D3CE.711F9CC0"
14
X-Priority: 3
15
X-MSMail-Priority: Normal
16
X-Mailer: Microsoft Outlook Express 6.00.2900.2869
17
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
18

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

  
21
------=_NextPart_000_0067_01C8D3CE.711F9CC0
22
Content-Type: text/plain;
23
	charset="utf-8"
24
Content-Transfer-Encoding: quoted-printable
25

  
26
This is reply
27
------=_NextPart_000_0067_01C8D3CE.711F9CC0
28
Content-Type: text/html;
29
	charset="utf-8"
30
Content-Transfer-Encoding: quoted-printable
31

  
32
=EF=BB=BF<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
33
<HTML><HEAD>
34
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8">
35
<STYLE>BODY {
36
	FONT-SIZE: 0.8em; COLOR: #484848; FONT-FAMILY: Verdana, sans-serif
37
}
38
BODY H1 {
39
	FONT-SIZE: 1.2em; MARGIN: 0px; FONT-FAMILY: "Trebuchet MS", Verdana, =
40
sans-serif
41
}
42
A {
43
	COLOR: #2a5685
44
}
45
A:link {
46
	COLOR: #2a5685
47
}
48
A:visited {
49
	COLOR: #2a5685
50
}
51
A:hover {
52
	COLOR: #c61a1a
53
}
54
A:active {
55
	COLOR: #c61a1a
56
}
57
HR {
58
	BORDER-RIGHT: 0px; BORDER-TOP: 0px; BACKGROUND: #ccc; BORDER-LEFT: 0px; =
59
WIDTH: 100%; BORDER-BOTTOM: 0px; HEIGHT: 1px
60
}
61
.footer {
62
	FONT-SIZE: 0.8em; FONT-STYLE: italic
63
}
64
</STYLE>
65

  
66
<META content=3D"MSHTML 6.00.2900.2883" name=3DGENERATOR></HEAD>
67
<BODY bgColor=3D#ffffff>
68
<DIV><SPAN class=3Dfooter><FONT face=3DArial color=3D#000000 =
69
size=3D2>This is=20
70
reply</FONT></DIV></SPAN></BODY></HTML>
71

  
72
------=_NextPart_000_0067_01C8D3CE.711F9CC0--
73

  
test/unit/mail_handler_test.rb
680 680
    assert_equal 'Feature request', journal.issue.tracker.name
681 681
  end
682 682

  
683
  def test_update_issue_with_bogus_issue_strings_in_subject
684
    journal1 = submit_email('ticket_reply_with_bogus_issue_strings_in_subject_1.eml')
685
    journal2 = submit_email('ticket_reply_with_bogus_issue_strings_in_subject_2.eml')
686
    assert journal1.is_a?(Journal)
687
    assert journal2.is_a?(Journal)
688
    assert_equal Issue.find(2), journal1.journalized
689
    assert_equal Issue.find(2), journal2.journalized
690
  end
691

  
683 692
  def test_update_issue_with_attribute_changes
684 693
    # This email contains: 'Status: Resolved'
685 694
    journal = submit_email('ticket_reply_with_status.eml')
(2-2/2)