Patch #2702 » mail_handler_update.diff
| app/models/mail_handler.rb (working copy) | ||
|---|---|---|
|
issue.subject = email.subject.chomp.toutf8
|
||
|
issue.description = plain_text_body
|
||
|
# custom fields
|
||
|
issue.custom_field_values = issue.available_custom_fields.inject({}) do |h, c|
|
||
|
if value = get_keyword(c.name, :override => true)
|
||
|
h[c.id] = value
|
||
|
end
|
||
|
h
|
||
|
end
|
||
|
issue.custom_field_values = get_custom_field_values(issue.available_custom_fields)
|
||
|
# other fields
|
||
|
set_issue_field_values(issue)
|
||
|
issue.save!
|
||
|
add_attachments(issue)
|
||
|
logger.info "MailHandler: issue ##{issue.id} created by #{user}" if logger && logger.info
|
||
| ... | ... | |
|
if status && issue.new_statuses_allowed_to(user).include?(status)
|
||
|
issue.status = status
|
||
|
end
|
||
|
# custom fields
|
||
|
issue.custom_field_values = get_custom_field_values(issue.available_custom_fields)
|
||
|
# other fields
|
||
|
set_issue_field_values(issue)
|
||
|
issue.save!
|
||
|
logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info
|
||
|
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
|
||
| ... | ... | |
|
end
|
||
|
@plain_text_body.strip!
|
||
|
end
|
||
|
|
||
|
def get_custom_field_values(custom_fields)
|
||
|
custom_fields.inject({}) do |h, c|
|
||
|
if value = get_keyword(c.name, :override => true)
|
||
|
h[c.id] = value
|
||
|
end
|
||
|
h
|
||
|
end
|
||
|
end
|
||
|
def set_issue_field_values(issue)
|
||
|
issue.start_date = get_keyword(:start_date, :override => true)
|
||
|
issue.due_date = get_keyword(:due_date, :override => true)
|
||
|
issue.done_ratio = get_keyword(:done_ratio, :override => true) || 0
|
||
|
issue.estimated_hours = get_keyword(:estimated_hours, :override => true)
|
||
|
assigned_to = get_keyword(:assigned_to, :override => true)
|
||
|
if assigned_to then
|
||
|
if assigned_to =~ /@/ then
|
||
|
issue.assigned_to = User.find_by_mail(assigned_to)
|
||
|
else
|
||
|
issue.assigned_to = User.find_by_login(assigned_to)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| test/unit/mail_handler_test.rb (working copy) | ||
|---|---|---|
|
assert_equal 'High', issue.priority.to_s
|
||
|
assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
|
||
|
end
|
||
|
def test_add_issue_with_full_attributes_override
|
||
|
issue = submit_email('ticket_with_full_attributes.eml', :allow_override => 'tracker,category,priority')
|
||
|
assert issue.is_a?(Issue)
|
||
|
assert !issue.new_record?
|
||
|
issue.reload
|
||
|
assert_equal 'New ticket on a given project', issue.subject
|
||
|
assert_equal User.find_by_login('jsmith'), issue.author
|
||
|
assert_equal Project.find(2), issue.project
|
||
|
assert_equal 'Feature request', issue.tracker.to_s
|
||
|
assert_equal 'Stock management', issue.category.to_s
|
||
|
assert_equal 'Urgent', issue.priority.to_s
|
||
|
assert_equal '2009-01-31'.to_date, issue.start_date
|
||
|
assert_equal '2009-02-03'.to_date, issue.due_date
|
||
|
assert_equal 70, issue.done_ratio
|
||
|
assert_equal 28, issue.estimated_hours
|
||
|
assert_equal User.find_by_login('jsmith'), issue.assigned_to
|
||
|
assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
|
||
|
end
|
||
|
|
||
|
def test_add_issue_with_attachment_to_specific_project
|
||
|
issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
|
||
| ... | ... | |
|
assert_match /This is reply/, journal.notes
|
||
|
assert_equal IssueStatus.find_by_name("Resolved"), issue.status
|
||
|
end
|
||
|
def test_add_issue_note_with_custom_fields
|
||
|
journal = submit_email('ticket_reply_with_custom_fields.eml')
|
||
|
assert journal.is_a?(Journal)
|
||
|
issue = Issue.find(journal.issue.id)
|
||
|
assert_match /This is reply/, journal.notes
|
||
|
assert_equal 'Updated value for a custom field', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value
|
||
|
end
|
||
|
|
||
|
def test_reply_to_a_message
|
||
|
m = submit_email('message_reply.eml')
|
||
| test/fixtures/mail_handler/ticket_with_full_attributes.eml (revision 0) | ||
|---|---|---|
|
Return-Path: <jsmith@somenet.foo>
|
||
|
Received: from osiris ([127.0.0.1])
|
||
|
by OSIRIS
|
||
|
with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200
|
||
|
Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris>
|
||
|
From: "John Smith" <jsmith@somenet.foo>
|
||
|
To: <redmine@somenet.foo>
|
||
|
Subject: New ticket on a given project
|
||
|
Date: Sun, 22 Jun 2008 12:28:07 +0200
|
||
|
MIME-Version: 1.0
|
||
|
Content-Type: text/plain;
|
||
|
format=flowed;
|
||
|
charset="iso-8859-1";
|
||
|
reply-type=original
|
||
|
Content-Transfer-Encoding: 7bit
|
||
|
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
|
||
|
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas imperdiet
|
||
|
turpis et odio. Integer eget pede vel dolor euismod varius. Phasellus
|
||
|
blandit eleifend augue. Nulla facilisi. Duis id diam. Class aptent taciti
|
||
|
sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In
|
||
|
in urna sed tellus aliquet lobortis. Morbi scelerisque tortor in dolor. Cras
|
||
|
sagittis odio eu lacus. Aliquam sem tortor, consequat sit amet, vestibulum
|
||
|
id, iaculis at, lectus. Fusce tortor libero, congue ut, euismod nec, luctus
|
||
|
eget, eros. Pellentesque tortor enim, feugiat in, dignissim eget, tristique
|
||
|
sed, mauris. Pellentesque habitant morbi tristique senectus et netus et
|
||
|
malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse
|
||
|
platea dictumst.
|
||
|
Nulla et nunc. Duis pede. Donec et ipsum. Nam ut dui tincidunt neque
|
||
|
sollicitudin iaculis. Duis vitae dolor. Vestibulum eget massa. Sed lorem.
|
||
|
Nullam volutpat cursus erat. Cras felis dolor, lacinia quis, rutrum et,
|
||
|
dictum et, ligula. Sed erat nibh, gravida in, accumsan non, placerat sed,
|
||
|
massa. Sed sodales, ante fermentum ultricies sollicitudin, massa leo
|
||
|
pulvinar dui, a gravida orci mi eget odio. Nunc a lacus.
|
||
|
Project: onlinestore
|
||
|
Tracker: Feature request
|
||
|
category: Stock management
|
||
|
priority: Urgent
|
||
|
start_date: 2009-01-31
|
||
|
due_date: 2009-02-03
|
||
|
done_ratio: 70
|
||
|
estimated_hours: 28.0
|
||
|
assigned_to: jsmith@somenet.foo
|
||
| test/fixtures/mail_handler/ticket_reply_with_custom_fields.eml (revision 0) | ||
|---|---|---|
|
Return-Path: <jsmith@somenet.foo>
|
||
|
Received: from osiris ([127.0.0.1])
|
||
|
by OSIRIS
|
||
|
with hMailServer ; Sat, 21 Jun 2008 18:41:39 +0200
|
||
|
Message-ID: <006a01c8d3bd$ad9baec0$0a00a8c0@osiris>
|
||
|
From: "John Smith" <jsmith@somenet.foo>
|
||
|
To: <redmine@somenet.foo>
|
||
|
References: <485d0ad366c88_d7014663a025f@osiris.tmail>
|
||
|
Subject: Re: [onlinestore - Bug #4] (New) Issue on project 2
|
||
|
Date: Sat, 21 Jun 2008 18:41:39 +0200
|
||
|
MIME-Version: 1.0
|
||
|
Content-Type: multipart/alternative;
|
||
|
boundary="----=_NextPart_000_0067_01C8D3CE.711F9CC0"
|
||
|
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_0067_01C8D3CE.711F9CC0
|
||
|
Content-Type: text/plain;
|
||
|
charset="utf-8"
|
||
|
Content-Transfer-Encoding: quoted-printable
|
||
|
|
||
|
This is reply
|
||
|
|
||
|
searchable field: Updated value for a custom field
|
||
|
------=_NextPart_000_0067_01C8D3CE.711F9CC0
|
||
|
Content-Type: text/html;
|
||
|
charset="utf-8"
|
||
|
Content-Transfer-Encoding: quoted-printable
|
||
|
|
||
|
=EF=BB=BF<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||
|
<HTML><HEAD>
|
||
|
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8">
|
||
|
<STYLE>BODY {
|
||
|
FONT-SIZE: 0.8em; COLOR: #484848; FONT-FAMILY: Verdana, sans-serif
|
||
|
}
|
||
|
BODY H1 {
|
||
|
FONT-SIZE: 1.2em; MARGIN: 0px; FONT-FAMILY: "Trebuchet MS", Verdana, =
|
||
|
sans-serif
|
||
|
}
|
||
|
A {
|
||
|
COLOR: #2a5685
|
||
|
}
|
||
|
A:link {
|
||
|
COLOR: #2a5685
|
||
|
}
|
||
|
A:visited {
|
||
|
COLOR: #2a5685
|
||
|
}
|
||
|
A:hover {
|
||
|
COLOR: #c61a1a
|
||
|
}
|
||
|
A:active {
|
||
|
COLOR: #c61a1a
|
||
|
}
|
||
|
HR {
|
||
|
BORDER-RIGHT: 0px; BORDER-TOP: 0px; BACKGROUND: #ccc; BORDER-LEFT: 0px; =
|
||
|
WIDTH: 100%; BORDER-BOTTOM: 0px; HEIGHT: 1px
|
||
|
}
|
||
|
.footer {
|
||
|
FONT-SIZE: 0.8em; FONT-STYLE: italic
|
||
|
}
|
||
|
</STYLE>
|
||
|
|
||
|
<META content=3D"MSHTML 6.00.2900.2883" name=3DGENERATOR></HEAD>
|
||
|
<BODY bgColor=3D#ffffff>
|
||
|
<DIV><SPAN class=3Dfooter><FONT face=3DArial color=3D#000000 =
|
||
|
size=3D2>This is=20
|
||
|
reply Status: Resolved</FONT></DIV></SPAN></BODY></HTML>
|
||
|
|
||
|
------=_NextPart_000_0067_01C8D3CE.711F9CC0--
|
||
|
|
||
- « Previous
- 1
- 2
- Next »