Patch #20732 » select-project-by-subaddress.patch
app/models/mail_handler.rb | ||
---|---|---|
362 | 362 |
keyword |
363 | 363 |
end |
364 | 364 | |
365 |
def get_project_from_receiver_addresses |
|
366 |
[:to, :cc, :bcc].each do |field| |
|
367 |
header = @email[field] |
|
368 |
next if header.blank? || header.field.blank? || !header.field.respond_to?(:addrs) |
|
369 |
header.field.addrs.each do |addr| |
|
370 |
if addr.local.to_s =~ /\+([^+]+)\z/ |
|
371 |
if project = Project.find_by_identifier($1) |
|
372 |
return project |
|
373 |
end |
|
374 |
end |
|
375 |
end |
|
376 |
end |
|
377 |
nil |
|
378 |
end |
|
379 | ||
365 | 380 |
def target_project |
366 | 381 |
# TODO: other ways to specify project: |
367 | 382 |
# * parse the email To field |
368 | 383 |
# * specific project (eg. Setting.mail_handler_target_project) |
369 |
target = Project.find_by_identifier(get_keyword(:project)) |
|
384 |
target = get_project_from_receiver_addresses |
|
385 |
target ||= Project.find_by_identifier(get_keyword(:project)) |
|
370 | 386 |
if target.nil? |
371 | 387 |
# Invalid project keyword, use the project specified as the default one |
372 | 388 |
default_project = handler_options[:issue][:project] |
test/fixtures/mail_handler/ticket_on_project_given_by_to_header.eml | ||
---|---|---|
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+onlinestore@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 |
Status: Resolved |
|
34 |
due date: 2010-12-31 |
|
35 |
Start Date:2010-01-01 |
|
36 |
Assigned to: John Smith |
|
37 |
fixed version: alpha |
|
38 |
estimated hours: 2.5 |
|
39 |
done ratio: 30 |
|
40 | ||
41 |
--- This line starts with a delimiter and should not be stripped |
|
42 | ||
43 |
This paragraph is before delimiters. |
|
44 | ||
45 |
BREAK |
|
46 | ||
47 |
This paragraph is between delimiters. |
|
48 | ||
49 |
--- |
|
50 | ||
51 |
This paragraph is after the delimiter so it shouldn't appear. |
|
52 | ||
53 |
Nulla et nunc. Duis pede. Donec et ipsum. Nam ut dui tincidunt neque |
|
54 |
sollicitudin iaculis. Duis vitae dolor. Vestibulum eget massa. Sed lorem. |
|
55 |
Nullam volutpat cursus erat. Cras felis dolor, lacinia quis, rutrum et, |
|
56 |
dictum et, ligula. Sed erat nibh, gravida in, accumsan non, placerat sed, |
|
57 |
massa. Sed sodales, ante fermentum ultricies sollicitudin, massa leo |
|
58 |
pulvinar dui, a gravida orci mi eget odio. Nunc a lacus. |
|
59 | ||
60 |
test/unit/mail_handler_test.rb | ||
---|---|---|
72 | 72 |
assert mail.subject.include?('New ticket on a given project') |
73 | 73 |
end |
74 | 74 | |
75 |
def test_add_issue_to_project_specified_by_subaddress |
|
76 |
# This email has redmine+onlinestore@somenet.foo as 'To' header |
|
77 |
issue = submit_email( |
|
78 |
'ticket_on_project_given_by_to_header.eml', |
|
79 |
:issue => {:tracker => 'Support request'} |
|
80 |
) |
|
81 |
assert issue.is_a?(Issue) |
|
82 |
assert !issue.new_record? |
|
83 |
issue.reload |
|
84 |
assert_equal 'onlinestore', issue.project.identifier |
|
85 |
assert_equal 'Support request', issue.tracker.name |
|
86 |
end |
|
87 | ||
75 | 88 |
def test_add_issue_with_default_tracker |
76 | 89 |
# This email contains: 'Project: onlinestore' |
77 | 90 |
issue = submit_email( |