Patch #2702 » mail_handler_update.diff
app/models/mail_handler.rb (working copy) | ||
---|---|---|
104 | 104 |
issue.subject = email.subject.chomp.toutf8 |
105 | 105 |
issue.description = plain_text_body |
106 | 106 |
# custom fields |
107 |
issue.custom_field_values = issue.available_custom_fields.inject({}) do |h, c| |
|
108 |
if value = get_keyword(c.name, :override => true) |
|
109 |
h[c.id] = value |
|
110 |
end |
|
111 |
h |
|
112 |
end |
|
107 |
issue.custom_field_values = get_custom_field_values(issue.available_custom_fields) |
|
108 |
# other fields |
|
109 |
set_issue_field_values(issue) |
|
113 | 110 |
issue.save! |
114 | 111 |
add_attachments(issue) |
115 | 112 |
logger.info "MailHandler: issue ##{issue.id} created by #{user}" if logger && logger.info |
... | ... | |
146 | 143 |
if status && issue.new_statuses_allowed_to(user).include?(status) |
147 | 144 |
issue.status = status |
148 | 145 |
end |
146 |
# custom fields |
|
147 |
issue.custom_field_values = get_custom_field_values(issue.available_custom_fields) |
|
148 |
# other fields |
|
149 |
set_issue_field_values(issue) |
|
149 | 150 |
issue.save! |
150 | 151 |
logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info |
151 | 152 |
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') |
... | ... | |
229 | 230 |
end |
230 | 231 |
@plain_text_body.strip! |
231 | 232 |
end |
233 |
|
|
234 |
def get_custom_field_values(custom_fields) |
|
235 |
custom_fields.inject({}) do |h, c| |
|
236 |
if value = get_keyword(c.name, :override => true) |
|
237 |
h[c.id] = value |
|
238 |
end |
|
239 |
h |
|
240 |
end |
|
241 |
end |
|
242 | ||
243 |
def set_issue_field_values(issue) |
|
244 |
issue.start_date = get_keyword(:start_date, :override => true) |
|
245 |
issue.due_date = get_keyword(:due_date, :override => true) |
|
246 |
issue.done_ratio = get_keyword(:done_ratio, :override => true) || 0 |
|
247 |
issue.estimated_hours = get_keyword(:estimated_hours, :override => true) |
|
248 | ||
249 |
assigned_to = get_keyword(:assigned_to, :override => true) |
|
250 |
if assigned_to then |
|
251 |
if assigned_to =~ /@/ then |
|
252 |
issue.assigned_to = User.find_by_mail(assigned_to) |
|
253 |
else |
|
254 |
issue.assigned_to = User.find_by_login(assigned_to) |
|
255 |
end |
|
256 |
end |
|
257 |
end |
|
232 | 258 |
end |
test/unit/mail_handler_test.rb (working copy) | ||
---|---|---|
89 | 89 |
assert_equal 'High', issue.priority.to_s |
90 | 90 |
assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') |
91 | 91 |
end |
92 | ||
93 |
def test_add_issue_with_full_attributes_override |
|
94 |
issue = submit_email('ticket_with_full_attributes.eml', :allow_override => 'tracker,category,priority') |
|
95 |
assert issue.is_a?(Issue) |
|
96 |
assert !issue.new_record? |
|
97 |
issue.reload |
|
98 |
assert_equal 'New ticket on a given project', issue.subject |
|
99 |
assert_equal User.find_by_login('jsmith'), issue.author |
|
100 |
assert_equal Project.find(2), issue.project |
|
101 |
assert_equal 'Feature request', issue.tracker.to_s |
|
102 |
assert_equal 'Stock management', issue.category.to_s |
|
103 |
assert_equal 'Urgent', issue.priority.to_s |
|
104 |
assert_equal '2009-01-31'.to_date, issue.start_date |
|
105 |
assert_equal '2009-02-03'.to_date, issue.due_date |
|
106 |
assert_equal 70, issue.done_ratio |
|
107 |
assert_equal 28, issue.estimated_hours |
|
108 |
assert_equal User.find_by_login('jsmith'), issue.assigned_to |
|
109 |
assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') |
|
110 |
end |
|
92 | 111 |
|
93 | 112 |
def test_add_issue_with_attachment_to_specific_project |
94 | 113 |
issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'}) |
... | ... | |
142 | 161 |
assert_match /This is reply/, journal.notes |
143 | 162 |
assert_equal IssueStatus.find_by_name("Resolved"), issue.status |
144 | 163 |
end |
164 | ||
165 |
def test_add_issue_note_with_custom_fields |
|
166 |
journal = submit_email('ticket_reply_with_custom_fields.eml') |
|
167 |
assert journal.is_a?(Journal) |
|
168 |
issue = Issue.find(journal.issue.id) |
|
169 |
assert_match /This is reply/, journal.notes |
|
170 |
assert_equal 'Updated value for a custom field', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value |
|
171 |
end |
|
145 | 172 |
|
146 | 173 |
def test_reply_to_a_message |
147 | 174 |
m = submit_email('message_reply.eml') |
test/fixtures/mail_handler/ticket_with_full_attributes.eml (revision 0) | ||
---|---|---|
1 |
Return-Path: <jsmith@somenet.foo> |
|
2 |
Received: from osiris ([127.0.0.1]) |
|
3 |
by OSIRIS |
|
4 |
with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200 |
|
5 |
Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris> |
|
6 |
From: "John Smith" <jsmith@somenet.foo> |
|
7 |
To: <redmine@somenet.foo> |
|
8 |
Subject: New ticket on a given project |
|
9 |
Date: Sun, 22 Jun 2008 12:28:07 +0200 |
|
10 |
MIME-Version: 1.0 |
|
11 |
Content-Type: text/plain; |
|
12 |
format=flowed; |
|
13 |
charset="iso-8859-1"; |
|
14 |
reply-type=original |
|
15 |
Content-Transfer-Encoding: 7bit |
|
16 |
X-Priority: 3 |
|
17 |
X-MSMail-Priority: Normal |
|
18 |
X-Mailer: Microsoft Outlook Express 6.00.2900.2869 |
|
19 |
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 |
|
20 | ||
21 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas imperdiet |
|
22 |
turpis et odio. Integer eget pede vel dolor euismod varius. Phasellus |
|
23 |
blandit eleifend augue. Nulla facilisi. Duis id diam. Class aptent taciti |
|
24 |
sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In |
|
25 |
in urna sed tellus aliquet lobortis. Morbi scelerisque tortor in dolor. Cras |
|
26 |
sagittis odio eu lacus. Aliquam sem tortor, consequat sit amet, vestibulum |
|
27 |
id, iaculis at, lectus. Fusce tortor libero, congue ut, euismod nec, luctus |
|
28 |
eget, eros. Pellentesque tortor enim, feugiat in, dignissim eget, tristique |
|
29 |
sed, mauris. Pellentesque habitant morbi tristique senectus et netus et |
|
30 |
malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse |
|
31 |
platea dictumst. |
|
32 | ||
33 |
Nulla et nunc. Duis pede. Donec et ipsum. Nam ut dui tincidunt neque |
|
34 |
sollicitudin iaculis. Duis vitae dolor. Vestibulum eget massa. Sed lorem. |
|
35 |
Nullam volutpat cursus erat. Cras felis dolor, lacinia quis, rutrum et, |
|
36 |
dictum et, ligula. Sed erat nibh, gravida in, accumsan non, placerat sed, |
|
37 |
massa. Sed sodales, ante fermentum ultricies sollicitudin, massa leo |
|
38 |
pulvinar dui, a gravida orci mi eget odio. Nunc a lacus. |
|
39 | ||
40 |
Project: onlinestore |
|
41 |
Tracker: Feature request |
|
42 |
category: Stock management |
|
43 |
priority: Urgent |
|
44 |
start_date: 2009-01-31 |
|
45 |
due_date: 2009-02-03 |
|
46 |
done_ratio: 70 |
|
47 |
estimated_hours: 28.0 |
|
48 |
assigned_to: jsmith@somenet.foo |
test/fixtures/mail_handler/ticket_reply_with_custom_fields.eml (revision 0) | ||
---|---|---|
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: [onlinestore - Bug #4] (New) Issue on project 2 |
|
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 |
|
|
28 |
searchable field: Updated value for a custom field |
|
29 |
------=_NextPart_000_0067_01C8D3CE.711F9CC0 |
|
30 |
Content-Type: text/html; |
|
31 |
charset="utf-8" |
|
32 |
Content-Transfer-Encoding: quoted-printable |
|
33 |
|
|
34 |
=EF=BB=BF<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
|
35 |
<HTML><HEAD> |
|
36 |
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8"> |
|
37 |
<STYLE>BODY { |
|
38 |
FONT-SIZE: 0.8em; COLOR: #484848; FONT-FAMILY: Verdana, sans-serif |
|
39 |
} |
|
40 |
BODY H1 { |
|
41 |
FONT-SIZE: 1.2em; MARGIN: 0px; FONT-FAMILY: "Trebuchet MS", Verdana, = |
|
42 |
sans-serif |
|
43 |
} |
|
44 |
A { |
|
45 |
COLOR: #2a5685 |
|
46 |
} |
|
47 |
A:link { |
|
48 |
COLOR: #2a5685 |
|
49 |
} |
|
50 |
A:visited { |
|
51 |
COLOR: #2a5685 |
|
52 |
} |
|
53 |
A:hover { |
|
54 |
COLOR: #c61a1a |
|
55 |
} |
|
56 |
A:active { |
|
57 |
COLOR: #c61a1a |
|
58 |
} |
|
59 |
HR { |
|
60 |
BORDER-RIGHT: 0px; BORDER-TOP: 0px; BACKGROUND: #ccc; BORDER-LEFT: 0px; = |
|
61 |
WIDTH: 100%; BORDER-BOTTOM: 0px; HEIGHT: 1px |
|
62 |
} |
|
63 |
.footer { |
|
64 |
FONT-SIZE: 0.8em; FONT-STYLE: italic |
|
65 |
} |
|
66 |
</STYLE> |
|
67 |
|
|
68 |
<META content=3D"MSHTML 6.00.2900.2883" name=3DGENERATOR></HEAD> |
|
69 |
<BODY bgColor=3D#ffffff> |
|
70 |
<DIV><SPAN class=3Dfooter><FONT face=3DArial color=3D#000000 = |
|
71 |
size=3D2>This is=20 |
|
72 |
reply Status: Resolved</FONT></DIV></SPAN></BODY></HTML> |
|
73 |
|
|
74 |
------=_NextPart_000_0067_01C8D3CE.711F9CC0-- |
|
75 |
|
- « Previous
- 1
- 2
- Next »